Announcement Announcement Module
Collapse
No announcement yet.
JSF - passing request parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSF - passing request parameters

    I was migrating from plain JSF to Spring JSF support using version 2.5.6.
    I used to pass request params by putting it into the request map, then navigating to the next page and getting the param back from the map. Now with Spring, this does not work anymore.
    This is my idea:

    Code:
    <!-- login.jsf -->
    ...
    <h:inputText value="#{login.email}" />
    <h:commandLink value="Password lost" action="#{login.goToPassword}" />
    ...
    
    
    /* Login.java */
    @Component("login")
    @Scope("request")
    public class Login {
      private String email;
      // + getter and setter
    
      public String goToPassword() {
        FacesContext.getCurrentInstance()
    	.getExternalContext()
    	.getRequestMap()
    	.put("email", this.email);
        return "lostPassword"; // navigating to password.jsf
      }
    }
    
    
    <!-- password.jsf -->
    ...
    <h:outputText value="#{password.email}" />
    ...
    
    
    /* Password.java */
    @Component("password")
    @Scope("request")
    public class Password () {
      private String email;
      // + getter
    
      @PostConstruct
      public void init() {
        this.email = (String)FacesContext.getCurrentInstance()
    	.getExternalContext()
    	.getRequestMap()
    	.get("email");
      }
    }
    In Password.init() the request param can't be retrieved. But why not?
    Is there a more common way to pass parameters with spring?


    Here are my further configuration files:
    Code:
    <!-- faces-config.xml -->
    <application>
      <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
      <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>
    ...
    
    
    <!-- web.xml -->
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    ...
    
    <!-- applicationContext.xml -->
    <context:annotation-config />
    <context:component-scan base-package="com.example.web" />
    ...
Working...
X