具有呈现属性的jsf commandlink和commandbutton不会触发actionlistener

时间:2012-04-02 11:09:03

标签: java jsf scope render actionlistener

我正在使用primefaces在页面上显示一些数据,当点击CLOB类型数据时,我想打开一个弹出窗口(使用primefaces对话框组件)来显示完整数据。问题是,当我将渲染的atrribute放到commandlink时,它不会触发支持bean的方法。如果我不使用渲染的atrribute,它会正确触发方法。但它不能正确传递参数。

支持bean是视图编组的。当我提交时,可能是关于豆的状态丢失了吗?如果是这样,那么要做些什么来克服这个问题?

以下是来源:

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

支持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 "";
}

}

1 个答案:

答案 0 :(得分:1)

如果在表单提交的HTTP POST请求期间变量columIndex的值已更改,则会发生这种情况。如果#{controller.columnNames}依赖于基于请求的条件,那么这又可能发生,该条件仅在使用表格显示页面时才是正确的。您需要确保在视图范围bean的(post)构造函数中预先初始化它,并且该值未在getter方法中初始化/操作。