0

I have template like here: http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/

i add menu navigation:

<h:form id="form">
    <div id="page">

        <div id="header">
            <ui:insert name="header" >
                <ui:include src="/pages/template/header.xhtml" />
            </ui:insert>
            <f:ajax render="ContentLoader">
                  <h:commandLink actionListener="#{contentPage.setPage('/pages/first.xhtml')}" value="About Us" />
                  <h:commandLink actionListener="#{contentPage.setPage('/pages/login.xhtml')}" value="Contact Us" />
               </f:ajax>
        </div>
        <h:panelGroup id="ContentLoader" >
        <div id="content">
            <ui:insert name="content" >
                <ui:include src="#{contentPage.page}" />
            </ui:insert>
        </div>
        </h:panelGroup>
    </div>
    </h:form>

links are working fine, but i have problem with redirect content by useing <h:commandButton action="link"> which is in content

how can i fix this problem? maybe it's something wrong with my layout? or how to correctly redirect from content to another content, useing buttons which are in contents?

justnobody
  • 3
  • 1
  • 5
  • `` this is not how you do redirects/navigation. You need to supply `action` with a method binding of your backing bean with a return type of `String` and the path to the next page as the value. – noone Aug 29 '13 at 20:07
  • yes, I find that the best way is to implement links in faces-config, and then method of bean will only return string with name of page. – justnobody Aug 29 '13 at 20:22
  • ah okey now i understood:) binding replace action;] – justnobody Aug 29 '13 at 20:38
  • @noone: untrue -again, http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener/3909382#3909382 justnobody: please ignore his advice, he somehow expected that this would never work. Using bean action methods which solely return a static string would only add unnecessary clutter. – BalusC Aug 30 '13 at 00:28
  • @BalusC Well the documentation of the `h:commandButton` (http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/h/commandButton.html) doesn't give any hint that this might work as well. So yeah, I somehow expected that this would never work... "Type: `javax.el.MethodExpression` (signature must match `java.lang.Object action()`)" seems quite strict. – noone Aug 30 '13 at 03:49

1 Answers1

0

As to your concrete problem, it's likely caused by the combination <ui:include src="#{...}"> and a view scoped bean. This construct works only if you upgrade to at least Mojarra 2.1.18. Otherwise, the view scoped bean will fail to restore and be newly recreated and therefore the default value of #{contentPage.page} will be considered when any form actions inside the page are to be decoded. Upgrading to at least Mojarra 2.1.18 should fix your problem. You can get it at http://javaserverfaces.java.net. It's currently already at 2.1.25.

As to your concrete functional requirement, using command links/buttons for plain page-to-page navigation is a poor practice. You should be using output links/buttons for this.

<h:button value="navigate" outcome="link" />

or

<h:link value="navigate" outcome="link" />
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555