0

開始.xhtml

アプリケーションのシーケンシャル フローを表示するために、primefaces ウィザードを使用しています。メンバーの詳細というタブの 1 つに、編集可能なデータ テーブルがあります。ボタンをクリックすると、名前、指定、部門が表示されます

ボタンをクリックすると、ダイアログボックスで別のデータテーブルを使用しています。

しかし、追加ボタンをクリックした後、元のデータテーブルで選択した値を更新するにはどうすればよいですか。

      <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> 

UserWizard.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;
}

}

4

0 に答える 0