2

in template i'm defining a parameter

<f:metadata >
    <f:viewParam name="pageKey" value="#{parameterProvider.pageKey}" />
</f:metadata>

All works fine except AJAX requests with makes this param disappear? example ajax button in xhtml page:

Message value from server= [#{lockerBean.msg}]<br/>
<h:form>
       <h:commandButton value="Ajax Action" styleClass="systemButton" >
           <f:ajax  execute="@all" render="@all" listener="#{lockerBean.ajaxButton(event)}"/>
       </h:commandButton><br/>

</h:form>

ajax action is simply

public void ajaxButton(ActionEvent event){
        msg="Ajax reload";
    }

After ajax request pageKey is gone. If i set required="true" i get valudation error j_idt3: Validation Error: Value is required. with clearly indicates, that parameter has been deleted. how can i preserve it?

I know about includeViewParams, but i don't understand this mechanism very well and it is not easy to add to all kinds of buttons and links... can i somehow force it to be passed or can i inject them somewhere in context?

EDIT: this log might help to understand what is happening: ParameterProvider, is sessionscoped CGI that holds pageKey. I modified getter & setter, so they log info about being called. In whole aplication getters and setters to this value is used only when applying request value in jsf lifecycle (my own code uses different methods)

14:04:06,400 OFF   [ParameterProvider] (default task-12) Getting pageKey[-1] into viewParams.
14:04:06,401 OFF   [ParameterProvider] (default task-12) Setting pageKey[2] from viewParams.
14:04:06,401 OFF   [MultiActionLockListener] (default task-12) AJAX ACTION
14:04:06,414 OFF   [ParameterProvider] (default task-12) Getting pageKey[3] into viewParams.

as you can see, before anything we have calling getter and setter for key (2 has been send from client 3 suppose to be sent to client in response) calling another action will cause to log:

14:08:54,281 OFF   [MultiActionLockListener] (default task-14) AJAX ACTION
14:08:54,294 OFF   [ParameterProvider] (default task-14) Getting pageKey[7] into viewParams.

as you see, there is no getter and setter, which means pageKey is gone?

sMaN
  • 3,667
  • 4
  • 23
  • 33
T.G
  • 1,913
  • 1
  • 16
  • 29
  • parameterProvider is `@SessionScoped`. Basically there is no error that is thrown. only validation error if pageKey is required, because it disappears after AJAX request. trying to do some action after AJAX request will end up badly- pageKey is missing so pageKey != required value (with ware written into that metadata parameter) – T.G May 05 '14 at 11:22
  • Consider http://stackoverflow.com/questions/14026702/jsf-viewparam-required-ajax-breaks-page for a solution. Thanks again @BalusC. – sMaN Oct 22 '15 at 00:57

0 Answers0