简体   繁体   English

在jsf中单击第一个按钮后,在第二个,第三个h:commandbutton上未调用操作方法

[英]Action method not being called on second, third h:commandbutton after first button is clicked in jsf

I have a JSF page that I intend on using to edit a user's information. 我有一个打算用于编辑用户信息的JSF页面。 All of the components needed for editing the user are included in the same pag an dI'm using the render attribute to determine which components should be rendered. 使用render属性确定应渲染哪些组件,将编辑用户所需的所有组件都包含在同一页面中。 The first panel group is rendered and when you enter the users login name and click the button everything works just fine and the second panel group is displayed and you can change the users information in the text fields. 呈现第一个面板组,当您输入用户登录名并单击按钮时,一切正常,第二个面板组显示,您可以在文本字段中更改用户信息。 The problem comes in with the clicking the button in the first tab of the accordian panel, it doesn't work. 问题来自于单击Accordian面板的第一个选项卡中的按钮,此按钮不起作用。 I've tried request scope and view scope and have the same problem when using either one. 我试过了请求范围和视图范围,使用任何一个时都遇到相同的问题。

    <f:view contentType="text/html">
    <h:head>
        <f:facet name="first">
            <meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
            <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
            <title></title>
        </f:facet> 
    </h:head>
    <h:body styleClass="pageDefaultBGC">
            <p:layout fullPage="true">
                <f:facet name="last">
                    <h:outputStylesheet library="css" name="discovery.css"></h:outputStylesheet>
                </f:facet>
                <p:layoutUnit styleClass="headerDiv" position="north" size="100">
                    <h:graphicImage library="images" name="header.jpg"></h:graphicImage>
                </p:layoutUnit>
                <p:layoutUnit styleClass="navDiv" position="west" size="200">
                    <h:outputText value="Navigation Menu"></h:outputText>
                    <br/>
                    <hr/>
                    <h:outputLink styleClass="navLink" value="index.xhtml">Admin Home</h:outputLink>
                    <br/>
                    <h:outputLink styleClass="navLink" value="addNewUser.xhtml">Add New User</h:outputLink>
                    <br/>
                    <h:outputLink styleClass="navLink" value="edituser.xhtml">Edit User</h:outputLink>
                    <br/>                    
                </p:layoutUnit>
                <p:layoutUnit position="center" id="main">
                    <h:form id="editForm">
                        <h:panelGroup rendered="#{!adminManagedBean.editingUser}">
                            <h2>Edit User Account</h2>
                            <h:outputLabel for="useredit" value="Enter User's Name:"></h:outputLabel>
                            <h:inputText id="useredit" value="#{adminManagedBean.editUserLogin}" required="true"></h:inputText>
                            <br/><br/>                  
      THIS BUTTON WORKS!---><h:commandButton value="Submit" action="#{adminManagedBean.startUserEdit()}"></h:commandButton>
                        </h:panelGroup>
                        <h:panelGroup rendered="#{adminManagedBean.editingUser}">
                            <h:outputText value="Editing User:"></h:outputText>
                            <p:dataTable value="#{adminManagedBean.editUser}" var="u">
                                <p:column styleClass="dataTableHeader" headerText="Full Name">#{u.firstName}&nbsp;#{u.lastName}</p:column>
                                <p:column styleClass="dataTableHeader" headerText="Username">#{u.login}</p:column>
                                <p:column styleClass="dataTableHeader" headerText="Phone">#{u.phone}</p:column>
                                <p:column styleClass="dataTableHeader" headerText="Email">#{u.email}</p:column>
                                <p:column styleClass="dataTableHeader" headerText="Agency ID">#{u.agencyId}</p:column>
                            </p:dataTable>
                            <br/>
                            <h:outputText value="User's Current Roles"></h:outputText>
                            <ul>
                                <ui:repeat value="#{adminManagedBean.editUsersRoles}" var="cr">
                                    <li><h:outputText value="#{cr}"></h:outputText></li>
                                </ui:repeat>
                            </ul>
                            <br/>
                            <h:outputText value="Select an item to edit using the menu below"></h:outputText>
                            <br/>
                            <p:accordionPanel>
                                    <p:tab title="Edit User's Name" titleStyleClass="accordianTitleStyle">
                                            <h:panelGrid styleClass="panelGridStyle1" columns="2" cellpadding="10">
                                                <h:outputText value="First Name:"></h:outputText>
                                                <h:inputText value="#{adminManagedBean.editUser.firstName}"></h:inputText>
                                                <h:outputText value="Last Name:"></h:outputText>
                                                <h:inputText value="#{adminManagedBean.editUser.lastName}"></h:inputText>
                  THIS BUTTON DOESN'T WORK----><h:commandButton value="Save Changes" action="#{adminManagedBean.saveNameChange()}"></h:commandButton>
                                                <h:commandButton value="Cancel Changes"></h:commandButton>    
                                            </h:panelGrid>
                                    </p:tab>

The command button with the value "Save Changes" is the button in question since the bean method is never called. 由于从未调用bean方法,因此具有“保存更改”值的命令按钮是有问题的按钮。

@ManagedBean
@ViewScoped
public class AdminManagedBean implements Serializable {
public String saveNameChange(){
    log.info("save Name called");
    this.editUser = ssb.updateUser(editUser);
    return "edituser";
}

The method "saveNameChange" is not being called when the button is clicked. 单击按钮时未调用方法“ saveNameChange”。 Any help wouldbe greatly appreciated. 任何帮助将不胜感激。

In the process of editing the page and bean for posting on SO the problem was discovered and it had nothing to do with the JSF components. 在编辑页面和bean以便在SO上发布的过程中,发现了问题,并且与JSF组件无关。 The problem was two fold, 问题是两个方面,

1) A developer had changed the size of a field in a table in the db but not in the entity class associated with that table which was causing validation to throw an error message. 1)开发人员已更改db中表中字段的大小,但未更改与该表相关联的实体类中的字段大小,这导致验证抛出错误消息。 2) The styling being used was preventing the error message from the validation from being displayed. 2)使用的样式阻止了错误消息从验证中显示出来。

Solution: I updated the entity class, corrected the styling and the buttons are now working properly. 解决方案:我更新了实体类,更正了样式,按钮现在可以正常工作。

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

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