p:命令按钮操作后不调用和ajax更新



我有一个JSF页面,它有一个p:commandButton,它有ajax=true,并呈现一个p:panel,它被包装在p:outputPanel点击时。当单击此按钮时,操作方法将ManagedBean中的showCreateUser值设置为true,这用于呈现面板。这工作得很好-点击按钮面板被正确渲染。在p:面板中还有另一个p:commandButton。这个commanButton不工作,因为当我点击它时什么都没有发生。动作方法永远不会被调用。当我调试时,我意识到,即使ajax操作设置showCreateUser为真,但当我点击第二个按钮时,showCreateUser值为假。因此,面板面板呈现=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>

托管Bean

    @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

我希望这对你有帮助。

相关内容

  • 没有找到相关文章

最新更新