1

I am working with jsf 2.0 and primefaces. With a command button i navigate to another page that displays a data table of crypted items. My problem is that each row in that data table is displayed twice although i am using preRenderView event in the command button one of BalusC solutions Why JSF calls getter many times

My XHTML code

<p:commandButton id="Later" style="width: 20%;height: 100%" value="Later" oncomplete="window.location.href = '/Hitonclick/data.xhtml'"  >
   <f:event type="preRenderView" listener="#{MB.preRender}"/>
</p:commandButton>
<p:dataTable id="datasTable" value="#{MB.dataList}"  var="item" rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                             paginator="true" rows="10" styleClass="case-table"  emptyMessage="No records found with given criteria" paginatorPosition="bottom" 
                             selectionMode="single" rowKey="#{item}" filteredValue="#{MB.filteredDatas}"  
                             selection="#{MB.selectedData}"  >
   <p:ajax event="rowSelect" />

   <p:column styleClass="blockable" filterStyle="width: 250px"  filterBy="#{item} " sortBy="#{item}">
      <h:outputText value="#{item}"/>
   </p:column>
</p:dataTable>

Part of my sessionScoped managedBean

 @PostConstruct
 public void init() {
        mailList=new ArrayList<>();
 }
 public void preRender(ComponentSystemEvent event) {
        // Or in some SystemEvent method (e.g. <f:event type="preRenderView">).
           dataList=this.protectDatas();
 } 
 public ArrayList<String> getDataList() {
        return dataList;
 }
 public void setDataList(ArrayList<String> dataList) {
        this.dataList = dataList;
 } 

protectData() method

public ArrayList<String> protectDatas(){
      for (int k = 0; k < datass.size(); k++) {
        String originalText;
        originalText = (String) datass.get(k).toString();

        String subStringToFind = "@";
        int x = originalText.indexOf(subStringToFind);

        String s1 = originalText.substring(x + 1);
        String f = originalText.replace(s1, "*******.***");

        getDataList().add(f);
       }
   return dataList;   
}
Community
  • 1
  • 1
junior developper
  • 448
  • 2
  • 19
  • 40
  • Given the way how you have set up the question, are you implying that the code behind `this.protectDatas()` isn't actually the one returning duplicate rows? – BalusC Dec 10 '13 at 14:45
  • @BalusC is this.protectDatas() causing the problem?? – junior developper Dec 11 '13 at 07:36
  • Are you sure `protectDatas` is returning non-duplicates? You could instead return a `Set` instead of `ArrayList` to avoid that. – Aritz Dec 11 '13 at 12:19

1 Answers1

-1

You cannot iterate a set over primefaces datatable. Refer here

You can try removing duplicate items and still have a list as below.

yourList.clear();
yourList.addAll(new HashSet<>(yourList));
Community
  • 1
  • 1
  • any reasons behind downvoting. please prove me with facts. – Wolverine Dec 12 '13 at 09:17
  • You're not answering the question. OP isn't using a `Set` anywhere and you haven't pointed out the actual mistake causing duplicate rows. – BalusC Dec 12 '13 at 10:44