MyFace implementation in Glassfish 3.1.1

Maybe I wasn’t searching enough, but I had agonizing experience by dealing with two JSF implementations in Dynamic Web Project in the Eclipse. Glassfish comes with Mojarra by default and it will conflict with other JSF implementation. By removing jsf-api.jar and jsf-impl.jar from Glassfish modules folder will break the project in the Eclipse. If I run the Glassfish outside of Eclipse, it may work, but I am using it within the Eclipse environment.

Solution to this problem was to modify the sun-web.xml file.

<sun-web-app error-url="">
<context-root>/DeleteThis</context-root>
<class-loader delegate="false"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class java code.</description>
</property>
</jsp-config>
<property name="useBundledJsf" value="true"/> 
 <property name="useMyFaces" value="true" />
</sun-web-app>

* Make sure to change the quote when Copy & Paste into the Eclipse

Maybe useBundledJsf is newer property, but both works fine. By setting class-loader delegate false, it tells Glassfish that the project will use other implementation instead of Sun RI.

Also, I came across another solution – from MyFace wiki. By creating in your webapp a “fake” com.sun.faces.config.ConfigureListener that will be loaded BEFORE the sun RI one’s.

/**
This class is here to prevent from using the real one from the sun reference implementation
*/
public class ConfigureListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent servletContextEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
}

I haven’t done above solution. Basically, modifying sun-web.xml will work just fine.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s