1

我在 GAE 上实现 spring mvc + primeFaces 时遇到问题,我认为一切正常,除非我尝试通过发送帖子来修改我的 bean 的值,值保持与以前相同。这是代码:

web.xml

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/main-servlet.xml</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>

     <context-param>
      <param-name>com.sun.faces.enableThreading</param-name>

      <param-value>false</param-value>

        </context-param>



    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>



<servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>



     <listener>
    <listener-class>
      com.remote.control.web.ApiKeyInitializer
    </listener-class>
  </listener>


    <servlet>
        <servlet-name>main</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>main</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  



 <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>



    <security-constraint>
        <web-resource-collection>
            <url-pattern>/home</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>




  <servlet> 
  <servlet-name>SystemServiceServlet</servlet-name>
  <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
  <init-param>
   <param-name>services</param-name>
   <param-value/>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>SystemServiceServlet</servlet-name>
  <url-pattern>/_ah/spi/*</url-pattern>
 </servlet-mapping>
</web-app>

主servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

     <beans>

    <context:component-scan base-package="com.remote.control.controller" />
     <context:component-scan base-package="com.remote.control.service" />

    <mvc:annotation-driven />

    <mvc:resources mapping="/res/**" location="/WEB-INF/res/"  />  



    <bean
        id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver" >

        <property
            name="prefix"
            value="/WEB-INF/jsp/" />

        <property
            name="suffix"
            value=".xhtml" />
    </bean>


</beans>

面孔-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config >

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

    </application>




</faces-config>

家庭控制器.java

@Controller
public class HomeController {

      private Logger logger = Logger.getLogger(getClass().getName());

      @Autowired
      Bean bean;


    @RequestMapping(value="/home", method=RequestMethod.GET)
    public ModelAndView homeGet() {
        ModelAndView mv=new ModelAndView("index");  
        bean.setParam1("111111111");
        bean.setParam2("22222222222");
        bean.setParam3("3333333333");
        mv.addObject("task",bean);      
        return mv;
    }


    @RequestMapping(value="/home", method=RequestMethod.POST)
    public ModelAndView homePost() {
        ModelAndView mv=new ModelAndView("index");

            logger.warning("param1"+ bean.getParam1());
            logger.warning("param2" + bean.getParam2());
            logger.warning("param3" + bean.getParam3());

            mv.addObject("task",bean);

    }


}

Bean.java

@Component
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
public class Bean implements Serializable {


    private String param1;
    private String param2;
    private String param3;
    public String getParam1() {
        return param1;
    }
    public void setParam1(String param1) {
        this.param1 = param1;
    }
    public String getParam2() {
        return param2;
    }
    public void setParam2(String param2) {
        this.param2 = param2;
    }
    public String getParam3() {
        return param3;
    }
    public void setParam3(String param3) {
        this.param3 = param3;
    }



}

索引.xhtml

<html>

<ui:composition template="baseLayout.xhtml">
    <ui:define name="content">

                <form action="home" method="post">
                <h:panelGrid style="margin-top:20px;" columns="2" cellpadding="10">

                    <p:outputPanel autoUpdate="true">

                        <p:inputText value="#{task.param1}" />
                        <p:inputText value="#{task.param2}" />


                        <p:inputTextarea value="#{task.param3}" id="text" rows="10" cols="50" />

                    </p:outputPanel>




                </h:panelGrid>
                <button value="submit" />

            </form>


    </ui:define>
</ui:composition>


</html>
4

1 回答 1

0

只要转

<form action="home" method="post">
    <h:panelGrid style="margin-top:20px;" columns="2" cellpadding="10">
        <p:outputPanel autoUpdate="true">

            <p:inputText value="#{task.param1}" />
            <p:inputText value="#{task.param2}" />

            <p:inputTextarea value="#{task.param3}" id="text" rows="10" cols="50" />

        </p:outputPanel>
    </h:panelGrid>
    <button value="submit" />

</form>

进入

<h:form>
    <h:panelGrid style="margin-top:20px;" columns="2" cellpadding="10">
        <p:outputPanel autoUpdate="true">

            <p:inputText value="#{task.param1}" />
            <p:inputText value="#{task.param2}" />

            <p:inputTextarea value="#{task.param3}" id="text" rows="10" cols="50" />

        </p:outputPanel>
    </h:panelGrid>
    <p:commandButton value="submit" action="#{task.myMethod}"/>

</h:form>

用下面的方法

public void myMethod(){
    System.out.println(param1);
    System.out.println(param2);
    System.out.println(param3);
}
于 2012-12-09T14:52:27.717 回答