【问题标题】:p:dataTable row selection is not working(with a radio button column)p:dataTable 行选择不起作用(带有单选按钮列)
【发布时间】:2012-01-13 11:27:37
【问题描述】:

我实现了 selectableDataModel 并扩展了 ListDataModel 我可以很好地看到表格的内容。

<h:form>
    <p:dataTable id="selectProductTable" var="product"  value="#{manageFormsView.productModel}" selection="#{manageFormsView.product}" >
    <p:column selectionMode="single"/>

<p:column>
                                <f:facet name="header">
                                    <h:outputText value="Urun Ismi" />
                                </f:facet>
                                <h:outputText value="#{product.name}" />
                            </p:column> 


            </p:dataTable>
            <h:panelGrid columns="2">

                <p:commandButton action="#{manageFormsView.setSelectedProductToForm}"
                    update="main_form"
                    oncomplete="if(#{manageFormsView.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"
                    value="sec">
                </p:commandButton>

                <p:commandButton onclick="selectProductDlg.hide();" action="#{manageFormsView.cancelSetRequest}"
                    value="Iptal">
                </p:commandButton>
            </h:panelGrid> 


     </h:form>

但是当我在setSelectedProductToForm 函数中单击“sec”时,我希望看到manageFormsView.product 的内容,但它为空。

可能是什么问题?

谢谢

【问题讨论】:

  • 你有没有注意到“sec”的更新设置为update="main_form",而你的表单没有id?

标签: jsf primefaces


【解决方案1】:

显然您没有正确实现SelectableDataModel#getRowData() 和/或getRowKey()。最基本的实现看起来像这样,假设你有一个 Long id 代表你的 Product 类中的一个 PK:

@Override
public Object getRowKey(Product product) {
    return product.getId();
}

@Override
public Product getRowData(String rowKey) {
    Long id = Long.valueOf(rowKey);

    for (Product product : (List<Product>) getWrappedData()) {
        if (product.getId().equals(id)) {
            return product;
        }
    }

    return null;
}

getRowKey() 用于返回可选行的行标识符。 getRowData() 用于返回与行标识符关联的整个对象。


与具体问题无关,请注意,oncomplete 属性中的 EL 是基于每个视图解决的,而不是基于每个请求的。你可能也想解决这个问题。参见例如EL expression inside p:commandButton onclick does not update/re-render on ajax request?

【讨论】:

    【解决方案2】:

    试试这个:

         <h:commandButton action="#{manageFormsView.setSelectedProductToForm}"
                    oncomplete="if(#{manageFormsView.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"
                    value="sec">
                   <f:ajax event="click" render="@form" />
         </h:commandButton>
    

    【讨论】:

      猜你喜欢
      • 2015-02-14
      • 2014-01-31
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多