0
votes

So, I have a datatable like this:

<p:dataTable var="object" value="#{objectBean.objects}"
            paginator="true" rows="10" editable="true" id="tableObjects"

            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5,10,15" style="border: 0px">

            <p:column sortBy="#{object.etc}">
                ..
            </p:column>

            ...

            <p:column sortBy="#{object.someValue}" id="sucessoColumn"
                headerText="Value">
                <p:cellEditor>
                    <f:facet name="output">

                        <h:outputText  value="#{object.someValue}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:selectOneMenu value="#{object.someValue}" effect="fade"
                            id="opt">
                            ...
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>



            <p:column id="bColumn" headerText="Options">

                <p:rowEditor />
            </p:column>
            <p:ajax event="rowEdit" listener="#{objectBean.update}"></p:ajax>

        </p:dataTable>

On a page that receives a parameter like this:

<f:metadata>
        <f:viewParam name="id" value="#{objectBean.object}"
            converter="#{objectConverter}" converterMessage="Converter error !"
            required="true" requiredMessage="Missing object !" />
    </f:metadata>

When the page is loaded, there is no problem at all, and everything works fine. But when I click on next page or try editing the row, then the "required message" from the viewparam appears. It looks like that the param disappears when anything on the datatable changes.

Any ideas ? Thank you.

2

2 Answers

0
votes

The problem was with the scope of the Bean we were using. It seems that, every time that the state of the datatable changes, it makes another request for the bean. If it was request scoped, the parameter was only available for the first request.

Changing to ViewScope solved half of the problem. The datatable worked as it should, but the message still appears. Taking of the "required" and "requiredMessage" attributes solved the last part of the problem and everything worked like a charm.

0
votes

Maybe my answer is too late, but i had same problem like yours.

I will explain my solution from you piece of code.

I dont know why but when your are using lazy loading and cell editor, rowEdit function doesnt work.

<p:ajax event="rowEdit" listener="#{objectBean.update}"></p:ajax>

If you remove you cellEditor from code you will see that objectBean.update method will run.

I remove

<p:ajax event="rowEdit" listener="#{objectBean.update}"></p:ajax>

and in every cell editor i change my code to this one.

<p:column sortBy="#{object.someValue}" id="sucessoColumn" headerText="Value">                      <p:cellEditor>
  <f:facet name="output">
   <h:outputText  value="#{object.someValue}" />
  </f:facet>
  <f:facet name="input">
   <p:selectOneMenu value="#{object.someValue} effect="fade" id="opt">
    <p:ajax event="valueChange" process="@this" listener="#{objectBean.update(object)}"/>
   </p:selectOneMenu>
  </f:facet>
 </p:cellEditor>
</p:column>

In Bean in change update method from first one to second one.

public void update(RowEditEvent event) {
    Object editingRow = (Object) event.getObject();
    objectService().saveOrUpdate(editingRow);
}

public void update(HospitalDoctor obj) {
    objectService().saveOrUpdate(obj);
}

In this way I solved my problem, I hope it will help to others.