Tuesday, July 14, 2009

Porting RichFaces Portlets in WebSphere 6.1 Portal

This was painful week of trying to get the rich faces to get work in WebSphere Portal 6.1 running on the WebSphereAS 6.1. I used fully functional RichFaces 3.3.0.GA enabled Portlets (JSR 286) which work fine in JBoss Portal 2.7.1 with JBoss Bridge 1.0.0.CR2, JSF 1.2_12.

When deploying this Portlets on WPS, they got started, but running the Portlets always failed. The problem was closely related to RichFaces and it's filter and how the Mapping of the Resources URL was built.

The following Exception was trhrown:


Rendering View[/myportlet/view.xhtml]
javax.faces.FacesException: Resources framework is not initialised, check web.xml for Filter configuration
at org.ajax4jsf.resource.ResourceBuilderImpl.getWebXml(ResourceBuilderImpl.java:116)
at org.ajax4jsf.resource.ResourceBuilderImpl.getUri(ResourceBuilderImpl.java:323)
at org.jboss.portletbridge.richfaces.PortalResourceBuilder.getUri(PortalResourceBuilder.java:29)

In short it tells that the Filter resources are not properly installed in the web.xml.

I traced the org.ajax4jsf.resource.ResourceBuilderImpl.getWebXm method and on the place where this exception is thrown, it appears that the WebXml Object is null.

I read here that the Ajax4Jsf Filter is not running in WebSphere.

I started playing with the filter mapping in the web.xml. Depending on the Filter Mapping I used in the web.xml, I either get the Portlet to render the Standart JSF with out RichFaces components or I get the above message.

When the Portlet renders the Standard JSF, I looked in to the source code of the page and I see the rich faces panels etc. printed out to XML/JS but the components are not loaded or rendered.
I noticed that the Java Script links are possibly not loading, cause they look in my opinion not correct.
For example, in the Source code I could see:

which I tried to download this way:
http:// localhost:8080/wps/myappcontextpath/rfResorg/richfaces/renderkit/html/scripts/utils.js which always returned:

Error 404: SRVE0190E: File not found: /myappcontextpath/rfResorg/richfaces/renderkit/html/scripts/utils.js


I initially thought that the part:/rfResorg/ should be more like: /rfRes/org/ and the following bug in the jboss jira gave me additional thoughts on the URLs.

I still ain't clear if this was the root cause of the problem, but with additional configuration games, I actually got it to work.

This is how the AJAX4JSF Filter Configuration in the web.xml now looks:


richfaces
org.ajax4jsf.Filter


richfaces
/*
REQUEST
FORWARD
INCLUDE
ERROR


richfaces
/faces/rfRes/*
REQUEST
FORWARD
INCLUDE
ERROR




I added one General mapping for every URL and one to get the Resources through the Faces Servlet. Don't ask me why this works, to me it looks weird enough.

This is not the whole pie. Additionally to this, I had to add the following factory in the faces-config.xml:



org.jboss.portletbridge.context.FacesContextFactoryImpl



So that was it all about. I don't know if this might work on another configuration or even WebSphere Portal, but for now it works on mine.

One more important issue: set the Classloading policy as application classes loaded first. This will make sure that your classes in your WEB-INF/lib/* Directory will be loaded first.

This way, you can run JSF 1.2_12 on your WPS 6.1

Update:

It appears that this issue is caused due to a Class loading problems in WPS. According to some sources, WPS loads the Filters and Servlets with different class loaders. This results in an Exception when the Filter Mapping is configured as followed



Faces Servlet



In this case, only the ULR based mapping as shown above will do, since the Servlet instance is not known to the Filter instance.

18 comments:

  1. AnonymousJuly 22, 2009

    Thanks a lot for your post! it helped me get a seam-gen cooked app running on WPS 6.1

    ReplyDelete
  2. I am trying to do a similar thing, not very experienced in WAS though so not sure if i did it right, I got it to start and run without errors though however I don't see anything when I load the page, nothing loaded on it at all. even the page source is empty. I also get some warnings on startup, here is my startup log:


    [8/8/09 10:59:52:906 EEST] 0000001e ApplicationMg A WSVR0204I: Application: jsf-test-ear Application build level: Unknown
    [8/8/09 10:59:52:984 EEST] 0000001e WebGroup A SRVE0169I: Loading Web Module: jsf-test-web.
    [8/8/09 10:59:53:031 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ImportTEI]
    [8/8/09 10:59:53:031 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ForEachTEI]
    [8/8/09 10:59:53:031 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ImportTEI]
    [8/8/09 10:59:53:031 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ForEachTEI]
    [8/8/09 10:59:53:031 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ImportTEI]
    [8/8/09 10:59:53:031 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ForEachTEI]
    [8/8/09 10:59:53:046 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.XmlParseTEI]
    [8/8/09 10:59:53:046 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.XmlTransformTEI]
    [8/8/09 10:59:53:046 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.XmlParseTEI]
    [8/8/09 10:59:53:046 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.XmlTransformTEI]
    [8/8/09 10:59:53:046 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.XmlParseTEI]
    [8/8/09 10:59:53:046 EEST] 0000001e jsp W com.ibm.ws.jsp.taglib.TldParser endElement JSPG0235E: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.XmlTransformTEI]
    [8/8/09 10:59:53:187 EEST] 0000001e config I Initializing Mojarra (1.2_13-b01-FCS) for context 'jsf-test-web'
    [8/8/09 10:59:53:578 EEST] 0000001e application I JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
    [8/8/09 10:59:54:046 EEST] 0000001e ServletWrappe I SRVE0242I: [jsf-test-ear] [/jsf-test-web] [Faces Servlet]: Initialization successful.
    [8/8/09 10:59:54:046 EEST] 0000001e VirtualHost I SRVE0250I: Web Module jsf-test-web has been bound to default_host[*:9086,*:80,*:9449,*:5069,*:5068,*:443].
    [8/8/09 10:59:54:046 EEST] 0000001e ApplicationMg A WSVR0221I: Application started: jsf-test-ear

    ReplyDelete
  3. Hi M@hdeTo,

    the stack trace you posted suggests that: The JSP container failed to load the TagExtraInfo class [org.apache.taglibs.standard.tei.ImportTEI

    As far as I can tell, this is some library missing in your class path.

    I suggest you get rid of the JSP and go over to Facelets.

    In my experience, facelets fit JSF much better than the JSP do.

    Hope you solve your problem.

    kind regards

    ReplyDelete
  4. Hi,

    thank to your help I get the richfaces portlet working in the Websphere portal.

    Now, I need to put some example working that uses JSR 286 Eventing. Did you test eventing\communication?. My problem is that I dont know how to get the values in the Portlet java class from the ManagedBean java class.

    Do you have an example? If you have it, can you send it to hferreira25@gmail.com

    Thanks in Advance

    ReplyDelete
  5. Hi hferreira25,

    When we talk about eventing, i was able to push only simple String through.

    I have wrote this article before some time, you can read it here: http://random-thoughts-vortex.blogspot.com/2009/03/jsr-286-ipc-with-faces.html

    I was wondering why is that so, till I did not see the following video: http://blog.jboss-portal.org/2009/07/jboss-portlet-bridge-20-alpha-released.html

    As far as I understand it (I may be wrong) I was not able to push Java Object (only String) through cause the JBoss Portlet Bridge was not supporting JSR 286 in Version 1.0 CR2

    The video shows that the new 2.0 ALFA version offers the opportunity to push Java Object as events.

    The video is also good reference, how eventing is working. You just have to look at it better.

    Hope it helped.

    ReplyDelete
  6. Hi,

    I'm using the CR2 JBoss bridge and I already have an example using an Object as an Event. Basically it's the same thing as for the String however your object has to implement Serializable and have the attribute @XMLRootElement.

    Regards
    Hervê

    ReplyDelete
  7. Hi Hervê,

    the @XMLRootElement was the first thing I have tried. I was following the SUN Example. But it did not work for me.

    Back than I was running my Portlets under JBoss.

    I can imagine, that this works for you, cause in WebSphere, even though the Events are specified in the portlet.xml, one still has to wire the events inside of WebSphere.

    The wires is special WebSphere mechanism that even allows you to wire Portlet Events between JSR 168 Portlets.

    But hey, thanx for the tip.

    Regards

    ReplyDelete
  8. Thanks for your info. I got pass the *.getWebXm issu thanks to you. However, I got javascript error A4J is not defined. I think, I got something missing in my configuration. Also, I could not find the class you are referencing in faces-config.xml (FacesContextFactoryImpl). I am using RAD 7.5.3 with jboss tooling plugin. I included 3 richfaces jars in my war lib.
    Any ideal why a4j javascript is not inluded in portlet page?
    Thanks.

    ReplyDelete
  9. Hi,

    the org.jboss.portletbridge.context.FacesContextFactoryImpl should be part of the JBoss portlet bridge jar.

    You mentioned that you use IBM RAD. I think JBoss has it's own Portlet Bridge, and this Portlet Bridge is used when creating the Project from with in the RAD. I can only imagine that the missing A4J could be related to the IBM Portlet Bridge and it's functionality.

    You should try the JBoss Portlet Bridge found here: http://www.jboss.org/portletbridg/download/ take the JBoss Portlet Bridge CR2 release.

    I hope it helps.

    ReplyDelete
  10. Hi, me again.
    So, I included FacesContextFactoryImp in faces-config.xml and now I got java.lang.InstantiononException: org.ajax4jsf.renderkit.ChameleonRenderKitFactory. This is on runtime, deployment is fine.
    I was playing with Render Kit Factory etc. But could not pass it. I removed all IBM/RAD related refrence in faces-config.xml but still nothing.

    ReplyDelete
  11. Hallo Marcin,

    I would also check if the RAD did included the ibm-jsf.jar instead of the Sun jsf jars.

    If I recall correctly, ibm has it's own jsf implementation, which may have some issues with RichFaces. But I ain't certain about this one.

    What I can recommend to you, is to build your APPs with maven, instead relying on some IDEs such as RAD.

    Maven needs getting used to it, but if you go through my first posts, you will get the grips to it very fast.

    Maven gives you very flexible building platform, and very good way to manage your project dependencies and so much more.

    I must say that without looking at your code, I can't really help you much. Further more, I have never used RAD, so I am not much help there too. I am sorry about that.

    But I will stress it again, get rid of RAD or any other IDE for that matter, as technology that creates your projects.

    I hope you get around this issue somehow.

    Kind regards.

    ReplyDelete
  12. Yes, I am using Maven to build and deploy. As I said, I don't have any errors on complile time. My issue is related on runtime.
    You are right about RAD implementing it's own jsf. Perhaps, I need to try changing that.
    Let me know if you would be interested in looking in my code to see if there is anything obvious to you. Perhaps, we could continue our conversation outsite this forum. Here is my eamil: koziarskim@yahoo.com
    Thanks,
    Marcin

    ReplyDelete
  13. One more question. You mentioned that you where able to run RichFaces and 268 portlet on WP6.1/WAS6.1. I am using exactly the same environment. Is there any way I can see the example? Would you be willing to send me your porlet project (war/zip) so I could try on my server and compare? I would really appreciate your help.
    Here is my email again: koziarskim@yahoo.com

    Thanks,
    Marcin.

    ReplyDelete
  14. Hi Marcin,

    I am sorry, but at this point I can't serve you with full project insight. All I have wrote is only a small part of a Product of my company. Out of Company Policy I can't post you my sources. You will understand.

    For configuring Richfaces in Maven for WPS 6.1 look here:

    http://random-thoughts-vortex.blogspot.com/2009/08/maven-dependency-management-for-running.html

    ReplyDelete
  15. Marcin,

    as for the IPC, look here:

    http://random-thoughts-vortex.blogspot.com/2009/08/ipc-issue-in-websphere-61.html

    I hope you have a success.

    Regards

    ReplyDelete
  16. Please, if anyone can send me .war, who has simple richfaces app running on WPS 6.1

    Thank you.

    silvijeh@gmail.com

    ReplyDelete
  17. I'm also trying to work with richfaces and WebSphere Portal 6.1 with WAS 7. But it did not work. Renders components richfaces but when I try to use a4j: support, generates the exception: Error processing execute lifecycle java.lang.UnsupportedOperationException.
    If you can help me, I appreciate it.

    Caio (caioccandido@gmail.com)

    ReplyDelete