I’ve recently started out with JSF (I’m also quite new to HTML) and I encountered a problem with a JSF expression. I need to send a dynamic value to one of my backing beans, the value is the ID of the current logged in user. I tried with a nested JSF expression, but I got the following exception:
action=”#{newLogBean.saveOrUpdateLog(#{user.current.id})}” Failed to
parse the expression
[#{newLogBean.saveOrUpdateLog(#{user.current.id})}]
On my web page, the line looks like this:
<h:commandButton value="Add Log Entry" action="#{newLogBean.saveOrUpdateLog(#{user.current.id})}"/>
As I understand it, I can’t use nested expressions like that, so my question is how I can solve that problem in another way. Is it possible to declare a variable in JSF to get the user ID and then use that variable for the backing bean, like this:
(in JSF) int id = user.current.getId(); // get id of current logged in user
<h:commandButton value="Add Log Entry" action="#{newLogBean.saveOrUpdateLog(id)}"/>
What is the easiest way to achive this?
In the version 2.2 of the unified expression language, you can invoke parameterized methods.
Newer application server, like Glassfish 3 or Tomcat 7 include that version.
See the specification at page 125.
In other words, you could do something like that: