2

I am using templates, which in my main template I have a

<ui:include src="#{navBean.content}.xhtml">

My problem is that the action method of any bean, is not called having been run on the previous page . Here is an example where when you click the menu on the first page, an ajax call is made, the action method is executed and the page content loaded. By clicking the link on the loaded page(page1) the action method is not executed.

Config: jsf 2.2.9 | primefaces 5.1 | tomcat 8.0.3

template.xhtml

<div>
    <div>
        <h:form>
            <p:slideMenu>
                <p:submenu label="Cat 1">
                    <p:menuitem value="page1" action="#{navBean.changeMenuContent('page1')}" update=":change"/>
                    <p:menuitem value="bla"/> 
                </p:submenu>
            </p:slideMenu>
        </h:form>
    </div>
    <div>
        <h:form id="change">
            <ui:include src="/#{navBean.content}.xhtml"/>
        </h:form>
    </div>
</div>

navBean:

@ManagedBean(name = "navBean")
@RequestScoped
public class NavigationBean
{
    private String content = "index";
    public void changeMenuContent(String content)
    {
        setContent(content);
    }
    //get set...
}

page1.xhtml

<p:commandLink value="teste" action="#{navBean.changeMenuContent('page2')}" ajax="false"/>

The page2 has only one <p: outputLabel />, for test.

I've tried with p:commandLink and h:commandLink

Thanks!

Vitor Freitas
  • 166
  • 1
  • 10

2 Answers2

0

Try add update=":change"on:

<p:commandLink value="teste" action="#{navBean.changeMenuContent('page2')}" ajax="false" update=":change />

See the changeMenuContent is void, so it does not cause page navigation.

So you need to run "update" manually.

See also, that your Bean is @RequestScope, therefore its contents are recreated on every request.

So the most recommended would change the Bean to @SessionScope, and:

<p:commandLink value="teste" actionListener="#{navBean.changeMenuContent('page2')}" update=":change />
0

Could you check your browser for any JS errors? Im getting a "TypeError: b is undefined" in Firebug while trying to replicate this issue. It seems to be related to Primefaces 5.x version. When i rollback to version 4.0 it works fine.

Emil Kaminski
  • 1,886
  • 2
  • 16
  • 26