Search code examples
templatesprimefacesmenubar

Why menubar is not working with ui:include in Primefaces


<ui:composition>
        <h:form>
           <p:menubar>
                    <p:menuitem id="signup" value="signup" label="Sign Up" action="goSignUp"/>
           </p:menubar>

            <h:commandButton  id ="signup2" value="signup2" label="Sign Up" action="goSignUp" />

        </h:form>
 </ui:composition>

Why the upper one is NOT working and normal command button is working? I am including menuBar.xhtml to my page and after that menus are not working any more. If I Implement them straight to the original page without including them, they are working fine, why? Primefaces version 3.1 and JSF2.0 + Glassfish 3.1.

Cheers, Sami


Solution

  • Ive checked your problem in my environment and have to say that it workes for me although I've made some minor changes.

    First I've created the composition page in my /WEB-INF/template/ folder:

    <body>
      <ui:composition>
        <p:menubar>
          <p:menuitem id="signup" value="signup" label="Sign Up" action="goSignUp" ajax="false"/>
        </p:menubar>
    
        <h:commandButton id="signup2" value="signup2" label="Sign Up" action="goSignUp" />
      </ui:composition>
    </body>
    

    And after that I've inserted it into my .xhtml file:

    <f:view>
      <h:body>
        <h:form>
            <ui:include src="/META-INF/template/navbar.xhtml" />
        </h:form>
      </h:body>
    </f:view>
    

    Everything workes great.
    Maybe you noticed the ajax="false" attribute set on the <p:menuitem> tag. This value is set to true per default and stops the JSF implementation to execute its default lifecycle. By setting it to false you'll get the regular JSF behavior.

    Hope this helped, have Fun!