我已经使用此处显示的组件构建了一个 primefaces 扩展向导,例如带有步骤的表单:
http://fractalsoft.net/primeext-showcase-mojarra/sections/masterDetail/wizardLikeNavigation.jsf
我的后台 bean 是 View Scoped 但是当我完成这些步骤并保存表单时,在后续表单加载时它不会被刷新清除(我在第一次提交表单时选择的值仍然存在)......
我的命令按钮位于我的向导面板代码的末尾,如下所示:
<h:form id="WizardForm">
<pe:masterDetail id="masterDetail" level="#{reviewWizard.currentLevel}" showBreadcrumb="false" style="margin-top:20px">
<f:facet name="header">
...
</f:facet>
<pe:masterDetailLevel level="1">
<p:dataTable id="patients" var="patient"
value="#{reviewWizard.cRImageDataListPatients}"
selection="#{reviewWizard.selectedPatients}" rowKey="#{patient}"
paginator="true" rows="10" paginatorAlwaysVisible="false"
emptyMessage="No records found" >
<p:ajax event="rowToggle" listener="#{reviewWizard.onRowToggle}"
update=":WizardForm:patients:selectedPatientImages" />
<f:facet name="header">
Select one or many images using the checkboxes and press "Next" button to proceed.
</f:facet>
<p:column selectionMode="multiple" style="width:18px" styleClass="mandara"/>
<p:column style="width:18px">
<p:rowToggler />
</p:column>
<p:column headerText="Patient ID">
#{patient}
</p:column>
<p:rowExpansion>
<p:dataTable id="selectedPatientImages" var="cRImageData"
value="#{reviewWizard.getSelectedPatientImages()}"
rowKey="#{cRImageData.imId}" emptyMessage="No records found"
style="padding:10px 40px;">
<p:column headerText="Image Name">
#{cRImageData.imName}
</p:column>
<p:column headerText="Image Type">
#{cRImageData.imType}
</p:column>
...
</p:dataTable>
</p:rowExpansion>
...
</p:dataTable>
<p:commandButton value="Next" process="masterDetail" style="margin-top: 10px;" icon="ui-icon-arrowthick-1-e">
<pe:selectDetailLevel step="1"/>
</p:commandButton>
</pe:masterDetailLevel>
<pe:masterDetailLevel level="2">
...
</pe:masterDetailLevel>
<pe:masterDetailLevel level="3">
...
</pe:masterDetailLevel>
<pe:masterDetailLevel level="4">
...
</pe:masterDetailLevel>
<pe:masterDetailLevel level="5">
<p:panel header="Confirmation">
<p:panel style="border:none;">
<h:outputText value="Selected Patients: " style="font-weight:700;"/>
<h:outputText value="#{reviewWizard.getSelectedPatiensString()}" />
</p:panel>
<p:panel style="border:none;">
<h:outputText value="Selected Features: " style="clear:left;font-weight:700;"/>
<h:outputText value="#{reviewWizard.getSelectedFeaturesString()}" />
</p:panel>
<p:panel style="border:none;">
<h:outputText value="Selected Reviewers: " style="clear:left;font-weight:700;"/>
<h:outputText value="#{reviewWizard.getSelectedReviewersString()}" />
</p:panel>
<p:panel style="border:none;">
<h:outputText value="Protocol Description: " style="clear:left;font-weight:700;"/>
<h:outputText value="#{reviewWizard.getReviewProtocolDesc()}" />
</p:panel>
<p:commandButton value="Back" style="margin-top: 10px;" icon="ui-icon-arrowthick-1-w"
process="@this" immediate="true">
<pe:selectDetailLevel step="-1"/>
</p:commandButton>
<p:commandButton value="Submit" process="masterDetail"
actionListener="#{reviewWizard.save}"
style="margin-top: 10px;" icon="ui-icon-disk">
<pe:selectDetailLevel level="1" resetInputs="@all"/>
</p:commandButton>
</p:panel>
</pe:masterDetailLevel>
</pe:masterDetail>
</h:form>
还有我的后备豆(在“保存”操作结束时创建新的空对象,如 primefaces extensions 相关示例中所建议的那样):
ManagedBean(name = "reviewWizard")
@ViewScoped
public class ReviewWizard implements Serializable {
private static final long serialVersionUID = -7410916604435445849L;
private List<String> cRImageDataListPatients;
private List<CRImageData> cRImageDataListPatientImages;
private CRImageData[] selectedImages;
private String[] selectedPatients;
private List<CRVariable> availableCRVariables;
private CRVariable[] selectedVariables;
private CRReviewProtocol reviewProtocol;
private String reviewProtocolDescription;
private List<User> availableReviewers;
private User[] selectedReviewers;
private List<CRReviewerData> availableReviewersInternal;
private CRReviewerData[] selectedReviewerInternal;
private CRTask[] cRTask;
private int currentLevel = 1;
// Logger
private static Logger logger = Logger.getLogger(ReviewWizard.class.getName());
private static final String SUCCESS = "success";
private static final String ERROR = "error";
//on report form load do
@SuppressWarnings("unchecked")
@PostConstruct
public void init(){
//call SOAP service to UPM to fetch patients
CallWebService callWebService = new CallWebService();
cRImageDataListPatients = callWebService.call("PatientIds");
availableCRVariables = getCRVariables();
// Set selectedImages to avoid null pointer exceptions
selectedImages = new CRImageData[0];
selectedPatients = new String[0];
selectedVariables = new CRVariable[0];
try {
availableReviewers = getReviewers();
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
selectedReviewers = new User[0];
reviewProtocolDescription = new String() ;
setSelectedReviewerInternal(new CRReviewerData[0]);
}
//on save report form do
public void save(ActionEvent actionEvent) {
String result = null;
List<CRVariable> mySelectedVariables = Arrays.asList(selectedVariables);
List<String> mySelectedPatients = Arrays.asList(selectedPatients);
List<User> mySelectedReviewers = Arrays.asList(selectedReviewers);
List<CRReviewerData> mySelectedReviewersInternal = transformLusers(mySelectedReviewers);
Date now = new Date();
Session session = HibernateUtil.getSessionFactory().openSession();
CRReviewProtocol reviewProtocol = new CRReviewProtocol();
reviewProtocol.setRevProtDescription(this.getReviewProtocolDescription());
reviewProtocol.setCrimagedata(mySelectedPatients);
reviewProtocol.setCrvariables(mySelectedVariables);
reviewProtocol.setcRReviewerData(mySelectedReviewersInternal);
Transaction tx = null;
try
{
tx = session.beginTransaction();
session.save(reviewProtocol);
tx.commit();
logger.debug("New Record :" + reviewProtocol + ", wasCommitted : " + tx.wasCommitted());
result = SUCCESS;
}
catch (Exception e)
{
if (tx != null)
{
tx.rollback();
result = ERROR;
e.printStackTrace();
}
}
finally
{
//session.close();
}
infoMsg("Successful", "The Review Protocol has been succesfully created!");
for(int j=0;j<mySelectedPatients.size();j++){
System.out.println(">>>> For patient " + j + " with id " + mySelectedPatients.get(j));
List<CRImageData> patientImages = getPatientImages(mySelectedPatients.get(j));
for (int k=0;k<patientImages.size();k++){
System.out.println(">>> For image with id " + patientImages.get(k).getImId());
for(int i=0;i<mySelectedReviewersInternal.size();i++){
System.out.println(">>>> For reviewer with id: " + mySelectedReviewersInternal.get(i).getUserEmail());
CRTask cRTask = new CRTask();
cRTask.setcRReviewProtocol(reviewProtocol);
cRTask.setStatus("Open");
cRTask.setDescription("Default description");
cRTask.setCreationDate(now);
cRTask.setReviewerId(mySelectedReviewersInternal.get(i).getUserId());
cRTask.setPatientId(mySelectedPatients.get(j));
cRTask.setImageId(patientImages.get(k).getImId());
System.out.println(">>>>> task object created");
try
{
tx = session.beginTransaction();
session.save(cRTask);
tx.commit();
logger.debug("New Record :" + cRTask + ", wasCommitted : " + tx.wasCommitted());
result = SUCCESS;
}
catch (Exception e)
{
if (tx != null)
{
tx.rollback();
result = ERROR;
e.printStackTrace();
}
}
}
}
}
//}
//finally
//{
session.close();
//}
//create an empty review protocol
CRImageData[] selectedImages = new CRImageData[0];
String[] selectedPatients = new String[0];
CRReviewProtocol reviewProtocol1 = new CRReviewProtocol();
ReviewWizard reviewWizard = new ReviewWizard();
currentLevel=1;
}
public ReviewWizard(){
}
//method to transform user object to crreviewerdata
public List<CRReviewerData> transformLusers(List<User> selectedReviewers){
List<CRReviewerData> selectedReviewersInternal = new ArrayList<CRReviewerData>();
for(int i=0;i<selectedReviewers.size();i++){
CRReviewerData selectedReviewerInternal = new CRReviewerData();
selectedReviewerInternal.setUserId(selectedReviewers.get(i).getUserId());
selectedReviewerInternal.setUserFname(selectedReviewers.get(i).getFirstName());
selectedReviewerInternal.setUserLname(selectedReviewers.get(i).getLastName());
selectedReviewerInternal.setUserEmail(selectedReviewers.get(i).getEmailAddress());
selectedReviewersInternal.add(selectedReviewerInternal);
}
return selectedReviewersInternal;
}
关于我所缺少的任何想法?