0

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.selectedUser.id )}" >
   //...
</p:dataTable>

Thanks, rob

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

3

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC, very helpful as always! I'm sure I tried something like this a couple years ago and couldn't get it to work, I think you just explained why. Harry Pham's solution worked fine because I'm on GlassFish. Thanks! –  Mar 29 '11 at 17:14
  • BalusC, does JBoss EL faster than EL2.2? I heard that JUEL much faster than EL2.2 that come with GF, have u try JUEL before? – Thang Pham Mar 29 '11 at 17:23
  • @Harry: sorry, I have not ever measured/read about EL performance, so I wouldn't be able to objectively answer this. – BalusC Mar 29 '11 at 17:55
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;
  }
Thang Pham
  • 38,125
  • 75
  • 201
  • 285