私はprimefaces 3.2を使用しています。データテーブルの同じページにユーザー情報を挿入するウィザードを用意しました。ウィザードはタブごとに情報を取得し、確認タブで送信します。また、データテーブルの同じページに反映されます。正常に動作しています。次に、複数のユーザーを更新する必要があります。そのためには、送信ボタンから最初のタブまでウィザードをナビゲートする必要があります。どんな助けでも大歓迎です。私のコードは以下の通りです
ウィザード.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Wizard Example</title>
<script type="text/javascript" >
function resetWizard() {
wiz.loadStep(wiz.cfg.steps[0], true);
}
</script>
</h:head>
<h:body>
<h:form id="form">
<!-- <p:growl id="growl" sticky="true" showDetail="true"/> -->
<p:growl redisplay="false" life="3000" id="mymessage" autoUpdate="true"/>
<p:wizard widgetVar="wiz"
flowListener="#{userWizard.onFlowProcess}" showNavBar="true" >
<p:tab id="personal" title="Personal" >
<p:panel header="Personal Details">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
<h:outputText value="Firstname: *" />
<p:inputText required="true" label="Firstname"
value="#{userWizard.user.firstname}" />
<h:outputText value="Lastname: *" />
<p:inputText required="true" label="Lastname"
value="#{userWizard.user.lastname}" />
<h:outputText value="Age: " />
<p:inputText value="#{userWizard.user.age}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="address" title="Address" >
<p:panel header="Adress Details">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Street: " />
<p:inputText value="#{userWizard.user.street}" />
<h:outputText value="Postal Code: " />
<p:inputText value="#{userWizard.user.postalCode}" />
<h:outputText value="City: " />
<p:inputText value="#{userWizard.user.city}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="contact" title="Contact" >
<p:panel header="Contact Information">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Email: *" />
<p:inputText required="true" label="Email"
value="#{userWizard.user.email}" />
<h:outputText value="Phone: " />
<p:inputText value="#{userWizard.user.phone}"/>
<h:outputText value="Additional Info: " />
<p:inputText value="#{userWizard.user.info}"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation" >
<p:panel header="Confirmation">
<h:panelGrid id="confirmation" columns="6">
<h:outputText value="Firstname: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.firstname}" />
<h:outputText value="Lastname: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.lastname}"/>
<h:outputText value="Age: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.age}" />
<h:outputText value="Street: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.street}" />
<h:outputText value="Postal Code: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.postalCode}" />
<h:outputText value="City: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.city}" />
<h:outputText value="Email: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.email}" />
<h:outputText value="Phone " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.phone}"/>
<h:outputText value="Info: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.info}" />
</h:panelGrid>
<p:commandButton immediate="true" value="Submit" update="wiz"
actionListener="#{userWizard.save}" ajax="false"/>
</p:panel>
</p:tab>
</p:wizard>
<p:dataTable var="user" value="#{userWizard.userAll}" id="userList" editable="true" rowKey="#{user.firstname}" paginator="true"
rows="4" rowsPerPageTemplate="4,6" >
<p:column headerText="FirstName" style="width:125px" filterBy="#{user.firstname}" sortBy="#{user.firstname}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.firstname}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{user.firstname}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LastName" style="width:125px" filterBy="#{user.lastname}" sortBy="#{user.lastname}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.lastname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.lastname}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Age" style="width:125px" filterBy="#{user.age}" sortBy="#{user.age}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.age}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.age}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:ajax event="rowEdit" listener="#{userWizard.editRowListner}" update=":form:mymessage"/>
</p:dataTable>
</h:form>
</h:body>
UserWizard.java
package com.test;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.faces.bean.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.event.FlowEvent;
import org.primefaces.event.RowEditEvent;
@ManagedBean
@SessionScoped
public class UserWizard {
private User user = new User();
private boolean skip;
private List<User> userAll = new ArrayList<User>();
private static Logger logger = Logger.getLogger(UserWizard.class.getName());
/*public UserWizard() {
userAll = new ArrayList<User>();
}*/
public List<User> getUserAll() {
return userAll;
}
public void setUserAll(List<User> userAll) {
this.userAll = userAll;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void save(ActionEvent actionEvent) {
//Persist user
System.out.println("First name : " + user.getFirstname());
System.out.println("Last name : " + user.getLastname());
System.out.println("Age name : " + user.getAge());
userAll.add(user);
user = new User();
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public boolean isSkip() {
return skip;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
public String onFlowProcess(FlowEvent event) {
logger.info("Current wizard step:" + event.getOldStep());
logger.info("Next step:" + event.getNewStep());
System.out.println("First name : " + user.getFirstname());
System.out.println("Last name : " + user.getLastname());
System.out.println("Age name : " + user.getAge());
if (skip) {
skip = false; //reset in case user goes back
return "confirm";
} else {
return event.getNewStep();
}
}
public void editRowListner(RowEditEvent rowEditEvent) {
try {
User updatedUser = (User) rowEditEvent.getObject();
System.out.println("User First Name: " + updatedUser.getFirstname());
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Update called", "updated by user"));
} catch (Exception ex) {
ex.getMessage();
}
}
}
ユーザー.java
public class User {
private String firstname;
private String lastname;
private Integer age;
private String street;
private String city;
private String postalCode;
private String info;
private String email;
private String phone;
public User(String firstname, String lastname, Integer age, String street, String city, String postalCode, String info, String email, String phone) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.street = street;
this.city = city;
this.postalCode = postalCode;
this.info = info;
this.email = email;
this.phone = phone;
}
public User() {
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}