启动.xhtml
我正在使用 primefaces 向导来显示应用程序的顺序流程。在成员详细信息选项卡之一中,我有一个可编辑的数据表。对于名称列,我希望用户从可用的用户列表中选择名称单击按钮时具有名称,名称,部门
我在单击按钮时在对话框中使用另一个数据表。
但是如何在单击添加按钮后更新原始数据表中的选定值。
<h:body>
<h:form id="compositionmaster">
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard widgetVar="wiz" flowListener="#{userWizard.onFlowProcess}" step="address" >
<p:tab id="address" title="Member Details">
<p:panel header="Member Selection" >
<h:messages errorClass="error"/>
<p:dataTable id="outputtable" var="membertable" value="#{tableBean.compositionRoles}" editable="true" editMode="cell" >
<p:column headerText="Role" >
<h:outputText value="#{membertable.role}" />
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="input">
<p:selectOneMenu value="#{userWizard.user.type}">
<f:selectItem itemLabel="--Select--" itemValue="0" />
<f:selectItem itemLabel="Internal" itemValue="1" />
<f:selectItem itemLabel="External" itemValue="2" />
</p:selectOneMenu>
</f:facet>
<f:facet name="output">
<h:outputText value="#{userWizard.user.type}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column id="namecol" headerText="Name">
<p:commandButton id="basic" value="..." onclick="dlg.show();" type="button" />
<h:outputText value="#{userBean.selectedUser.name}" />
</p:column>
<p:column id="divcol" headerText="Section/Division">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{userBean.selectedUser.division}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{userBean.selectedUser.division}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
<p:dialog id="dialog" header="UserList" widgetVar="dlg" >
<h:form id="userform">
<p:dataTable var="user" value="#{userBean.users}" selection="#{userBean.selectedUser}" rowKey="#{user.name}" >
<p:column selectionMode="single"/>
<p:column headerText="Name">
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Division">
<h:outputText value="#{user.division}" />
</p:column>
<f:facet name="footer">
<p:commandButton update=":compositionmaster:namecol" ajax="true" onclick="dlg.hide()" value="Add" id="addmember"/>
</f:facet>
</p:dataTable>
</h:form>
</p:dialog>
用户向导.java
package committee;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;
import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import org.primefaces.event.FlowEvent;
import java.io.Serializable;
import javax.faces.bean.ViewScoped;
import office.UserBean;
@ManagedBean
@ViewScoped
public class UserWizard implements Serializable{
private User user = new User();
private Committee comm =new Committee();
private boolean skip;
private UserBean userbean;
private static final Logger logger = Logger.getLogger(UserWizard.class.getName());
public UserBean getUserbean() {
return userbean;
}
public void setUserbean(UserBean userbean) {
this.userbean = userbean;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Committee getComm() {
return comm;
}
public void setComm(Committee comm) {
this.comm = comm;
}
public void save(ActionEvent actionEvent) {
//Persist user
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public boolean isSkip() {
return skip;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
public String onFlowProcess(FlowEvent event) {
System.out.println(event.getOldStep());
System.out.println(event.getNewStep());
System.out.println(skip);
logger.log(Level.INFO, "Current wizard step:{0}", event.getOldStep());
logger.log(Level.INFO, "Next step:{0}", event.getNewStep());
return event.getNewStep();
}
} UserBean.java
package office;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import committee.User;
import committee.UserDataModel;
import java.util.List;
import java.util.ArrayList;
@ManagedBean
@ViewScoped
public class UserBean implements Serializable{
private List<User> users;
public UserBean() {
users = new ArrayList<User>();
users.add(new User("Kanika","Development"));
users.add(new User("Shreya","Development"));
users.add(new User("Tushti","Development"));
users.add(new User("abc","Marketing"));
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
private User selectedUser;
private UserDataModel userDataModel;
public UserDataModel getUserDataModel() {
return userDataModel;
}
public void setUserDataModel(UserDataModel userDataModel) {
this.userDataModel = userDataModel;
}
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
this.selectedUser = selectedUser;
}
}