我正在尝试使用带有Primefaces的向导(ViewScoped)。我创建了包含4个选项卡的页面。导航第一个选项卡后,用户到达第二个选项卡,用户在第二个选项卡页面的输入文本字段中输入一些值。当用户从第二个选项卡转到上一个或下一个选项卡并返回到第二个选项卡时,除第一个选项卡外,所有输入的值都将丢失。除第一个选项卡外,验证也不起作用。是否有解决此问题的方法?这是我的HTML代码:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
template="template/template.xhtml">
<ui:define name="body">
<h:graphicImage value="resources/myimage.jpg" />
<!-- First Tab -->
<h:form id="form">
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard flowListener="#{myView.onFlowProcess}" widgetVar="wiz">
<p:tab id="person" title="PERSON">
<p:panel header="">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="NAME :" />
<p:inputText value="#{myView.user.firstname}" label="Name" validatorMessage="NAME ERROR">
<f:validateRegex pattern="[a-zA-Z]{2,50}+"/>
</p:inputText>
<h:outputText value="SURNAME: *" />
<p:inputText value="#{myView.user.lastname}" label="Surname" validatorMessage="SURNAME ERROR">
<f:validateRegex pattern="[a-zA-Z]{2,60}+"/>
</p:inputText>
<h:outputText value="obligatory" style="color:red;"/>
</h:panelGrid>
</p:panel>
</p:tab>
<!-- ADDRESS -->
<p:tab id="address" title="ADDRESS">
<p:panel header="">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="cellular Phone" />
<p:inputMask id="cellularPhone" value="#{myView.user.cellularPhone}" mask="59999999999" required="true" requiredMessage="CELLULAR PHONE CANNOT BE EMPTY"/>
<h:outputText value="Cellular Phone :" style="color:red;" />
<h:outputText value="" />
<h:outputText value="Email :" />
<p:inputText value="#{myView.user.email}" />
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="country" value="country" />
<p:selectOneMenu id="country" value="#{dropDownView.country}" style="width:150px">
<p:ajax listener="#{dropDownView.onCountryChange}" update="city" />
<f:selectItem itemLabel="please Select" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{dropDownView.countries}" />
</p:selectOneMenu>
<p:outputLabel for="city" value="city" />
<p:selectOneMenu id="city" value="#{dropDownView.city}" style="width:150px">
<f:selectItem itemLabel="please Select" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{dropDownView.cities}" />
</p:selectOneMenu>
</h:panelGrid>
<p:separator />
<h:outputText value="obligatory" style="color:red;"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="PAYMENT">
<p:panel header="">
<p:commandButton value="SAVE" action="#{myView.save}" update="growl" oncomplete="wiz.next();" process="@this" validateClient="true"/>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
</ui:define>
</ui:composition>