Sebi
Sebi

Reputation: 2584

JSF: Reload request scope property after ajax-request

I have a hidden input field, which value is read from a property of the request scope:

<h:inputHidden id="myHiddenField" value="#{requestScope['myVar']}" />

I trigger an Ajax-Request where I change the value of myVar.

<p:commandButton value="submit" action="#{myController.doSomething}" update="myHiddenField">

But my input field still contains the old value.

Any idea how I can solve this?

UPDATE: Maybe I have to explain it a little bit more.. myVar contains the IDs of all input fields with an error message (facesContext.getClientIdsWithMessages()).

When I first submit the form (with some validation errors) it works as expected. When I resubmit the form with some other validation errors the value of myVar doesn't get updated... (Still contains the IDs of the 'old' errors) When I resubmit the form with no validation errors myVar gets updated. (myVar is empty now)

Upvotes: 3

Views: 1797

Answers (1)

siebz0r
siebz0r

Reputation: 20339

If you want to access a bean after the page has been loaded it needs to be at least ViewScoped. RequestScoped beans are destroyed when the page is loaded (the request is handled and there is no need for it anymore).

Upvotes: 1

Related Questions