Input value not processed in request scoped bean when using conditional rendering

前端 未结 1 1421
自闭症患者
自闭症患者 2021-01-21 23:59

I know this type of question has been asked million times here, but I couldn\'t find a solution for my problem in relevant posts.

JSF 1.2

I have a request-scoped

相关标签:
1条回答
  • 2021-01-22 00:42

    You've there a rendered="#{DoStuff.pnlStep1}" on a parent component. During processing of the form submit, JSF will as part of attack safeguard determine if the input component (and all of its parents) is rendered according to the server side conditions. If it's not rendered, then it will simply be skipped altogether during the processing.

    That it works in a session scoped bean but fails in a request scoped bean indicates that the value behind rendered="#{DoStuff.pnlStep1}" is determined based on some request based variable/condition which was present during the request of displaying the form, but is absent during the request of processing the form submit.

    To fix this, you need to make sure that you preserve exactly the same variable/condition for the value behind rendered="#{DoStuff.pnlStep1}" during the request of processing the form submit. There are several ways to achieve this, depending on the nature of the condition and how you're submitting the form. One of the ways is to pass the request based variable/condition back as a request parameter by <f:param> or <h:inputHidden>.

    The canonical JSF 2.0 fix would be to put the bean in the view scope which is not available in JSF 1.2, but can be simulated using Tomahawk's <t:saveState> component.

    See also:

    • JSF 1.2: How to keep request scoped managed bean alive across postbacks on same view?
    • How to call an action method of a UICommand Component which was rendered conditionally?
    0 讨论(0)
提交回复
热议问题