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