Announcement Announcement Module
Collapse
No announcement yet.
On transition evaluate redirect to a view without showing FacesMessage Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • On transition evaluate redirect to a view without showing FacesMessage

    Hello
    On transition, my flow redirect without rendering the FacesMessage contained in the FacesContext current instance, the issue is the same with the MessageContext.

    The service layer is functionally tested so it might not come from this area.

    the whole code is available there

    the portion who should causing troubles are linked there :
    RegistrationController.groovy

    enterRegistration.xhtml

    web.xml

    applicationContext.xml


    in the flow xml definition file the statement
    PHP Code:
        <view-state id="enterRegistration" model="model">
            <
    transition on="cancelRegistrationAction" to="exitRegistrationAction"/>
            <
    transition on="validateRegistrationAction" to="reviewRegistration">
                <
    evaluate expression="registrationController.validate(model)"/>
            </
    transition>
        </
    view-state
    should display the facesmessages, instead it's redirect to the next step on the next view with messages into the facescontext (spyed on the console) but not rendered
    Last edited by Khaled.Noordin; Jan 25th, 2013, 09:58 AM.

  • #2
    what's wrong?

    Comment


    • #3
      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(
                          
      requestcontext
                                  
      .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(
                                              
      severityFacesMessage.SEVERITY_ERROR,
                                              
      summarybundle.getString(it))
                              break
                          case new 
      PrimaryEmailAlreadyExistsException().message:
                              
      context.addMessage "register_form_currentEmailValue_inputText_id",
                                      new 
      FacesMessage(
                                              
      severityFacesMessage.SEVERITY_ERROR,
                                              
      summarybundle.getString(it))
                              break
                          case new 
      EmailRetypeException().message:
                              
      context.addMessage "register_form_currentEmailValueRetype_inputText_id",
                                      new 
      FacesMessage(
                                              
      severityFacesMessage.SEVERITY_ERROR,
                                              
      summarybundle.getString(it))
                              break
                          case new 
      PasswordRetypeException().message:
                              
      context.addMessage "register_form_password_inputText_id",
                                      new 
      FacesMessage(
                                              
      severityFacesMessage.SEVERITY_ERROR,
                                              
      summarybundle.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>
      Last edited by Khaled.Noordin; Jan 29th, 2013, 07:01 PM.

      Comment


      • #4
        the first version of the method was returning void wich was relevant for the evaluate who seems in that case let the the flow transite to next step, so the initial problem was to give a boolean value as a return value in the method evaluated in the evaluate balise.... end of story

        Comment

        Working...
        X