0

i implemented selectableDataModel and extend ListDataModel i can excellently see the content of table.

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

but when i click 'sec' in setSelectedProductToForm function i expect to see manageFormsView.product with a content but it is null.

what may the problem be?

thanks

merveotesi
  • 2,145
  • 15
  • 53
  • 84
  • have you noticed that the update of "sec" is set to update="main_form" while your form does not have an id? – Daniel Jan 13 '12 at 13:27

2 Answers2

1

try this:

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

Apparently you didn't implement SelectableDataModel#getRowData() and/or getRowKey() properly. The most basic implementation would look like this, assuming that you have a Long id representing a PK in your Product class:

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

The getRowKey() is to be used to return the row identifier of the selectable rows. The getRowData() is to be used to return the whole object which is associated with the row identifier.


Unrelated to the concrete problem, please note that the EL as you have there in oncomplete attribute is resolved on a per-view basis, not on a per-request basis. You might want to fix that as well. See also for example EL expression inside p:commandButton onclick does not update/re-render on ajax request?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555