移行時に、FacesContext の現在のインスタンスで FacesMessage をレンダリングせずにフロー リダイレクトします (MessageContext と同じ問題) FacesContext に FacesMessage が存在することを確認しましたが、これは正しいですが、理由により、コンテキスト内部にメッセージが含まれています
春のアプリケーションコンテキスト:
<faces:resources/>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"
p:order="1"
p:flowRegistry-ref="flowRegistry">
<property name="defaultHandler">
<!--If no flow match, map path to a view to render; e.g. the "/home" path
would map to the view named "home" -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
</property>
</bean>
<bean id="faceletsViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:viewClass="org.springframework.faces.mvc.JsfView"
p:prefix="/WEB-INF/"
p:suffix=".xhtml"/>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter"
p:flowExecutor-ref="flowExecutor"/>
<webflow-config:flow-executor id="flowExecutor">
<webflow-config:flow-execution-listeners>
<webflow-config:listener ref="facesContextListener"/>
<webflow-config:listener ref="jpaFlowExecutionListener"/>
<webflow-config:listener ref="securityFlowExecutionListener"/>
</webflow-config:flow-execution-listeners>
</webflow-config:flow-executor>
<webflow-config:flow-registry id="flowRegistry"
flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
<webflow-config:flow-location-pattern
value="/**/*-flow.xml"/>
</webflow-config:flow-registry>
<faces:flow-builder-services id="facesFlowBuilderServices"
development="true"/>
<bean id="facesContextListener"
class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
<bean id="jpaFlowExecutionListener"
class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
<constructor-arg ref="entityManagerFactory"/>
<constructor-arg ref="transactionManager"/>
</bean>
<bean id="securityFlowExecutionListener"
class="org.springframework.webflow.security.SecurityFlowExecutionListener"/>
コントローラー:
@Named("registrationController")
class RegistrationController implements Serializable {
@Inject
@LangServiceQualifier
ILangService langService
@Inject
@RegistrationServiceQualifier
IRegistrationService registrationService
void validate(RegistrationModel model) {
model.user.profile.lang ?: model.user.profile.setLang(registrationLang())
try {
registrationService.validate(model)
model.header = new RequestHelper(request: FacesUtils.request).header
} catch (RegistrationException re) {
FacesContext context = FacesUtils.context
re.messages.each {
switch (it) {
case new UsernameAlreadyExistsException().message:
context.addMessage("register_form_username_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: FacesUtils.bundle.getString(it)))
break
case new PrimaryEmailAlreadyExistsException().message:
context.addMessage("register_form_currentEmailValue_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: FacesUtils.bundle.getString(it)))
break
case new EmailRetypeException().message:
context.addMessage("register_form_currentEmailValueRetype_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: FacesUtils.bundle.getString(it)))
break
case new PasswordRetypeException().message:
context.addMessage("register_form_password_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: FacesUtils.bundle.getString(it)))
break
}
}
}
}
春のウェブフロー定義:
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<on-start>
<evaluate expression="requestParameters.contains('from')?requestParameters.get('from'):'home'"
result="flowScope.from"/>
<evaluate expression="registrationService.initModel()"
result="flowScope.model"/>
</on-start>
<view-state id="enterRegistration" model="model">
<transition on="cancelRegistrationAction" to="exitRegistrationAction"/>
<transition on="validateRegistrationAction" to="reviewRegistration">
<evaluate expression="registrationController.validate(model)"/>
</transition>
</view-state>
<view-state id="reviewRegistration" model="model">
<transition on="cancelRegistrationAction" to="exitRegistrationAction"/>
<transition on="reviseRegistrationAction" to="enterRegistration"/>
<transition on="confirmRegistrationAction" to="exitRegistrationAction">
<evaluate expression="registrationService.register(model)"/>
</transition>
</view-state>
<end-state id="exitRegistrationAction" view="externalRedirect:#{from}"/>
<on-end>
<evaluate expression="registrationController.clearRegistrationModel(flowScope.model)"/>
</on-end>
JSF ページ:
<h:form id="register_form">
<p:messages id="register_form_messages_id"/>
<p:outputLabel for="register_form_username_inputText_id"
value="#{msgs['user.username.label']}"/>
<p:inputText id="register_form_username_inputText_id"
label="#{msgs['user.username.label']}"
value="#{model.username}"/>
<p:outputLabel for="register_form_currentEmailValue_inputText_id"
value="#{msgs['user.currentEmailValue.label']}"/>
<p:inputText id="register_form_currentEmailValue_inputText_id"
label="#{msgs['user.currentEmailValue.label']}"
value="#{model.email}"/>
<p:outputLabel
for="register_form_currentEmailValueRetype_inputText_id"
value="#{msgs['user.currentEmailValueRetype.label']}"/>
<p:inputText
id="register_form_currentEmailValueRetype_inputText_id"
label="#{msgs['user.currentEmailValueRetype.label']}"
value="#{model.emailRetype}"/>
<p:outputLabel for="register_form_password_inputText_id"
value="#{msgs['user.password.label']}"/>
<p:password id="register_form_password_inputText_id"
label="#{msgs['user.password.label']}"
value="#{model.password}"/>
<p:outputLabel for="register_form_passwordRetype_inputText_id"
value="#{msgs['user.passwordRetype.label']}"/>
<p:password id="register_form_passwordRetype_inputText_id"
label="#{msgs['user.passwordRetype.label']}"
value="#{model.passwordRetype}"/>
<p:commandButton
id="exit_registration_cmd_btn_id"
action="cancelRegistrationAction"
value="#{msgs['cancel.button']}"
immediate="true"/>
<p:commandButton
id="validate_registration_cmd_btn_id"
action="validateRegistrationAction"
value="#{msgs['register.label']}"
update="@form"
ajax="false"/>
</h:form>
私はopenjdk7 tomcat7 mojarra primefacesで実行していますが、問題はglassfish 3.1.2、groovy eclipseコンパイラを使用したgroovy 2.0.5、spring 3.2、spring webflow 2.3.1でも同じです