cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Using NetBeans to Edit Info*Engine Tasks

Highlighted
Newbie

Using NetBeans to Edit Info*Engine Tasks

You can read the Enterprise Product Focus of the Month here also authored by Bruce Hulse and you can also read the Desktop Product Focus of the Month here and the Desktop Tip of the Month here authored by Jon Jarvis.

PTC Technical Specialists Newsletter - January 2011

Tip of the Month : Using NetBeans to Edit Info*Engine Tasks

IDEs such as NetBeans allow a developer to be significantly more productive when editing Java code or JSP pages. However, did you know that you can also make the IDE edit Info*Engine tasks?

You Can’t use XML as the File Extension

The key to the whole process is to choose a different file extension than the standard XML extension used by Info*Engine. Info*Engine tasks are actually modeled after JSP pages, so you need to get the IDE to treat them as such. However, you aren’t going to coerce an XML file to be anything other than an XML file in one of the IDEs without serious repercussions. So just choose another extension (I typically use .task) and make that your standard file extension in your source tree.

Once you have created task files with a non-standard extension, there are certain features (such as task registration from embedded comments in the task files) that will not work. You should have whatever build and installation scripts rename the files back to .xml as they are deployed to your Windchill server.

For the duration of this tip, we’ll assume that .task will be the source tree’s extension for Info*Engine tasks.

One-Time Setup

Configure .task as a Valid Extension to NetBeans:

To activate the .task extension in NetBeans, use Options / Miscellaneous / Files:

B_T_Figure 1.jpg

Use the dialog to set up .task with an associated file type of JSP, so it will operate with JSP editing rules.

Create NetBeans Templates for Info*Engine and Cognos Tasks

I have created templates in NetBeans for three types of files:

  • InfoEngineTask – A typical Info*Engine task

<%@page session="false"%>

<%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%>

<%@page import="java.util.*"%>

<%@page import="com.infoengine.object.factory.Group"%>

<%@page import="com.infoengine.object.factory.Att"%>

<%@page import="com.infoengine.object.factory.Element"%>

<%@page import="com.infoengine.SAK.BasicTasklet"%>

<%@page import="com.infoengine.util.IEException"%>

<!--com.infoengine.delegate.def

@delegateName YourTaskNameHere

@repositoryType com.ptc.windchill

@typeId WCTYPE|wt.fc.Persistable

@installDelegate false

-->

<!--com.infoengine.soap.rpc.def

DESCRIPTION

@param java.lang.String name description

@return INFOENGINE_GROUP description

-->

<%

BasicTasklet ie = null;

Object me = this;

ie = (BasicTasklet) me;

String gout=(String)ie.getParam("group_out","output");

%>

<ie:webject>

<ieSmiley Tonguearam data="$(@FORM[]group_out[])" default="<%= gout %>"/>

</ie:webject>

  • CognosTask – An Info*Engine task with specialized comments for use as Cognos queries

<%@page session="false"%>

<%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%>

<%@page import="java.util.*"%>

<%@page import="com.infoengine.object.factory.Group"%>

<%@page import="com.infoengine.object.factory.Att"%>

<%@page import="com.infoengine.object.factory.Element"%>

<%@page import="com.infoengine.SAK.BasicTasklet"%>

<%@page import="com.infoengine.util.IEException"%>

<!--com.infoengine.delegate.def

@delegateName YourTaskNameHere

@repositoryType com.ptc.windchill

@typeId com.ptc.windchill.enterprise.report.ReportTask

@installDelegate true

-->

<!--com.infoengine.soap.rpc.def

Fill in task description here.

@param java.lang.String paramname description

@return INFOENGINE_GROUP ${out} {columns: java.lang.String val1, java.lang.String val2}

-->

<%

BasicTasklet ie = null;

Object me = this;

ie = (BasicTasklet) me;

String gout="out";

%>

<ie:webject>

<ieSmiley Tonguearam data="<%= gout %>"/>

</ie:webject>

  • InfoEngineJSP – A JSP set up for use with Info*Engine webjects

<%@page import="java.util.*,java.io.*,com.infoengine.object.factory.*,com.infoengine.object.*"

%><%@page import="com.infoengine.jsp.InfoEngine"

%><%@ taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"

%><%@ taglib uri="http://www.ptc.com/infoengine/taglib/directory" prefix="dir"

%><ie:getService varName="iex"/><%

InfoEngine ie = (InfoEngine) pageContext.findAttribute("iex");

%>

Use the NetBeans Tools / Templates menu item to get this dialog:

B_T_Figure 2.jpg

Create a New Folder and call it Windchill, then select it and do an Add. Identify the template file you want to use in NetBeans’ New menu. Repeat this for as many templates as you want to create. Once you’ve done this, you can do New “InfoEngine Task” (or whatever you name the template) from any folder in your project and it will copy the template file into the name you specify, giving you a consistent starting point for editing any task file.

Project Setup

Whenever you need to edit Info*Engine Tasks or JSP pages, create a Web App Project in NetBeans. Edit the web.xml for the project, find the line with </session-config> and add this immediately after it:

<jsp-config>

<taglib>

<taglib-uri>http://www.ptc.com/infoengine/taglib/core</taglib-uri>

<taglib-location>/WEB-INF/infoengine-core.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>http://www.ptc.com/infoengine/taglib/directory</taglib-uri>

<taglib-location>/WEB-INF/infoengine-directory.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>http://www.ptc.com/windchill/taglib/util</taglib-uri>

<taglib-location>/WEB-INF/util.tld</taglib-location>

</taglib>

</jsp-config>

Copy a set of the Info*Engine .tld files into the WEB-INF directory of the project (copy them from your Windchill/codebase/WEB-INF directory

Add any Cognos, Info*Engine, and / or Windchill libraries you’ll need to the project so NetBeans can do code completion and compilation for you from those classes.

Under the Web Pages folder, create tasks and/or codebase directories. Anything you create in the tasks directory as a .task file will appear like it's a web page and be edited like it is a JSP file. This also applies to any .jsp files you create under codebase. You will now get tag completion on the webjects, plus code completion on any scriptlet code you need to put into the task.

When you have properly configured everything, your Web Pages directory will look something like this:

B_T_Figure 3.jpg

How it all works

Task File Setup

Since the NetBeans JSP editor assumes that the page is a SimplifiedJSPServlet rather than a BasicTasklet, you need to trick the .task file into operating and compiling as a BasicTasklet. Essentially, treat it like a jsp page except for the use of the <ie:getService> tag. This means that instead of just referencing getParam, you’ll always use ie.getParam, just like you would do in an Info*Engine JSP page. To do this, you will need to import the following:

<%@page import="com.infoengine.object.factory.Group"%>

<%@page import="com.infoengine.object.factory.Att"%>

<%@page import="com.infoengine.object.factory.Element"%>

<%@page import="com.infoengine.SAK.BasicTasklet"%>

<%@page import="com.infoengine.util.IEException"%>

(and any other classes you might use out of infoengine or windchill)

Then, at the first opportunity, add this scriptlet:

<%

BasicTasklet ie = null;

Object me = this;

ie = (BasicTasklet) me;

%>

This will create ie as a BasicTasklet object and then you can use ie.getGroup, ie.getParam, etc., just like you were writing a JSP page. All code completions will be available to you in the NetBeans editor, both for scriptlets as well as for any tag libraries you are referencing.

JSP File Setup

JSP files have always used the <ie:getService> tag to establish a variable (for instance, “ie”) that is then used to reference an embedded Info*Engine variable named “ie”. However, the JSP editor in NetBeans doesn’t know that “ie” is actually an InfoEngine object, so you’d normally get errors whenever you reference something like ie.getParam.

To solve this issue, we add the following lines to the JSP to create an “ie” object that will be seen by the editor.

<ie:getService varName="iex"/><%

InfoEngine ie = (InfoEngine) pageContext.findAttribute("iex");

%>

This creates an “iex” service name with the ie:setService tag, then we find that “iex” variable and assign it to an explicit “ie” variable, making it possible for the editor to know what “ie” really is.

The results

Here is a sample of NetBeans being used to edit a .task file. Notice the code completion popups near the bottom of the text window, as well as the syntax coloring of the scriptlet code and the webject tags.

B_T_Figure 4.jpg

Summary

By being able to use code and webject completion, plus the built-in syntax checking done by the Editor, you’ll find that you will significantly reduce the amount of time it takes to create either tasks or JSP for use with Info*Engine.

For those of you who use another IDE, similar approaches can be used to get the same results.

You can read the Enterprise Product Focus of the Month here also authored by Bruce Hulse and you can also read the Desktop Product Focus of the Month here and the Desktop Tip of the Month here authored by Jon Jarvis.

2 REPLIES 2

Re: Using NetBeans to Edit Info*Engine Tasks

Looks very good, may you know how to do similar in eclipse, my favorite java IDE?

Re: Using NetBeans to Edit Info*Engine Tasks

Hi Mr. Peng!

Sorry to bring back a post so old...

It's amazing the possibility to use a decent IDE to code tasks!

Unfortunately, I wasn't able to reproduce your configuration in netbeans or even eclipse...

I didn't understand this point:

John Peng wrote:

Add any Cognos, Info*Engine, and / or Windchill libraries you’ll need to the project so NetBeans can do code completion and compilation for you from those classes.

How could I know which library I had used? The Task editor don't tell me with dependences my tasks use!

May you improve your instructions a little more?

Listing dependencies, a version to eclipse, etc.

Thank you!


Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________ Check out the Windchill Tips Board! We're talking about Whirlpool's use of digital twin, augmented reality, and data-driven design!

The NAVIGATE WORKING GROUP is here! Come innovate with PTC!

Sign up for a Working Group