Portlet Issues I feel sorry for Portlet developers. I really do. These people are always on the mailing lists and forums with problem after problem and it’s never their fault. If any group of people has been bent over by the standards bodies, it is Portlet application developers. Some parts of the JSF API behave different when inside a Portlet application. If your code is to run within a Portlet application and a regular Servlet container there are a few assumptions that need to be avoided. Here is some code assuming it will always run in a Servlet container.FacesContext ctx = FacesContext.getCurrentInstance(); ExternalContext externalContext = ctx.getExternalContext(); ServletRequest request = (ServletRequest) externalContext.getRequest(); String id = request.getParameter("id");If your code will run in a Portlet application you must make not make explicit casts to javax.servlet.ServletRequest or javax.servlet.ServletResponse. If this code were used in a Portlet application, ExternalContext.getRequest would return a javax.portlet.PortletRequest, causing a ClassCastException. An interoperable way to obtain a value of a request attribute is to do the following.FacesContext ctx = FacesContext.getCurrentInstance(); ExternalContext externalContext = ctx.getExternalContext(); externalContext.getRequestParameterMap().get("id");(It's worth noting that Dennis will be presenting at TheServerSide Java Symposium on this exact subject.)
-
Article: JSF Anti-Patterns and Pitfalls (17 messages)
- Posted by: Joseph Ottinger
- Posted on: February 28 2008 13:07 EST
"JSF AntiPatterns and Pitfalls" by Dennis Byrne covers anti-patterns and pitfalls of day to day JSF development. Most of these issues have kept the author up at night; some of these are the same old challenges with a new face. These challenges include performance, tight coupling, thread safety, security, interoperability and just plain ugliness. A short excerpt:Threaded Messages (17)
- Re: Article: JSF Anti-Patterns and Pitfalls by Jacob Hookom on February 28 2008 13:59 EST
- good by matlabtutorials matlab on March 02 2008 08:31 EST
- Your portlet points are well taken ... by Adam Spencer on February 28 2008 15:26 EST
- Re: Your portlet points are well taken ... by Wesley Hales on February 29 2008 12:51 EST
- Re: Article: JSF Anti-Patterns and Pitfalls by Jason Lee on February 28 2008 16:57 EST
- View State Encryption by Scott Langley on February 28 2008 20:04 EST
- Re: View State Encryption by Dennis Byrne on February 28 2008 21:41 EST
- Re: Article: JSF Anti-Patterns and Pitfalls by Frank Zammetti on February 29 2008 00:31 EST
- Re: Article: JSF Anti-Patterns and Pitfalls by greg matthews on March 02 2008 23:47 EST
-
Re: Re: Article: JSF Anti-Patterns and Pitfalls by Siarhei Dudzin on March 04 2008 03:32 EST
- Re: Re: Article: JSF Anti-Patterns and Pitfalls by greg matthews on March 04 2008 04:55 EST
- Re: Article: JSF Anti-Patterns and Pitfalls by Thiago Concei????o on March 04 2008 12:55 EST
-
Re: Re: Article: JSF Anti-Patterns and Pitfalls by Siarhei Dudzin on March 04 2008 03:32 EST
- Re: Article: JSF Anti-Patterns and Pitfalls by greg matthews on March 02 2008 23:47 EST
- Wait~you said "using client side state saving in production"? by liny liny on March 15 2008 05:54 EDT
- Re: Wait~you said "using client side state saving in production" by Dennis Byrne on March 19 2008 11:44 EDT
- Lacking solutions to the design patterns by Allan Lykke Christensen on March 29 2008 18:53 EDT
- :) by club stork on January 14 2013 02:45 EST
- hey by Matt Coleman on April 03 2013 04:01 EDT
-
Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: Jacob Hookom
- Posted on: February 28 2008 13:59 EST
- in response to Joseph Ottinger
Nice write up Dennis-- good tips in there for JSF and non-JSF deployments around modeling objects and managing reuse for applications. -
good[ Go to top ]
- Posted by: matlabtutorials matlab
- Posted on: March 02 2008 08:31 EST
- in response to Jacob Hookom
thnks ------------------------------------ http://www.matlabtutorials.com/ Matlab tutorials -
Your portlet points are well taken ...[ Go to top ]
- Posted by: Adam Spencer
- Posted on: February 28 2008 15:26 EST
- in response to Joseph Ottinger
I feel sorry for Portlet developers. I really do. These people are always on the mailing lists and forums with problem after problem and it’s never their fault. If any group of people has been bent over by the standards bodies, it is Portlet application developers.
+1. Portlets could be a lot more widely adopted than they currently are for a variety of reasons but I blame mostly weaknesses in the spec for the lack of adoption. Actually, the idea of creating reusable, JSF based portlets is pretty attractive. If one can work through all of the idiosyncracies of getting the servlet spec, the portlet spec and JSF to cooperate it kind of works. But it's a pain in the arse at times. For example, I still don't understand at this point why there isn't just a single conversational state object that is defacto for all HTTP communication in JEE. Regardless of whether it's with a servlet, a portlet or a JSF component. Why the conversational state ever got tied to the delivery technology, instead of the protocol, I have no idea. -
Re: Your portlet points are well taken ...[ Go to top ]
- Posted by: Wesley Hales
- Posted on: February 29 2008 12:51 EST
- in response to Adam Spencer
Actually, the idea of creating reusable, JSF based portlets is pretty attractive. If one can work through all of the idiosyncracies of getting the servlet spec, the portlet spec and JSF to cooperate it kind of works. But it's a pain in the arse at times.
Thanks to JSR-301 and the JBoss Portlet Bridge worries are eliminated and the developer only needs to worry about their JSF, Seam, or RichFaces application. -
Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: Jason Lee
- Posted on: February 28 2008 16:57 EST
- in response to Joseph Ottinger
Yes, good write up. For what it's worth:Because all JSF implementations automatically parse /WEB-INF/faces-config.xml, if it exists, as well as all files specified in the comma separated list of the javax.faces.CONFIG_FILES context parameter. When /WEB-INF/faces-config.xml is specified in the javax.faces.CONFIG_FILES context parameter it can be parsed twice. The PhaseListeners configured in this file are consequently registered twice at startup and invoked twice at runtime.
Mojarra doesn't have The Déjà vu PhaseListener problem. When we're processing config files, we make sure we don't process this file twice. -
View State Encryption[ Go to top ]
- Posted by: Scott Langley
- Posted on: February 28 2008 20:04 EST
- in response to Joseph Ottinger
Could you post any more details or links to JSF implementations that allow View State Encryption? My Google search turned up nothing except for some references to ASP.net. Thanks. -
Re: View State Encryption[ Go to top ]
- Posted by: Dennis Byrne
- Posted on: February 28 2008 21:41 EST
- in response to Scott Langley
Could you post any more details or links to JSF implementations that allow View State Encryption?
http://wiki.apache.org/myfaces/Secure_Your_Application Note that this feature is on by default in any 1.2 implementation . -
Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: Frank Zammetti
- Posted on: February 29 2008 00:31 EST
- in response to Joseph Ottinger
I submit: JSF *is* an anti-pattern. Let the flames begin, it's chilly tonight, I could use it! -
Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: greg matthews
- Posted on: March 02 2008 23:47 EST
- in response to Frank Zammetti
JSF *is* an anti-pattern.
+1 I would have thought minimum requirements for a web layer toolkit would include: - *not* being forward based, e.g. should support Post-Redirect-Get out of the box - *not* baking in view artifacts, like referencing JSP pages. Use logical view names and allow a view resolver to work out what view technology is being used. - Having a halfway decent notion of a conversation as well as rich *navigation*. Its pretty easy to use jQuery + JSP 2.0 tags to build rich pages. What's difficult to do is the rich navigation part, like offered by Spring Webflow. I wonder how long its going to take for JSF to die, i.e. less or more time than J2EE. -
Re: Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: Siarhei Dudzin
- Posted on: March 04 2008 03:32 EST
- in response to greg matthews
Since you've mentioned a plug on Spring, I'll do one of my own :) You get pretty much all of this (and much more) with Seam and as a bonus you can dump JSP (and you can still use Spring because it is integrated).JSF *is* an anti-pattern.
+1
I would have thought minimum requirements for a web layer toolkit would include:
- *not* being forward based, e.g. should support Post-Redirect-Get out of the box
- *not* baking in view artifacts, like referencing JSP pages. Use logical view names and allow a view resolver to work out what view technology is being used.
- Having a halfway decent notion of a conversation as well as rich *navigation*.
Its pretty easy to use jQuery + JSP 2.0 tags to build rich pages. What's difficult to do is the rich navigation part, like offered by Spring Webflow.I wonder how long its going to take for JSF to die, i.e. less or more time than J2EE.
I guess WebBeans will be pretty much it for JSF as we know it now... -
Re: Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: greg matthews
- Posted on: March 04 2008 16:55 EST
- in response to Siarhei Dudzin
You get pretty much all of this (and much more) with Seam and as a bonus you can dump JSP (and you can still use Spring because it is integrated).
I have looked at Seam, although only for about 2 hrs reading the doco / samples. It does look good in that it too, like Spring Webflow (SWF) has the notion of rich navigation / conversations. And yes, I'm working on a JSF app right now as I type this, and able to directly compare it to SWF. -
Re: Article: JSF Anti-Patterns and Pitfalls[ Go to top ]
- Posted by: Thiago Concei????o
- Posted on: March 04 2008 12:55 EST
- in response to greg matthews
Either Java kills Spring or Spring kills Java. -
Wait~you said "using client side state saving in production"?[ Go to top ]
- Posted by: liny liny
- Posted on: March 15 2008 05:54 EDT
- in response to Joseph Ottinger
Hi, Dennis: You wrote "I strongly recommend view state encryption for public facing JSF applications using client side state saving in production because it prevents web clients from being able to tamper with the view state." OK, my English level is not excellent and new to JSF. But I thought using server side state saving to prevents this issue. How do you think? Thanks for any comment. -
Re: Wait~you said "using client side state saving in production"[ Go to top ]
- Posted by: Dennis Byrne
- Posted on: March 19 2008 11:44 EDT
- in response to liny liny
Hi, Dennis:
Good question, there are better ways to communicate this. All you need to remember is that with unencrypted client side state saving, the view state can be manipulated by the client. By encrypting it, you prevent this problem.
You wrote "I strongly recommend view state encryption for public facing JSF applications using client side state saving in production because it prevents web clients from being able to tamper with the view state."
OK, my English level is not excellent and new to JSF.
But I thought using server side state saving to prevents this issue.
How do you think?
Thanks for any comment. -
Lacking solutions to the design patterns[ Go to top ]
- Posted by: Allan Lykke Christensen
- Posted on: March 29 2008 18:53 EDT
- in response to Joseph Ottinger
Hi Dennis, I enjoyed the article and think it is great that someone finally points out what-not-to-do when using JSF. However, I feel that you are missing alternative solutions for some of the anti-patterns. For example, you are mentioning "the Map trick" and "Law of Demeter" anti-pattern without an actual solution (or maybe I'm just not understanding it right). The readability of the anti-patterns could also be improved if they followed the structure used in other literature about anti-patterns (e.g. background, symptoms, consequences, refactorings, variations, and related solutions). Nevertheless, I like the article and glad that you are putting focus on the subject! Perhaps a follow-up article could be "JSF Design Patterns" as there seems to be great confusion about the best way to achieve certain functionality in real-life scenarios. All the best. -
:)[ Go to top ]
- Posted by: club stork
- Posted on: January 14 2013 02:45 EST
- in response to Joseph Ottinger
JSF Anti-Patterns and Pitfalls...thanks for explaining
-
hey[ Go to top ]
- Posted by: Matt Coleman
- Posted on: April 03 2013 04:01 EDT
- in response to Joseph Ottinger
i get the dinstinction now,,thanks!