我有一个打算用来编辑用户信息的 JSF 页面。编辑用户所需的所有组件都包含在同一个页面中,并且我正在使用 render 属性来确定应该呈现哪些组件。呈现第一个面板组,当您输入用户登录名并单击按钮时,一切正常,显示第二个面板组,您可以在文本字段中更改用户信息。问题在于单击手风琴面板第一个选项卡中的按钮,它不起作用。我已经尝试过请求范围和查看范围,并且在使用任何一个时都遇到了同样的问题。
<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} #{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>
值为“Save Changes”的命令按钮是有问题的按钮,因为从未调用过 bean 方法。
@ManagedBean
@ViewScoped
public class AdminManagedBean implements Serializable {
public String saveNameChange(){
log.info("save Name called");
this.editUser = ssb.updateUser(editUser);
return "edituser";
}
单击按钮时未调用方法“saveNameChange”。任何帮助将不胜感激。