Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF Ajax Link performs partial ajax render before the link action

I have the following in a JSF page:

<h:commandLink action="#{manager.removeEntity(row.id)}" value="Remove">
    <f:ajax event="action" render=":form:table" />
</h:commandLink>

The rendering works perfectly, though it renders the component before the action is performed. (I know this through logging)

Is there any way for me to render the components after the action function is performed on the server?

Any help will be greatly appreciated

Update 1

I removed the action attribute and added a listener to the tag, though unfortunately it doesn't seem to help, the method is still called after the component tree is rendered.

like image 588
Sheldon Irwin Avatar asked Nov 13 '22 08:11

Sheldon Irwin


1 Answers

<h:commandLink action="#{manager.removeEntity(row.id)}" value="Remove">
    <f:ajax event="action" render=":form:table" />
</h:commandLink>

The rendering works perfectly, though it renders the component before the action is performed. (I know this through logging)

This is not true. You must be misinterpreting the logging. Perhaps you have put a log statement inside the getter method of the table's value in a misassumption that it's only called during render response. This is thus not true. The getter is called as many times as an EL expression referencing the property is been evaluated. This can happen in a different phase before and after invoke action phase. As you've the command link inside a datatable, the table's value getter method will also be called during apply request values phase in order to find find the row associated with the link.

Pass FacesContext#getCurrentPhaseId() along with the log to learn during which phase the getter method is been called. Also note that doing business job (like calling database and so on) inside a managed bean getter method is a bad idea.

See also:

  • Why JSF calls getters multiple times
like image 61
BalusC Avatar answered Dec 18 '22 11:12

BalusC