문제

i am using primefaces to develop the application. I have a p:dataTable with refresh icon created using p:commandLink.Below is records.xhtml sample code:

<f:facet name="header">
    <h:outputText value="SALES Information" />  
    <p:commandLink action="#{showMB.recordList}" update="salesInfo" ajax="true">
        <h:graphicImage library="images" name="show.jpg" title="Show Sales" height="20px;" width="20px;"/>
    </p:commandLink>
</f:facet> 

Below is the method in ManagedBean:

  public List<RecordDTO> getRecordList() {
        boolean flag=true;
        try {
            if(dataList==null){
                //logic here
                flag=false;
            }
            if(dataList!=null){
                //Logic here
            } 
        } catch (Exception e) {

        }
        return dataList;
    }

Now the issue is when i click the p:commandLink button, the control should always go 2nd if condition.

Please suggest. Thanks.

도움이 되었습니까?

해결책

Have a seperate actionListener where you will explicitly make datalist as null.

  public void actionListener(javax.faces.event.ActionEvent event) {  

      datalist=null;  
  }   

And now your commandlink should be

  <p:commandLink action="#{showMB.getRecordList}" 
    actionListener="#{showMB.actionListener}" update="recordsInfo"   
     action="#{showMB.recordList}" ajax="true">  
   <h:graphicImage library="images" name="show.jpg" title="Refresh"/>  
 </p:commandLink>  

ActionListener is executed first before action So you will have datalist set to null before action method execution.

But ideally you have to use actionListener only when the event source component instance is needed in backend raised.

Hope this helps.

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