繁体   English   中英

p:commandButton操作和ajax更新后未调用

[英]p:commandButton action not invoked after and ajax update

我有一个JSF页面,该页面具有ap:commandButton,该页面具有ajax = true并在单击时呈现ap:panel,该ap:panel包装在p:outputPanel中。 单击此按钮后,该操作方法会将ManagedBean中的showCreateUser值设置为true,这将用于呈现Panel。 效果很好-在按钮上单击,面板将正确呈现。 在p:panel内部,还有另一个p:commandButton。 该commanButton不起作用,因为当我单击它时什么也没有发生。 该操作方法永远不会被调用。 当我调试时,我意识到即使ajax操作将showCreateUser设置为true,但是当我单击第二个按钮时,showCreateUser的值为false。 因此,panel panel render = false,因此该操作永远不会被调用。 以下是xhtml和managedbean类。 我该如何解决? 谢谢你的帮助!

registration.xhtml

<h:form id="userForm" style="background-color:white;border:0px; width:90%;">
   <p:messages id="messagesForDebugging"
               showDetail="true"
               autoUpdate="true" />
   <ui:debug hotkey="x"/>
   <div style="margin-bottom: 10px;">
       <p:commandButton id="btnConfirmYes" value="Yes" ajax="true" update="userRegOutPanel" 
               action="#{regBean.confirmYes}" styleClass="button" style="height:35px;">
        <!-- <f:ajax render="userRegOutPanel" execute="userRegOutPanel"/> -->
       </p:commandButton>

       <p:commandButton id="btnConfirmNo" value="No" ajax="false"
             action="#{regBean.confirmNo}" styleClass="button" style="height:35px;"/>
   </div>

   <p:outputPanel id="userRegOutPanel">
        <p:panel id="userRegPanel" rendered="#{regBean.showCreateUser}">
            <p:panelGrid id="userRegPanelGrid">
                <p:row>
                   <p:column style="width:40%;background-color:#00a5b6;-moz-border-radius: 10px;-webkit-border-radius: 10px;-khtml-border-radius: 10px;border-radius: 10px;text-align:left;">

                      <h:inputHidden id="ssn" value="#{regBean.ssn}"/>

                      <p:panelGrid>
                          <p:row>
                              <p:column>
                                  <p:commandButton value="Submit" ajax="true" action="#{regBean.submitRegistration}"                                                 
                                           styleClass="button" style="width:140px;height:35px;" type="submit"/>
                              </p:column>
                          </p:row>
                      </p:panelGrid>
                   </p:column>
                </p:row>
            </p:panelGrid>
        </p:panel>
   </p:outputPanel>
</h:form>

托管豆

    @ManagedBean
        @ViewScoped
        public class RegBean implements Serializable{

    private static final long serialVersionUID = 1L;
    static Logger log = LoggerFactory.getLogger(RegBean.class);

    private String ssn;

    private boolean showCreateUser = false;

    public void confirmYes(){
        setShowCreateUser(true);
    }

    public String confirmNo(){
        log.info("In retrieveRegistration");
        FacesContext fc = FacesContext.getCurrentInstance();
        fc.addMessage("registrationError", new FacesMessage(
                FacesMessage.SEVERITY_ERROR,
                "Error. Contact customer service",
                "Error. Contact customer service"));
        return "/registration/registrationError";
    }

    public String submitRegistration() {  
        log.info("In submitRegistration");
        FacesContext fc = FacesContext.getCurrentInstance();

        return "/secured/home";
    }  

    public String getSsn() {
        return ssn;
    }
    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public boolean isShowCreateUser() {
        return showCreateUser;
    }

    public void setShowCreateUser(boolean showCreateUser) {
        this.showCreateUser = showCreateUser;
    }
}
<p:commandButton id="btnConfirmNo" value="No" ajax="false"
action="#{regBean.ConfirmNo}"
styleClass="button" style="height:35px;"/>

在上面的代码中,您已将操作设置为“ ConfirmNo ”。 我没有这样的方法。

将上面的代码更改为:

<p:commandButton id="btnConfirmNo" value="No" ajax="false"
action="#{regBean.agentConfirmNo}"
styleClass="button" style="height:35px;"/>

现在,它将从您的注册bean调用方法agentConfirmNo

希望对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM