0

I start with examples:

Example 1

<p:dataTable>
...
<p:column headerText="Actions" style="text-align:center; width:100px;">
    <p:commandLink value="Delete" action="#{bean.delete}"
        update="data">
        <f:setPropertyActionListener target="#{bean.key}" value="#{item.key}" />            
    </p:commandLink>
</p:column>
...
</p:dataTable>

Example 2

<p:dataTable>
...
<p:column headerText="Actions" style="text-align:center; width:100px;">
    <p:commandLink value="Delete" actionListener="#{bean.delete}"
        update="data">
        <f:setPropertyActionListener target="#{bean.key}" value="#{item.key}" />            
    </p:commandLink>
</p:column>
...
</p:dataTable>

In the first case (command link with action), property bean.key is set correctly but the table is not rendered again after the item is deleted.

In the second case (command link with actionListener), property is not set and I get NullPointerException. But I have another command link with actionListener outside the table and it works fine and updates the table.

How can I make the first case to render the table after the item is deleted or somehow solve the problem?

user219882
  • 15,274
  • 23
  • 93
  • 138

3 Answers3

1

try to add attribute prependId=false to the form tag which wraps component with id="update"

<h:form prependId="false">

advice: add attribute process="@this" to your <p:commandLink value="Delete" ...> in this case you submit just this one component instead of all components in the form

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
corsair
  • 658
  • 5
  • 14
1

Is there a chance that you have two forms? and the p:commandLink is in the first form and the render component (the one with the id="data") is in the second form?.
Then you should assign an id to the second form and your commandLink should be like <p:commandLink... update=":secondformid:data">.
If you are using PrimeFaces 3.0 you can read more in the PrimeFaces User's Guide, chapter 4, section 4.1.2 Partial Rendering and Processing->Using IDs.
http://www.primefaces.org/documentation.html
Sorry about my bad english.

Roteke
  • 663
  • 2
  • 9
  • 12
1

A tip (or trick):
Instead of:

<p:commandLink value="Delete" action="#{bean.delete}" update="data">
    <f:setPropertyActionListener target="#{bean.key}" value="#{item.key}" />            
</p:commandLink>  

You could use:

<p:commandLink value="Delete" action="#{bean.delete}" actionListener="#{bean.setKey(item.key)}" update="data" />  

This way you use the actionListener to explicitly call the setter and set the property.

Roteke
  • 663
  • 2
  • 9
  • 12
  • Can you ensure that the actionListener method is called before the action method? I don't want to end up with NPE. – user219882 Dec 18 '11 at 00:37
  • The actionListener should be executed first. You can read more here: http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener – Roteke Dec 18 '11 at 01:38