Matthias Kahlau wrote:
Hi!
I have a page with a form that contains some input elements like inputText
etc. When I change the selection in a selectOneMenu, the page is submitted
(immediate = true), and the valueChangeListener invoked, and then the render
response phase is directly processed and the page redisplayed with all the
content that I added in the input components previously. All is fine.
But when I leave the page to get to a second page (to edit details) via a
commandLink (immediate = true), and then cancel back to the first page
(immediate = true), it seems that all input components of the first page are
resetted to their original state, and the text I inputted is deleted.
Can anybody explain, why JSF behaves like I described, and how I can prevent
the input components from beeing resetted?
Values in JSF can be sitting in two places:
* just in the component
* pushed into the "model"
When "immediate" + renderResponse is being used, the values sit in the
component and never get pushed into the model.
And when you navigate to a different view, the old view (including its
associated components) gets discarded. On return to the page a new set
are created.
So what you're seeing is exactly what's expected. You're such a heavy
user of immediate+renderResponse that values never get pushed to
somewhere that they can be made persistent across views.
So, about "fixing" the behaviour:
I expect you could use "immediate=false" on the commandlink. Assuming
all these input fields you're worried about have value-bindings, that
will push the values into your backing beans. On return to the page, the
components will then pull them back from the backing beans. However
validation *will* be applied when the link is clicked, and if validation
fails then navigation to the details page will be prevented.
Or you could make your selectOneMenu non-immediate, and don't use
renderResponse. Again, that will cause data to be pushed to a backing
bean from which it can later be retrieved by a new copy of the view.
There was some work done a while ago on saving views away to handle
back-button usage. Maybe that could help you, but I don't know much
about it.
Regards,
Simon