Reputation: 2204
I am using primefaces to display some data on the page and when clicked on CLOB type data I want to open a popup(using primefaces dialog component) to display full data. The thing is when I put rendered atrribute to commandlink it won't fire the method at backing bean. It fires the method correctly if I don't use rendered atrribute. But it wont pass parameters correctly.
The backing bean is viewscoped. Could be about the bean's state is lost when I submit? If so, what is to be done to overcome this ?
Here is the source:
<p:dataTable id="dynamicDBReaderResultTable"
widgetVar="wv_dynamicDBReaderResult" paginator="true" page="1"
rows="10" value="#{controller.data}" var="record"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,25,50,100"
emptyMessage="#{dtsmsgm['NoRecords']}"
errorMessage="Error viewing data" rowIndexVar="rownumber" lazy="false"
dynamic="true">
<p:column>
<h:outputText value="#{rownumber+1}"
style="font-weight:bold; font-size:1.05em" />
</p:column>
<p:columns value="#{controller.columnNames}" var="columnName"
columnIndexVar="columnIndex">
<f:facet name="header">
<h:outputText value="#{columnName}" />
</f:facet>
<h:outputText value="#{record[columnIndex].toDisplayString()}" />
<p:commandLink id="showDataButton" value="..."
actionListener="#{controller.prepareLargeData(rownumber,columnIndex)}"
rendered="#{record[columnIndex].dataType eq '2005'}" //if this attribute is removed, it fires the action, but with both parameters as zero
onsuccess="dlg.show()">
</p:commandLink>
</p:columns>
</p:dataTable>
<p:dialog id="largeDataDialog" header="Large Data Content"
widgetVar="dlg" closeOnEscape="true" minHeight="150">
<h:outputText id="largeData" value="#{controller.largeData}" />
</p:dialog>
Backing Bean:
@ManagedBean(name = "dynamicDBReader")
@ViewScoped
public class DynamicDBReader extends AEntityBean<AEntity> {
private List<String> columnNames;
private List<DBData[]> tabularData;
private boolean showTable;
private DBData largeData;
public void prepareLargeData(int rowNumber, int columnIndex) {
largeData = tabularData.get(rowNumber)[columnIndex];
}
@Override
public void init() {
reInit();
}
private void reInit() {
columnNames = new ArrayList<String>();
tabularData = new ArrayList<DBData[]>();
selectedRelease = getLastRelease();
setShowTable(false);
}
public List<DBData[]> getData() {
return tabularData;
}
public List<String> getColumnNames() {
return columnNames;
}
/**
* @param showTable
* the showTable to set
*/
public void setShowTable(boolean showTable) {
this.showTable = showTable;
}
/**
* @return the showTable
*/
public boolean isShowTable() {
return showTable;
}
/**
* @param largeData
* the largeData to set
*/
public void setLargeData(DBData largeData) {
this.largeData = largeData;
}
/**
* @return the largeData
* @throws SQLException
* @throws IOException
*/
public String getLargeData() {
if (largeData == null) {
return "";
}
try {
return largeData.toFullString();
} catch (IOException ioe) {
String errorMessage = "Failed reading data";
LogUtil.error(logger, errorMessage, ioe);
} catch (SQLException sqle) {
String errorMessage = "Failed reading data";
LogUtil.error(logger, errorMessage, sqle);
}
return "";
}
}
Upvotes: 1
Views: 2807
Reputation: 1108742
That can happen if the value of the variable columIndex
has changed during the HTTP POST request of the form submit. That can in turn happen if the #{controller.columnNames}
is dependent on a request based condition which was only correct during displaying the page with the table. You need to make sure that you preinitialize it in the (post)constructor of a view scoped bean and that the value is not initialized/manipulated in the getter method.
Upvotes: 1