我在动态包含的页面上有一个奇怪的行为
我的第一页有一个组合可以从不同的页面中选择,包括:
<h:panelGrid columns="2">
<h:outputLabel value="Choose your page to include" />
<h:selectOneMenu id="pageList" value="#{anyPageBean.page}">
<f:selectItems value="#{anyPageBean.pageList}" var="w" itemValue="#{w}" itemLabel="#{w}" />
</h:selectOneMenu>
</h:panelGrid>
AnyPageBean 只返回以下 2 个页面之一:pilotNoTemplate.xhtml 或 pipo.xhtml
@ManagedBean
@SessionScoped
public class AnyPageBean {
private String page;
private java.util.List<String> pageList;
public AnyPageBean() {
super();
pageList = new ArrayList<String>();
pageList.add("pilotNoTemplate.xhtml");
pageList.add("pipo.xhtml");
}
当我选择该页面(pipo 页面)时,pilotNoTemplate.xhtml 正确显示。
但是当我从 PilotNoTemplate.xhtml 提交表单时,JSF 认为提交作为 POST 是可以的,但只有 Phase1 和 Phase 6 是跨越的,为什么?我有一个 PhaseListener 显示阶段,它打印:
INFO IN pour /jsf2-todo-001-dynamic-page-include-v2/any.faces ¤¤¤¤¤ POST
INFO AJAX BEFORE RESTORE_VIEW 1 for viewId=null
INFO AJAX AFTER RESTORE_VIEW 1 for viewId=/any.xhtml
INFO AJAX BEFORE RENDER_RESPONSE 6 for viewId=/any.xhtml
INFO AJAX AFTER RENDER_RESPONSE 6 for viewId=/any.xhtml
如果表格中填写了任何内容,它将被重置...
第二次提交没问题,所有阶段都跨越:
INFO IN pour /jsf2-todo-001-dynamic-page-include-v2/any.faces ¤¤¤¤¤ POST
INFO AJAX BEFORE RESTORE_VIEW 1 for viewId=null
INFO AJAX AFTER RESTORE_VIEW 1 for viewId=/any.xhtml
INFO AJAX BEFORE APPLY_REQUEST_VALUES 2 for viewId=/any.xhtml
INFO AJAX AFTER APPLY_REQUEST_VALUES 2 for viewId=/any.xhtml
INFO AJAX BEFORE PROCESS_VALIDATIONS 3 for viewId=/any.xhtml
INFO AJAX AFTER PROCESS_VALIDATIONS 3 for viewId=/any.xhtml
INFO AJAX BEFORE UPDATE_MODEL_VALUES 4 for viewId=/any.xhtml
INFO AJAX AFTER UPDATE_MODEL_VALUES 4 for viewId=/any.xhtml
INFO AJAX BEFORE INVOKE_APPLICATION 5 for viewId=/any.xhtml
INFO AJAX AFTER INVOKE_APPLICATION 5 for viewId=/any.xhtml
INFO AJAX BEFORE RENDER_RESPONSE 6 for viewId=/any.xhtml
INFO AJAX AFTER RENDER_RESPONSE 6 for viewId=/any.xhtml
我的模板页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<div>
<h:panelGroup id="globalMessages">
<h:messages globalOnly="false" styleClass="messages" />
</h:panelGroup>
<ui:insert name="content" />
</div>
</h:body>
</html>
合成页面,可以选择要包含的页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" >
<ui:composition template="/layout/template.xhtml">
<ui:define name="content">
<h:form id="chooseForm">
<h:panelGrid columns="2">
<h:outputLabel value="Choose your page to include" />
<h:selectOneMenu id="pageList" value="#{anyPageBean.page}">
<f:selectItems value="#{anyPageBean.pageList}" var="w" itemValue="#{w}" itemLabel="#{w}" />
</h:selectOneMenu>
</h:panelGrid>
<h:commandButton id="show" value="Show page">
<f:ajax event="click" execute="@form" render=":panelForDynaPage :globalMessages" />
</h:commandButton>
</h:form>
<h:panelGroup id="panelForDynaPage">
<ui:include id="includeContenu" src="#{anyPageBean.page}" />
</h:panelGroup>
</ui:define>
</ui:composition>
</html>
PilotNoTemplate.xhtml 页面:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<f:metadata>
<f:viewParam id="b" name="id" value="#{pilotAction.id}" />
</f:metadata>
<f:event id="a" listener="#{pilotAction.prepare}" type="preRenderView" />
<h:form id="formPilot">
<h:panelGrid columns="2">
<h:outputLabel value="#{appMsg['pilot.firstname']}" />
<h:inputText id="firstname" label="#{appMsg['pilot.firstname']}" value="#{pilotHolder.pilot.firstname}"
required="true" />
<h:outputLabel value="#{appMsg['pilot.lastname']}" />
<h:inputText id="lastname" label="#{appMsg['pilot.lastname']}" value="#{pilotHolder.pilot.lastname}" />
<h:outputLabel value="#{appMsg['pilot.age']}" />
<h:inputText id="age" label="#{appMsg['pilot.age']}" value="#{pilotHolder.pilot.age}" required="true"
validator="#{pilotAction.validateAge}" />
</h:panelGrid>
<h:commandButton id="merge" action="#{pilotAction.doMerge}"
value="#{pilotHolder.pilot.id ne null ? appMsg['pilot.update'] : appMsg['pilot.create']}">
<f:ajax id="ajaxm" event="click" execute="@form" render=":panelForDynaPage :globalMessages" />
</h:commandButton>
</h:form>
</ui:composition>
我注意给 xhtml 页面中的每个组件都赋予“id”,因为没有它就会出现这种问题,在我的情况下似乎是不够的。任何想法 ?
我看到其他人也有同样的问题,你找到解决办法了吗?