0

I am beginner in JSF and Spring integration. I've watched in some youtube videos how to start developing. But my application is very simple and always return null to managed bean. I used inputText and the set method is null. I need a session implementation? What is wrong?

xhtml

  <p:outputLabel id="text1" value="Name:" />
   <p:inputText id="teste" value="#{restAction.teste}" />    
   <p:commandButton value="save" actionListener="#{restAction.save}" />

Managed Bean

@Named
@ManagedBean
@Scope("session")
public class RestAction {

String teste;

public void save(){

    if(teste != null){
        // ----
    }   
}

public String getTeste() {
    return teste;
}

    public void setTeste(String teste) {
        this.teste = teste;


}

Faces Config

<application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>

Web config

    </welcome-file-list>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
</web-app>
art143
  • 1

1 Answers1

0

For JSF, use @SessionScoped instead of @Scope("session") and make sure that <p:inputText>...<p:commandButton> is enclosed within the <h:form> tag. Without it nothing would be send to the server for JSF to process.

Dukefirehawk
  • 476
  • 1
  • 3
  • 11