0

When I call a method in a page with a param in its URI, the method is not invoked unless I pass the parameters of the uri again. For example if I have:

http://maywebsite/myapp/mypage.xhtml?mykey=myvalue

This method results in error (obviously because it renders the page again without params, but the method foo is never invoked):

<h:commandLink value="Do Action" actionListener="#{mybean.foo}"/>

So I added an ajax to only update the component, but the button is not getting fired:

<h:commandLink value="Do Action" actionListener="#{mybean.foo}">
    <f:ajax render="somecomponent"/>
</h:commandLink>

When I passed the param values again, the button invokes the method just fine:

 <h:commandLink value="Do Action" actionListener="#{mybean.foo}">
     <f:param name="mykey" value="myvalue"/>
     <f:ajax render="somecomponent"/>
 </h:commandLink>

However, this button is included (ui:include) in many pages with different param keys and values. How can I invoke the method without passing the param values?

Im using glassfish 3.1.2, jsf 2.0

fareed
  • 3,034
  • 6
  • 37
  • 65

1 Answers1

2

Apparently the bean is request scoped and the parameter plays a role in the way how the command link is rendered (e.g. by the rendered attribute on one of its parent components, or by a dynamic include of the template containing the command link).

All those conditions are namely re-evaluated during apply request values phase of the form submit. The developer has to make sure that all those conditions are exactly the same as when the form was presented to the enduser. So, when the bean is request scoped and the parameter is absent, then the command link appears as non-rendered in the component tree and this way its action won't be invoked.

Putting the bean in the view scope is the easiest way to fix this (unless you're using a dynamic <ui:include>, this is then more complicated, you'd need to turn off partial state saving for the particular view).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I don't have request beans, and yest I'm using dynamic ui:include. I had to change the logic and made a workaround to solve this problem. Thanks for explaining. – fareed Oct 19 '12 at 12:38