【发布时间】:2015-04-15 08:49:06
【问题描述】:
我正在尝试借助按钮动态地提供一些内容,即没有专门的页面。上述内容已正确加载,但无法正常工作。
布局是这样的:
<p:outputPanel style="width: 100%; height: 100%; overflow: auto;" id="contentPanel">
<c:choose>
<c:when test="#{empty requestComposition}">
<ui:insert name="body">Content</ui:insert>
</c:when>
<c:otherwise>
<ui:include src="#{requestComposition}" />
</c:otherwise>
</c:choose>
</p:outputPanel>
加载内容的按钮是这样的(在另一个输出面板里面):
<p:commandButton value="Load Dynamic" update=":contentPanel" actionListener="#{applicationController.processActionButton('/dynamic')}" />
动作监听器是这样的:
public void processActionButton(String target){
if(target == null || target.isEmpty()){
return;
}
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest req = (HttpServletRequest)context.getExternalContext().getRequest();
req.setAttribute("requestComposition", "/WEB-INF/templates" + target + ".xhtml");
}
dynamic.xhtml是这样的:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<p:outputPanel style="width: 100%; padding-top: 20px;">
<p:outputPanel style="width: 60%; margin: 0 auto;">
<p:outputPanel style="text-align: center; color: gold; font-weight: bold;">Dynamic</p:outputPanel>
<p:messages id="messages" />
<h:form>
<p:panelGrid columns="2" style="width: 100%;">
<p:outputLabel value="Item" for="idItem" />
<p:outputPanel style="display: block; padding-right: 10px;" layout="inline">
<p:inputText value="#{bean.item}" id="idItem" style="width: 100%;" required="true" />
</p:outputPanel>
</p:panelGrid>
<p:outputPanel style="text-align: center;">
<p:commandButton value="Process" style="margin: 5px;" update=":growl" onclick="PrimeFaces.widgets.widget_#{fn:replace(component.clientId, ':', '_')}.disable()" oncomplete="PrimeFaces.widgets.widget_#{fn:replace(component.clientId, ':', '_')}.enable()" actionListener="#{applicationController.dummyAction}" />
<p:commandButton value="Dummy" style="margin: 5px;" update=":growl" actionListener="#{applicationController.dummyAction}" process="@this" />
</p:outputPanel>
</h:form>
</p:outputPanel>
</p:outputPanel>
</ui:composition>
当单击任何按钮时,表单显然已提交,但未执行操作侦听器。 当 dynamic.xhtml 作为页面内容加载时,表单提交,但动作监听器仅针对第二个按钮(标记为 Dummy)触发,因为进程 @this,在这种情况下不再提交表单。我可以通过在输入元素中添加 onchange 来解决不使用 process@this 提交的表单,但我不明白为什么在动态加载时它不起作用。
谢谢
【问题讨论】:
-
布局中也有表格吗?浏览器控制台中什么都没有?
-
我没有嵌套表单并且控制台很干净。我正在使用 Chrome,唯一的变化是在“网络”选项卡中,它显示它正在发布到服务器并得到 OK 回复。
-
这是可以接受的骗局吗? stackoverflow.com/questions/7108668/…
-
很接近了。我知道我可以有一个 bean 属性来存储要显示的“页面”,但是这种方法意味着当我刷新页面时,我仍然会获得该内容,我不希望这种情况发生。该项目很小,所以我不想打扰完整的 ACL 设置。我检查了生成的源代码,它包含 viewState 隐藏字段,我还添加了 fixview 脚本,但无济于事。
标签: jsf primefaces dynamic-content