Announcement Announcement Module
Collapse
No announcement yet.
FacesContext is null in web flow 2.0.5 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FacesContext is null in web flow 2.0.5

    hi
    on rendering the page i fill the h:selectOneMenu if error occured i create a message with FacesContext.getCurrentInstanece()..........
    but FacesContext.getCurrentInstanece() is null.

    this is my code
    search-flow.xml
    Code:
    	
    <view-state id="list" view="../test/search.xhtml">
    
    	<on-render>
    		<evaluate expression="search.getAccounts()" result="flowScope.accounts"/>
    
    	</on-render>
    		<transition on="cancel" to="end" />
    	</view-state>
    Code:
    	public List<SelectItem> getAccounts() {
    
        	try {
               
                ......
        	}
        	catch (Exception e) {
        		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "error", ""));
        	}
    
        }
    web-mvc.xml

    Code:
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    		<property name="flowRegistry" ref="flowRegistry" />
    		<property name="defaultHandler">
    			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    		</property>
    	</bean>
    
    	<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
    		<property name="prefix" value="/test/" />
    		<property name="suffix" value=".xhtml" />
    	</bean>
    
    	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor" />
    	</bean>
    web-flow.xml

    Code:
    <webflow:flow-executor id="flowExecutor">
    		<webflow:flow-execution-listeners>
    			<webflow:listener ref="securityFlowExecutionListener" />
    		</webflow:flow-execution-listeners>
    		<webflow:flow-execution-attributes>
    			<webflow:always-redirect-on-pause value="false"/>
    		</webflow:flow-execution-attributes>
    	</webflow:flow-executor>
    
    	<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/f">
    		<webflow:flow-location-pattern value="/**/*-flow.xml" />
    	</webflow:flow-registry>
    
    	<faces:flow-builder-services id="facesFlowBuilderServices" development="true" />
    
    	<bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
    faces-config.xml

    Code:
    <managed-bean>
      <managed-bean-name>search</managed-bean-name>
      <managed-bean-class>com.test.Search</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
     </managed-bean>
     <application>
      <variable-resolver>org.springframework.web.jsf.SpringBeanVariableResolver</variable-resolver>
      <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
      <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
     </application>

    if i define bean in application-context or add this part to application-context
    Code:
    <context:component-scan base-package="com.test" />
    nothing change
    Last edited by ashkan.am528; Jan 22nd, 2009, 07:52 AM.

  • #2
    FacesContext has not been re-constructed yet at that point as on-render actually fires just before the rendering process. Easiest alternative is to pass the SWF MessageContext into your method and use that to add the message (with Spring Faces, any message added to the SWF MessageContext will be available as a FacesMessage).

    So in your flow definition:
    Code:
    <on-render>
        <evaluate expression="search.getAccounts(messageContext)" result="flowScope.accounts"/>
    </on-render>
    and in your Java code:
    Code:
    public List<SelectItem> getAccounts(MessageContext messages) {
    
        try {
               
            ......
        }
        catch (Exception e) {
            messages.addMessage(new MessageBuilder().error().defaultText("error").build());
        }
    }

    Comment


    • #3
      thanks for your response.
      can you tell me the harder way for this question.
      because i use FacesContext for getting component , adding message, getting http request for many process, and so on.

      Comment


      • #4
        no message displayed in style that you said.
        i put externalContext as input parameter of getAccounts method, from request and response i create facesContext object, but message didn't displayed in page.
        how can i pass facesContext as method parameter?

        Comment


        • #5
          alternative is to pass

          at that point as on-render actually fires just before the rendering process. Easiest alternative is to pass the SWF MessageContext into your method and use that to add the message (with Spring Faces, any message added to the SWF MessageContext

          Comment


          • #6
            i send request to service layer of my application in on-renderer and based on result of service i load different ui for client. in this situation i need FacesContext.
            i there another way for solving this problem with web flow and jsf?

            Comment


            • #7
              Originally posted by ashkan.am528 View Post
              i send request to service layer of my application in on-renderer and based on result of service i load different ui for client. in this situation i need FacesContext.
              i there another way for solving this problem with web flow and jsf?
              You can use JSF capability (PhaseListener for instance) to execute code at the specified moment of the JSF lifecycle.

              Comment


              • #8
                can you explain how to use phaselistener?
                if you meen beforPhase and afterPhase ,it has a lot of problem.
                you must change one class of facelet in 1.1.9.
                i need something in web flow, or something like @postConstruct that i can inject spring service to it.

                Comment


                • #9
                  Originally posted by ashkan.am528 View Post
                  can you explain how to use phaselistener?
                  if you meen beforPhase and afterPhase ,it has a lot of problem.
                  you must change one class of facelet in 1.1.9.
                  i need something in web flow, or something like @postConstruct that i can inject spring service to it.
                  We use facelets 1.1.14 and don't have any problem with PhaseListener's. All is needed - is just register them in faces-config.xml. If you need access to the flow context - invoke RequestContextHolder.getRequestContext().

                  Comment

                  Working...
                  X