Is there a way to pass an argument to a method from a JSF page?
I'm using JSF 2. Is it possible to send an argument to a method from a JSF page? I want to do something like this:
<p:dataTable id="groupsTable" var="group"
value="#{groupHandler.groupsByUserId( userHandler.selectedUse开发者_开发知识库r.id )}" >
//...
</p:dataTable>
Thanks, rob
This is not specific to JSF. This is specific to EL. If you're running on a Servlet 3.0 / EL 2.2 capable container (Glassfish 3, JBossAS 6, Tomcat 7, etc) and your web.xml
is declared conform the Servlet 3.0 spec, then your code will work.
On anything else, it won't work. You would need to upgrade to a Servlet 3.0 / EL 2.2 capable container, or to alter your web.xml
declaration (it would however make your webapp incompatible with Servlet 2.5 containers or older), or to install a custom EL implementation which supports that, such as JBoss EL.
Once again, this is regardless of the JSF version used! It was just the coincidence that EL 2.2 was introduced in Java EE 6 which also comes together with JSF 2.0. So there's some kind of urban myth/impression that it came along with JSF 2.0.
Yup, it is possible to send an argument to a method in JSF page. Your above code will work if method groupsByUserId()
method inside bean groupHandler
has this format
public List<Group> groupsByUserId(Long id){
List<Group> group = myEJB.findGroupsByUserId(id);
return group;
}
精彩评论