ui:include with方法破坏了jsf的ajax函数 [英] ui:include with method breaks the jsf's ajax function
问题描述
我面临一个非常相似的问题,我已经在该问题上做了票,但是现在这个问题出现在我的主项目中.上一张票涉及一个测试项目.此处链接到故障单.我将首先简要说明我的项目,然后提供代码.
I'm facing a pretty similar issue on which I already made a ticket but now the problem arises in my main project. The previous ticket involved a test project. Here's the link to the ticket. I'll first explain my project briefly and then provide the code.
这是一个基本的ui,因为我省略了不相关的部分,但是当您启动webapp时,您应该定向到通过使用ajax加载了简介的主页.我正在使用一个名为Navigation的托管bean,它是一个简单的pojo,带有2个注释和一个名为'page'的字符串属性.我已将该属性设置为'intro',因此默认情况下已加载它.
It's a basic ui since I left out irrelevant parts, but when you start the webapp you should be directed to the main page which has an intro loaded through the use of ajax. I'm using a managedbean called Navigation which is a simple pojo with 2 annotations and one string property called 'page'. I've set the property to 'intro', so it's loaded by default.
// Navigation.java
@ManagedBean
@RequestScoped
public class Navigation {
private String page = "intro";
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
index.xhtml看起来像这样:
index.xhtml looks like this:
<!-- index.xhtml -->
<h:body>
<!-- Navigation -->
<h:form>
<p:menubar>
<p:menuitem value="Home" icon="ui-icon-home" action="#{navigation.setPage('intro')}" update=":contentPanel" />
<p:submenu label="Actions" icon="ui-icon-transferthick-e-w">
<p:submenu label="Employee">
<p:menuitem value="Search" action="#{navigation.setPage('employee/find')}" update=":contentPanel" />
</p:submenu>
</p:submenu>
</p:menubar>
</h:form>
<!-- ContentPanel -->
<p:panel id="contentPanel" styleClass="content">
<ui:include src="/#{navigation.page}.xhtml" />
</p:panel>
</h:body>
现在,当您导航到操作/员工/新建"时,find.xhtml文件确实加载到了主页中,但是表单本身不起作用.这是文件:
Now, when you navigate to 'Actions/Employee/Create new' the file find.xhtml does get loaded into the main page but, the form itself doesn't work. Here's the file:
<!-- find.xhtml -->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<f:facet name="header">
Create new employee
</f:facet>
<h:outputLabel value="User ID: " for="userId" />
<p:inputText value="#{managedEmployee.userId}" id="userId" />
<p:commandButton value="Show" update="result" />
<h:outputText id="result" value="#{managedEmployee.userId}" />
</ui:composition>
因此,用户将能够在表单中输入userId,并且当按下commandbutton时,它将在表单附近显示.显然我必须做错了什么,但似乎无法弄清楚.我不喜欢这样说,但我迫切希望得到一个答案.
So a user would be able to input a userId in the form and it would be displayed near the form when commandbutton is pressed. Obviously I must be doing something wrong but I can't seem to figure it out. I don't like saying it, but I'm desperate for an answer.
提前谢谢!
推荐答案
我已经找到了解决问题的方法.不知道是什么原因,但是如果我在ui:composition中将代码与h:form包围在一起,并添加该表单ID以在链接上进行更新,那么它会起作用.希望这对其他人有帮助.干杯
I've found a solution for my problem. Not sure what the reason is but if I surround the code in ui:composition with h:form and add that form id to update on the link it works. Hope this helps others when they encounter it. Cheers
<p:menuitem value="Create" action="#{navigationBean.setPage('employee/create')}" update=":contentPanel :form" />
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:form id="form">
...
</h:form>
</ui:composition>
这篇关于ui:include with方法破坏了jsf的ajax函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!