문제

i have build a primefaces extensions wizard like form with steps, using component shown here:

http://fractalsoft.net/primeext-showcase-mojarra/sections/masterDetail/wizardLikeNavigation.jsf

My back bean is View Scoped however when i complete the steps and save the form, on subsequent form loads it does not get refreshed cleared (the values i have selected in the first time i submitted the form are still present) ...

My command button is at the end of my wizard panel code which is the following:

<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 &quot;Next&quot; 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>

And my back bean (create new empty object at the end of the 'save' action, as suggested in primefaces extensions relative example):

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

Any ideas of what i have been missing?

도움이 되었습니까?

해결책 2

The issue is solve by setting my selected variables on the bottom part of Save action like:

...
//create an empty review protocol
ReviewWizard reviewWizard = new ReviewWizard();     
setSelectedImages(null);
setSelectedPatients(null);
setSelectedVariables(null);
setSelectedReviewers(null);
setReviewProtocolDescription(null);
currentLevel=1;
...

다른 팁

Edit:

You are creating the new empty object in the reviewProtocol = new CRReviewProtocol(); that variable is only visible inside the scope of your save(ACtionEvent actionEvent) method.

If you see like in your example from the link you should have something like:

<p:inputText required="true" label="Firstname" value="#wizardMasterDetailController.user.firstname}"/>  

You have to set the user = new User() in order to reset it. In that case the user is a class variable, how is yours called and that is the variable which you have to reset.

Please post more of your panel to help you better.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top