Ok I found a workaround, but still dont know what "court-circuite" the JSF lifecycle to not let the message be displayed inside an evaluate of a transition, so I had to use a decision-state to block the transition and change the controller method signature
PHP Code:
import javax.faces.application.FacesMessage
import javax.faces.context.FacesContext
import javax.inject.Inject
import javax.inject.Named
import javax.servlet.http.HttpServletRequest
@Named("registrationController")
class RegistrationController {
static final Logger log = LoggerFactory.getLogger(RegistrationController)
@Inject
@LangServiceQualifier
ILangService langService
@Inject
@RegistrationServiceQualifier
IRegistrationService registrationService
Lang registrationLang() {
return langService.supportedLangs.find {
it.code == FacesContext
.currentInstance
.externalContext
.requestLocale
.language
} as Lang ?: langService.defaultLang
}
Boolean validateModel(RegistrationModel registrationModel) {
FacesContext context = FacesContext.currentInstance
ResourceBundle bundle = ResourceBundle.getBundle(
II18nConfigService.BUNDLE_BASE_NAME_VALUE,
context.viewRoot.locale,
Thread.currentThread().contextClassLoader)
registrationModel.user.profile.lang ?: registrationModel.user.profile.setLang(registrationLang())
try {
registrationService.validate(registrationModel)
registrationModel.header = new RequestHelper(
request: context
.externalContext
.request as HttpServletRequest).header
} catch (RegistrationException re) {
assert !re.messages.empty
re.messages.each {
switch (it) {
case new UsernameAlreadyExistsException().message:
context.addMessage "register_form_username_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: bundle.getString(it))
break
case new PrimaryEmailAlreadyExistsException().message:
context.addMessage "register_form_currentEmailValue_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: bundle.getString(it))
break
case new EmailRetypeException().message:
context.addMessage "register_form_currentEmailValueRetype_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: bundle.getString(it))
break
case new PasswordRetypeException().message:
context.addMessage "register_form_password_inputText_id",
new FacesMessage(
severity: FacesMessage.SEVERITY_ERROR,
summary: bundle.getString(it))
break
}
}
return Boolean.FALSE
}
return Boolean.TRUE
}
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<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.registrationModel"/>
</on-start>
<view-state id="enterRegistration" model="registrationModel">
<transition on="validateRegistrationAction" to="isValidModelDecision">
<evaluate expression="registrationController.validateModel(registrationModel)"
result="flowScope.isValidModel"/>
</transition>
<transition on="cancelRegistrationAction" to="exitRegistrationAction" history="discard"/>
</view-state>
<decision-state id="isValidModelDecision">
<if test="isValidModel" then="reviewRegistration" else="enterRegistration"/>
</decision-state>
<view-state id="reviewRegistration" model="registrationModel">
<transition on="reviseRegistrationAction" to="enterRegistration"/>
<transition on="confirmRegistrationAction" to="exitRegistrationAction">
<evaluate expression="registrationService.register(registrationModel)" />
</transition>
<transition on="cancelRegistrationAction" to="exitRegistrationAction" history="discard"/>
</view-state>
<end-state id="exitRegistrationAction" view="externalRedirect:#{from}"/>
</flow>