Form内只包含一个<h:outputText>显示一条信息,两个<h:commandButton分别表示Yes or No的选择按钮,按钮的action属性都设置成Bean里面的方法,第一次点击按钮的时候页面提交了,但是Bean的方法没有执行,又返回原来的页面了,第二次再点击的时候才执行了Bean方法,请问这是这么回事?为什么要点击两次才起作用?

解决方案 »

  1.   

    <f:view>     
          <h:form id="confirmForm">

    <t:div styleClass="centerAlign">      
              <t:panelGrid columns="1" styleClass="loginForm">
                <h:outputText value="Are you sure?" />
                <t:panelGrid columns="2">
                  <h:commandButton action="#{sessionBean.logout}" value="Yes" />
                  <h:commandButton action="cancel" value="No" />  
                </t:panelGrid>  
              </t:panelGrid>
            </t:div>
          
          </h:form>
        </f:view>
      

  2.   

    public SessionBean {
        public String logout() {
            isLogin = false;
            return "login";
        }
    }
      

  3.   

    这很正常,在web.xml里设置
      <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>//设置为客户端,默认为服务器端
      </context-param>
    就可以了.