NB 6.0 plugin to convert old Creator J2EE 1.4 project to VWP Java EE 5 (JSF 1.2) project

Using Netbeans 6.0 you can create and edit Visual  Web Applications with JSF 1.2 and Java EE 5 support. These Java EE 5 projects use Project Woodstock Components with advanced AJAX capabilities. Netbeans 6.0 also provides a neat migration path to open and edit old J2EE 1.4 projects created using Sun Java Studio Creator. However, the components used in these J2EE 1.4 projects are still the old Sun Web UI Components with no AJAX capabilities. NB 6.0 Visual Web does not provide upgrade path for these projects, so that they can be converted to Java EE 5 project with JSF 1.2 support and AJAX capable components.

I've written a small helper plugin to "plugin" this hole. This tool takes the old  JSF 1.1 (J2EE 1.4) project and converts it to JSF 1.2 (Java EE 5) Project. The converted project can be opened in Netbeans 6.0 and edited like any other Java EE 5 Web project created using Netbeans 6.0. The components are also upgraded from JSF 1.1 Sun Web UI Components to JSF 1.2 Project Woodstock Components. This could be accomplished easily because Project Woodstock components still use the same tag name and most of the old tag attributes.

Disclaimer: This is not a Netbeans 6.0 release supported plugin. It did not go through any rigorous QA tests like other Netbeans 6.0 VWP plugins. So comes without out any warranty.

Steps to install the plugin and convert a project

Important Note:
Before using this tool, first migrate the project using Netbeans 6.0, especially resolve the datasources. For details on datasource migration read John Baker's blog on Visual Web: Recovering database connections . For overall migration details read Tips for Migrating Java Studio Creator 2 Update 1 Projects to NetBeans IDE 6.0

  • This plugin adds a menu item called Visual Web Project Converter to the Tools Menu.

    Visual Web Project Converter Menu Item
  • Clicking on this menu items pops up a dialog where you can browse and provide the directory of the old project and a new directory where the converted project will be placed.

     
  • Clicking on the convert button, converts the old Java EE 1.4 project and places the converted Java EE 5 project in the provided new directory. Once the project is converted a Diff Viewer dialog pops up and gives an opportunity to browse the diff of converted files in the old and newly converted project.

    Project Converter Diff Viewer

  • Click on the convert button in the Diff Viewer to complete the conversion and open the converted project in the IDE.

    Project Converter - Open Project

PS: Leave a comment if you are able to convert your project or having trouble using this tool.

Update:

  • The layout switched to org.desktop.layout so that the NBM can be installed in Netbeans 6.0 IDE that  runs on JDK 1.5.
  • JSPF convesrion included.
Comments:

It would be great if this would be an official plugin. I have tried to convert a project from J2EE 1.4 to Java EE 5 by hand and it was is hard to find any documentation of what changes I needed to make. I had to create a simple Java EE 5 project and compare its files to the old project to detect any changes in configuration files etc.

Posted by Mikael on September 16, 2007 at 05:22 PM PDT #

Excelent tool! Didn't converted everything like validator--> validaorExpression, action--> actionExpression and some other minor things but all in all a great tool. Just a note that on one PC it throwed an GroupMemberException and wouldn't even start and on another worked without any problems. Thanks Winston

Posted by Bojan on September 20, 2007 at 07:36 PM PDT #

Bojan, thanks for testing the tool. I did not put logic to convert validator and action etc, because they are backward compatible and wouldn't break the page and could be manually converted later. If required, I could add the logic. Could you send me the full GroupMemberException stack trace to wjprakashATnetbeansDOTcom. This could happen if there is $ character in the Patten and not escaped with backslah then matcher could throw this exception. Not sure what scenario this happens in the tool.

Posted by Winston Prakash on September 20, 2007 at 11:50 PM PDT #

Hi, also it's need to replace valueChangeListener --> valueChangeListenerExpression. The Conversion Tool does not work into jspf files.

Posted by Carlos Díaz Suárez on September 23, 2007 at 11:24 PM PDT #

This plug-in is great!.
But when we applied this plug-in to Project including
Japanese Character,JSP is corrupted.
We want this plugin to be fixed,and to be Netbeans 6.0 release supported plugin.

Posted by Sotohiro Terashima on October 02, 2007 at 09:16 PM PDT #

Hi Sotohiro, I did not test it in other locales. If there are enough interest then this can be released as Netbeans Supported plugin.

Posted by Winston Prakash on October 02, 2007 at 11:48 PM PDT #

Hi Winston,
Things are not working for me. I cannot open .jsp/.jspf (page fragment) pages in Visual Mode. Also, both jsp and managed beans are detached.

While compiling some of my managed beans I am getting errors:
java.lang.NoClassDefFoundError: javax.faces.FacesException
I imported JSF 1.2 library into my project to solve this error, but I think there is something missing as I am getting same error at deployment in tomcat 6.0 now.

I want to have this done desperately as I wanted JSF 1.2 projects. I managed to include page fragments into the converter by changing your source.

Whenever I am adding some other libraries/jars which were present in my current project it shows me a error of "cannot create build.xml file already exists"

Can yu help me through this ? I was waiting long for this to happen.

Posted by Pratham on October 03, 2007 at 05:04 PM PDT #

Hi Winston,

Any Updates on my comments !!!

Posted by Pratham on October 08, 2007 at 03:11 PM PDT #

Hi Winston,

I've heard we can vote for plugins to become officially supported. What's the link and how do we vote for your plugin?

Thanks,

Dave

Posted by DaveBazaar on October 10, 2007 at 06:03 PM PDT #

Link is http://www.netbeans.org/issues/show_bug.cgi?id=121592

If we want this feature than we have to request it. So please vote for it.

Posted by bjaksi10 on November 09, 2007 at 08:58 AM PST #

I like your concept and it currently needed but, I am more interested in the process to make my JSF 1.1 WA and Portlets run under JSF 1.2 RI. I've tried a number of things to try and make this work but so far no luck.

Posted by D Johnson on November 28, 2007 at 10:06 PM PST #

Hi D Johnson, did you take a look at the URLs I mentioned in my blog http://blogs.sun.com/winston/entry/importing_creator_porlet_project

Posted by Winston Prakash on November 30, 2007 at 08:57 AM PST #

Hi Mr.Winston
I solved the problem I pointed out formerly on October 03, 2007,
by modifing method filterFile() of WebDirectoryConverter.java to force file read/write in encoding "UTF-8" mode as below.

private void filterFile(File sourceFile, File targetFile) {
projectConverter.addModifiedFiles(sourceFile, targetFile);
BufferedReader rd = null;
BufferedWriter wt = null;
FileInputStream fis = null;
FileOutputStream fos = null;
InputStreamReader in = null;
OutputStreamWriter out = null;
try {
// Create the reader
String[] patternStr = {"1[:.:]2", "xmlns:ui", "http://www.sun.com/web/ui", "ui:"};
String[] replacementStr = {"2.1", "xmlns:webuijsf", "http://www.sun.com/webui/webuijsf", "webuijsf:"};

// rd = new BufferedReader(new FileReader(sourceFile));
// wt = new BufferedWriter(new FileWriter(targetFile));
fis = new FileInputStream(sourceFile);
fos = new FileOutputStream(targetFile);
in = new InputStreamReader(fis, "UTF-8");
out = new OutputStreamWriter(fos, "UTF-8");
rd = new BufferedReader(in);
wt = new BufferedWriter(out);

// Retrieve all lines that match pattern
String line = null;
while ((line = rd.readLine()) != null) {
for (int i = 0; i < patternStr.length; i++) {
// Create the pattern
Pattern pattern = Pattern.compile(patternStr[i]);
Matcher matcher = pattern.matcher("");
matcher.reset(line);
if (matcher.find()) {
line = matcher.replaceAll(replacementStr[i]);
}
}
wt.write(line);
wt.newLine();
}
rd.close();
wt.close();
in.close();
out.close();
fis.close();
fos.close();
} catch (IOException exc) {
Logger.getLogger(SourceDirectoryConverter.class.getName()).log(Level.SEVERE, null, exc);
try {
rd.close();
wt.close();
in.close();
out.close();
fis.close();
fos.close();
} catch (IOException ex) {
Logger.getLogger(SourceDirectoryConverter.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

Posted by Sotohiro Terashima on March 08, 2008 at 10:22 AM PST #

Hi Mr.Winston

I already posted one bug fix on March 08, 2008.

Now I found more troubles and I could fix them.
So I posted the solution to your blog site.
This time I point out some troubles and the solutions.

Troubles:
1.
We need to change tag "ui" to "webui" on "\*.jspf" files.
2.
We need to make more changes to "\*.jsp" files as following.
action= --> actionExpression=
validator --> validatorExpression
valueChangeListener= --> valueChangeListenerExpression=
\* exception
on the case  " <h:commandLink action " do not apply this rule as following
<h:commandLink action="#{forms$GamesList.hyperlinkHighlight_action}" --> leave as is.
3.
We need to modify web.xml at servlet as following to deploy on application server.

after conversion:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param><param-name>javax.faces.LIFECYCLE_ID</param-name><param-value>com.sun.faces.lifecycle.PARTIAL</param-value></init-param></servlet>

modify to following
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<init-param>
<param-name>javax.faces.LIFECYCLE_ID</param-name>
<param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

I show my solution of web.xml trouble as following.
The modified code of WebInfDirectoryConverter.java:
########################################################################
106 line
if (servletNameElementText.getData().equals("Faces Servlet")) {
Element initParamElement = doc.createElement("init-param");
NodeList loadNameNodes = servletElement.getElementsByTagName("load-on-startup"); // Added
Element loadElement = (Element) loadNameNodes.item(0); // Added
// servletElement.appendChild(initParamElement); // Deleted
servletElement.insertBefore(initParamElement,loadElement); // Added

I show my solution of some troubles as following.
The modified method filterFile() of WebDirectoryConverter.java:
########################################################################
public class WebDirectoryConverter {

private static Pattern sourceFilePattern = Pattern.compile(".\*\\\\.(jsp|jspf)$", Pattern.CASE_INSENSITIVE);
ProjectConverter projectConverter;

..........................

private void filterFile(File sourceFile, File targetFile) {
projectConverter.addModifiedFiles(sourceFile, targetFile);
BufferedReader rd = null;
BufferedWriter wt = null;
FileInputStream fis = null;
FileOutputStream fos = null;
InputStreamReader in = null;
OutputStreamWriter out = null;
try {
// Create the reader
String[] patternStr = {"1[:.:]2", "xmlns:ui", "http://www.sun.com/web/ui", "ui:", "action=", "validator", "valueChangeListener="};
String[] replacementStr = {"2.1", "xmlns:webuijsf", "http://www.sun.com/webui/webuijsf", "webuijsf:", "actionExpression=", "validatorExpression", "valueChangeListenerExpression="};

// rd = new BufferedReader(new FileReader(sourceFile));
// wt = new BufferedWriter(new FileWriter(targetFile));
fis = new FileInputStream(sourceFile);
fos = new FileOutputStream(targetFile);
in = new InputStreamReader(fis, "UTF-8");
out = new OutputStreamWriter(fos, "UTF-8");
rd = new BufferedReader(in);
wt = new BufferedWriter(out);

// Retrieve all lines that match pattern
String line = null;
while ((line = rd.readLine()) != null) {
if(!line.trim().startsWith("<h:commandLink")){
for (int i = 0; i < patternStr.length; i++) {
// Create the pattern
Pattern pattern = Pattern.compile(patternStr[i]);
Matcher matcher = pattern.matcher("");
matcher.reset(line);
if (matcher.find()) {
line = matcher.replaceAll(replacementStr[i]);
}
}
}
wt.write(line);
wt.newLine();
}
rd.close();
wt.close();
in.close();
out.close();
fis.close();
fos.close();
} catch (IOException exc) {
Logger.getLogger(SourceDirectoryConverter.class.getName()).log(Level.SEVERE, null, exc);
try {
rd.close();
wt.close();
in.close();
out.close();
fis.close();
fos.close();
} catch (IOException ex) {
Logger.getLogger(SourceDirectoryConverter.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

Posted by Sotohiro Terashima on March 23, 2008 at 12:41 PM PDT #

Thank you very much, Winston for your plugin. I had to migrate a more than 100 jsp web page project and your plugin has done the job!!
A few problems:
-web.xml (my project was deployed on Tomcat, and now it's going to run over GlassFish) >> But i've fixed it using Sotohiro's comments
-in JSP, when I use buttons, I've got both (only the second is needed: "action= XXX" (this one is wrong) and "actionExpression=XXX"(this one is right)

Once Again, Thank you a lot for your work!!!

Giovanni

Posted by Giovanni Colonese on March 24, 2008 at 12:45 PM PDT #

Hi all,

I am a newbie at JSF.
SITUATION:: I have a project already running with Java EE 1.4 and jsf 1.1.
PROBLEM:: I want to migrate the project to Java EE 1.5 and jsf 1.2.
SOLUTION:: ??

I tried usign the above converter plugin and managed to get rid of some bugging errors.
But i am still stuck on one exception::

SEVERE: Exception sending context initialized event to listener instance of class

com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError: javax/faces/application/StateManagerWrapper

and

SEVERE: Error configuring application listener of class com.sun.faces.extensions.avatar.event.DynaFacesContextListener
java.lang.NoClassDefFoundError: javax/faces/FacesException

I just cant understand why this error is coming.

What i have ALREADY tried::
1. copying the jsf-api.jar in tomcat lib.
2. jsf-extensions-dynamic-faces-0.1.jar to tomcat lib.

Please give me any suggestions or solutions if any..

Posted by sonali on March 25, 2008 at 01:38 AM PDT #

Hi Sotohiro Terashima, Thank you very much for the fix. It is very encouraging to see community members actively participating and willing to share their code changes for the benefit of other community members. I will add your changes and publish the new jar soon.

Posted by guest on April 01, 2008 at 12:30 AM PDT #

Hi Sonali, I would suggest you to first deploy your application to Glassfish and see if everything works fine. Note, all java EE 5 compliant servers contains JSF 1.2 already, so no need to copy them. jsf-extensions-dynamic-faces-0.1.jar gets bundled in the war file, so no need to copy it also. Which version of Tomcat are you using?

Posted by guest on April 01, 2008 at 12:33 AM PDT #

I modified this plugin, you can found at my blog.

Link : http://heryuksel.blogspot.com/2008/05/nb-60-plugin-to-convert-j2ee-14-project_17.html

Posted by Haluk ERYUKSEL on May 16, 2008 at 07:09 PM PDT #

Dear winston
I had convert my application and all seems to be ok... but there is something wrong with the buttons actionExpression that are not firing the backing beans event. i'm breaking my head trying to find this wrong behavior. If you need more information please just tell me. thanks

Posted by maximiliano simon on October 31, 2008 at 09:38 AM PDT #

hi, i m new to jsf
i created a web application with visual jsf and jsf options selected
my application worked fine until i added dynamic faces component ajax zone to my only page Page1.jsp .
I m facing following error n application cann't be deployed.
15 Jan, 2009 5:22:57 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError: javax/faces/application/StateManagerWrapper
Please help.

Posted by Hrishikesh Joshi on January 14, 2009 at 08:46 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today