How can we use multiple tags or tags in a single JSF page?

后端 未结 1 804
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 05:14

My problem is that I have 2 forms in a single JSF page each having its or tag. As we know the message/messages

相关标签:
1条回答
  • 2021-01-15 05:43

    If you're using JSF 2, then you could just submit and update the form by ajax. This allows for partially updating the view.

    <h:form>
        <h:messages />
        ...
        <h:commandButton ...>
            <f:ajax execute="@form" render="@form" />
        </h:commandButton>
    </h:form>
    
    <h:form>
        <h:messages />
        ...
        <h:commandButton ...>
            <f:ajax execute="@form" render="@form" />
        </h:commandButton>
    </h:form>
    

    Or if you can't/don't want to use ajax for some unobvious reason, or are still using the legacy JSF 1.x, then check in the rendered attribute of <h:messages> if the desired form is been submitted or not.

    <h:form binding="#{form1}">
        <h:messages rendered="#{form1.submitted}" />
        ...
        <h:commandButton ... />
    </h:form>
    
    <h:form binding="#{form2}">
        <h:messages rendered="#{form2.submitted}" />
        ...
        <h:commandButton ... />
    </h:form>
    

    The <h:message> shouldn't have this problem by the way, in contrary to what you're implying in your question.

    0 讨论(0)
提交回复
热议问题