| Author |
Is there any provision to call a parameterized method in JSF
|
manoj sahu
Greenhorn
Joined: Jul 17, 2008
Posts: 5
|
|
|
I need to call a method which will return me a customized message based on screen id and the user role. As there is no provision in JSF, I am not able to do the same, for the reason I am doing work around, even I am not satisfied by with the thing I did. Is there any provision/way that while calling/associating a method to an outputtext I can pass parameters?
|
 |
Jason Porter
Ranch Hand
Joined: Apr 26, 2007
Posts: 120
|
|
|
You can do this with JSF 2.0 or use the JBoss EL.
|
 |
Ed Burns
author
Ranch Hand
Joined: Sep 11, 2006
Posts: 69
|
|
Jason Porter wrote:You can do this with JSF 2.0 or use the JBoss EL.
Yes, this is correct. This is one of those hugely powerful but largely unknown features in EE6. As Mr. Porter points out, you can either use EE6 (which currently means Oracle Glassfish) or use something like the JBoss EL on top of Tomcat or Jetty. As an aside, the method invocation features in both projects were largely contributed by Jacob Hookom, inventor of Facelets.
Ed
|
 |
Marco Ehrentreich
best scout
Bartender
Joined: Mar 07, 2007
Posts: 1220
|
|
Would you consider this method invocation as a powerful or maybe a dangerous feature? The question may seem stupid but I'm currently working on a project with a self-made view technology which makes extensive use of Java code and method calls inside XML templates. This makes the code and the view templates hard to understand, refactorings are much more difficult as tons of code are buried inside XML files and you always have to be careful when you change some code because the application may fail at runtime even though the Java code itself compiles just fine.
I'm pretty sure that the JSF 2.0 implementation is much more powerful and has better tools support etc. but I think the basic problem stays the same if you allow too much code to creep inside view templates - no matter if it's XML, JSP or XHTML.
What are your opinions on this? Does JSF 2.x help to avoid the trouble? Or should developers take care not to overuse this feature?
Marco
|
 |
Jason Porter
Ranch Hand
Joined: Apr 26, 2007
Posts: 120
|
|
|
I'd view this mostly as a tooling concern. I believe the three major IDEs will refactor EL on changes. The inability to call parameterized methods in previous versions of EL I think is crippling, and leads to back end code that is written to work around this limitation. This overall makes code hard to read / understand and maintain.
|
 |
Marco Ehrentreich
best scout
Bartender
Joined: Mar 07, 2007
Posts: 1220
|
|
Of course you're right. The feature comes in handy where needed (instead of creating some dirty hacks in other parts of the application). So maybe tool support would be a good way to avoid problems. I love how NetBeans already handles the mapping between EL properties and code which let's you easily navigate between Java and XHTML. Hopefully future versions will give use advanced features for more complex refactorings etc.
Marco
|
 |
manoj sahu
Greenhorn
Joined: Jul 17, 2008
Posts: 5
|
|
Hi there,
The disscussion is really helpful.
I have a little doubt, as Jason suggested I can use JBoss EL to reach the goal, but will it not be a server depencency? How to configure the JBoss EL for my view and how can I use it?
|
 |
Marco Ehrentreich
best scout
Bartender
Joined: Mar 07, 2007
Posts: 1220
|
|
Hi Manoj,
although I've never used it myself I'm pretty sure that JBoss EL in general does not depend on the JBoss server even though the name may suggest it. I think a library for just one small part of the view layer of web apps wouldn't become very popular today if it would bind you to a specific server vendor.
The better question is if and how well it integrates with other web frameworks. Unfortunately I can't answer this question as I haven't yet used it, sorry.
Marco
|
 |
Jason Porter
Ranch Hand
Joined: Apr 26, 2007
Posts: 120
|
|
manoj sahu wrote:Hi there,
The disscussion is really helpful.
I have a little doubt, as Jason suggested I can use JBoss EL to reach the goal, but will it not be a server depencency? How to configure the JBoss EL for my view and how can I use it?
In the faces-config.xml (assuming you're using JSF 1.2, if you're on 1.1 I think you're out of luck)
Then you just use it like normal: #{someBean.someMethod(param)} or #{someBean.someProperty}
As far as integration goes, it's just another ELResolver that's added to the chain.
|
 |
manoj sahu
Greenhorn
Joined: Jul 17, 2008
Posts: 5
|
|
Here again, is there any rule needs to be followed to call a parameterized method, I mean normally the method association is the property name ie. if my UserBean is mapped as UserBean and bean definition is
then the call to getUserId() is straight forward and clear to me (it will look for getUserId() method)
but is the following a valid call for method validUserActionsForTheScreen(String, String)?
|
 |
 |
|
|
subject: Is there any provision to call a parameterized method in JSF
|
|
|