1

I got a JSF 2.0 + PrimeFaces application and inside a h:form there's an inputHidden like this:

<h:inputHidden id="mdid" />

Unfortunately our managed beans come from another developer team and they had deployed a bean (@ViewScoped) in a .jar with an action method like this:

public void action(Integer id) {
    //Call service layer passing the id.
}

Our inputHidden is changed in client side and we can't bind it with bean.

Is there anyway I can do this?

<p:commandButton action="#{ServiceBean.action( mdid )}"

mdid should be replaced with inputHidden's value.

Thanks a lot.

Adriano Castro
  • 1,411
  • 4
  • 19
  • 33

1 Answers1

4

Bind it to the view so that you can get its value in EL scope as well.

<h:inputHidden id="mdid" binding="#{mdid}" />
...
<p:commandButton ... action="#{ServiceBean.action(mdid.value)}" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi @BalusC, thanks, but I can't bind anything because we can't create anything in bean, just consume it, and bean contains only `public void action(Integer id)`. – Adriano Castro May 24 '12 at 14:18
  • The example in my answer doesn't bind it to the bean. It binds it to the view. Just use the exact syntax `binding="#{mdid}"` and thus **not** `binding="#{someBean.mdid}"`. – BalusC May 24 '12 at 14:21
  • 1
    So you have an existing variable `#{mid}` which is a `String`? Give it a different and unique name. To be clear, you don't need to prepare any variables in view or in bean. The answer is just complete and as-is. – BalusC May 24 '12 at 14:48
  • Sure, this binding works fine. There's now only one detail I'm missing. Tried a lot here but not success. Got it `action="#{ServiceBean.action(mdid.value)}" Failed to parse the expression [#{ServiceBean.action(mdid.value)}]`. However this works: `` – Adriano Castro May 24 '12 at 14:59
  • 1
    Then your environment apparently doesn't support EL 2.2. Make sure that you target a Servlet 3.0 compatible container (Tomcat 7, Glassfish 3, etc) with a `web.xml` which is declared conform Servlet 3.0 spec version. Otherwise, use JBoss EL: http://stackoverflow.com/questions/3284236/jsf-2-0-method-invocation/3284328#3284328 – BalusC May 24 '12 at 15:01
  • That's it! My application was build under tomcat 6. I changed to tomcat 7 and works perfectly. Thanks a lot @BalusC. – Adriano Castro May 24 '12 at 20:14