Search code examples
templatesjsfprimefacesfacelets

menuitem actionListener is not invoked when form is enclosed in a template


When I use a <p:menuButton> as follows:

<div id="div_menutop">
    <h:form id="form_top">    
        <p:menubar id="mnb_top" >  
            <p:submenu label="Help" icon="ui-icon-help">  
                <p:menuitem ajax="true"  process="@this" id="mn_item_help" update="@form" value="Hướng dẫn" actionListener="#{topprocess.helpListener}"/>  
            </p:submenu> 
        </p:menubar>  
        <p:commandButton ajax="false" action="#{secuser.logout()}" value="Thoát" />
        <p:commandButton ajax="true" actionListener="#{topprocess.helpListener}" value="Thoát" />
    </h:form>  
</div>

Then it works, the actionListener is called.

But when I try to put it in a template composition as follows:

<ui:composition>
    <div id="div_menutop">
        <h:form id="form_top">    
            <p:menubar id="mnb_top" >  
                <p:submenu label="Help" icon="ui-icon-help">  
                    <p:menuitem id="mn_item_help" update="@form" value="Hướng dẫn" actionListener="#{topprocess.helpListener}"/>  
                </p:submenu> 
            </p:menubar>  
        </h:form>  
    </div>
</ui:composition>

Then the actionListener is never called. What can be the cause of this problem?


Solution

  • That can happen if you're nesting forms. I.e. when the template client has already another <h:form>. This is illegal in HTML and the browser behaviour is then unspecified. Some browsers will then send only the data of the outer form, other browsers will send nothing. If JSF hasn't received the parameter name=value of the action, then it won't invoke anything.

    You need to remove one of those forms so that they aren't nested anymore.

    See also: