我有一个带有身份验证的页面,这个页面是我的模板页面,其中有菜单。
<navigation-rule>
<from-view-id>pages/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>userOK</from-outcome>
<to-view-id>pages/template.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>userNOK</from-outcome>
<to-view-id>pages/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
我的页面template.xhtml
<h:form>
<p:menu type="plain" style="width:200;box-shadow: 6px 6px 6px black;top:-18;left:-40" >
<p:submenu label="Dossier" id ="Dossier" >
<p:menuitem update=":contentform,:messages" value="Nouveau Dossier" action="#{choix.setPage('ajoutDossier')}"
....
....
</h:form>
<h:form id="contentform" >
<h:panelGroup rendered="#{choix.page == 'ajoutDossier'}">
<ui:include src="Dossier/ajoutDossier.xhtml" />
</h:panelGroup>
....
....
</h:form>
问题是在第一次点击时没有调用动作我必须点击2次,然后在我点击很多时间之前没有调用动作,有时候juste p:子菜单在最后一个位置工作< / p>
当它没有前进时,只有页面template.xhtml才有效!
答案 0 :(得分:1)
您没有利用JSF模板。您可以在一个页面中拥有所有内容,而不是使用模板和多个模板客户端;并有条件地渲染东西。查看此tutorial或任何其他有关jsf tempaltes的教程
通常你会有一个模板,它具有所有页面共有的所有布局和内容;并根据需要多次使用标记<ui:insert name="title" >Default content</ui:insert>
(使用不同的名称)。然后创建模板客户端,使用
<ui:composition template="./../resources/templates/templateFile.xhtml">
然后使用标记<ui:define name="nav2">
设置要包含在模板中的内容。
除此之外,关于代码中导航的问题:当您进行导航时,您不会更新内容,因为导航后页面已完全加载(无ajax)。首先,您必须删除更新属性;而且你必须将p:menuitem的“ajax”属性设置为false;因为默认情况下这是真的。否则不会进行导航 如果您做得不错,则不需要导航规则中的重定向属性。它可以与前锋完美配合。转发的唯一问题是浏览器URL不会更改,因为浏览器不会通知导航。
答案 1 :(得分:0)
我发现解决方案我必须在有问题的页面的<redirect />
之后添加<to-view-id>
,因为我读到JSF使用内部FORWARD而不是REDIRECT导航到成功页面这就是为什么URL不会改变,但我真的不明白为什么??
这是代码工作:
<navigation-rule>
<from-view-id>pages/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>userOK</from-outcome>
<to-view-id>pages/template.xhtml</to-view-id>
<redirect />
</navigation-case>
<navigation-case>
<from-outcome>userNOK</from-outcome>
<to-view-id>pages/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
也不要松开重定向页面的CSS我必须添加这个
<link rel="stylesheet" href="#{request.contextPath}/css/style.css" />