Form submit in conditionally rendered component is not processed

后端 未结 1 1069
忘了有多久
忘了有多久 2020-11-28 16:28

I have a custom tagfile with a form:


    
        

        
相关标签:
1条回答
  • 2020-11-28 16:53

    Your concrete problem is caused by 2 facts:

    1. When JSF needs to decode a form submit action or a submitted input value, then it also checks if the component is rendered or not (as safeguard against hacked/tampered requests).
    2. Request scoped beans are recreated on every HTTP request (an ajax request counts also as one request!).

    In your specific case, the rendered condition has evaluated false while JSF needs to decode the form submit action and therefore the non-rendered input/command components are never processed.

    Putting the bean in view scope should fix it. Below example assumes JSF 2.x.

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    
    @ManagedBean
    @ViewScoped
    

    And below example assumes JSF 2.2+ with CDI:

    import javax.inject.Named;
    import javax.faces.view.ViewScoped;
    
    @Named
    @ViewScoped
    

    Or, if the techncial requirement is to keep the bean in request scope, then carry around the condition behind rendered attribute in a <o:inputHidden>. Adjust your snippet to include it in the <h:form>.

    <o:inputHidden value="#{backingTest.flag}" />
    

    See also:

    • commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated - point 6
    • How to choose the right bean scope?
    0 讨论(0)
提交回复
热议问题