4

what is the difference between

  <h:commandLink actionListener="#{serviceProviderBean.method}" value="Save" />

and

 <h:commandLink actionListener="#{serviceProviderBean.method()}" value="Save" />

is both invoke same method or any error in above code

Tibin Varghese
  • 125
  • 1
  • 9
  • if both works... :) I think it relates to the used EL parser version. Earlier version did not support calling methods using braces and would try to resolve "method" to a get or set method. You can also add parameters into the braces if I remember that correctly (for ex. the current object in a table). – wemu Nov 25 '14 at 07:50
  • how to know EL parser version ? – Tibin Varghese Nov 25 '14 at 07:52
  • it is part of the application server / servlet container / tomcat / thing. For tomcat the EL spec version is listed here: http://tomcat.apache.org/whichversion.html - the EL parser can be reconfigured. The JBoss EL was quite famous before braces came officially into the EL spec. – wemu Nov 25 '14 at 08:18

3 Answers3

2

Second will not work under tomcat6, it will work with tomcat7/jSF2

Armen Arzumanyan
  • 1,939
  • 3
  • 30
  • 56
1

Both are fine. The second one is being used for passing params like

<h:commandLink actionListener="#{serviceProviderBean.save(someBean.someOption)}" 
   value="Save" />
vels4j
  • 11,208
  • 5
  • 38
  • 63
0

I think you also have to use the method with braces, when you want to use a method returning a boolean value, but don't have a matching property defined in the bean.

I had that situation today. My xhtml page has a <h:panelGroup ...> with the rendered="#{bean.isLoggedIn}" attribute. The isLoggedIn method, calls the method of the boundary, so the bean does not have the matching property private boolean isLoggedIn. I got a exception because of the missing property. After adding the braces to the rendered attribute making it to rendered="#{bean.isLoggedIn()}" it's working correctly.

Anyway. The method got removed by now, because my bean should not do business logic stuff :D

binarykitten
  • 61
  • 1
  • 9
  • You got a typo and/or misunderstanding here. The machting property would be `private boolean loggedIn` and not `isLoggedIn`. Nevertheless, your point is just wrong. It just comes down to the EL parser version. For example, I can freely use `#{bean.searchPerson}`, while those is not a property. It is a method without any parameter instead. – alexander Jun 27 '16 at 06:45