JSF Ajax Link does partial ajax rendering before link action

The JSF page has the following:

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

rendering works fine even though it displays component before action . (I know this by registering)

Is there a way to show components after executing an action function on a server?

Any help would be greatly appreciated.

Update 1

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

+4
source share
3 answers

You can use listener for f:ajax to execute your logic and pass row.id one of the following ways (remove action="#{manager.removeEntity(row.id)}" )

Pass parameter when calling ajax 1

Pass parameter when calling ajax 1

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

rendering works fine, although it renders the component before the action completes. (I know this by registering)

This is not true. You must misinterpret the log. Perhaps you put the log statement inside the getter method of the table value in misassumption, which it called only during the render response. This is not true. A getter is called as many times as an EL expression referencing a property is evaluated. This can happen in a different phase before and after the action phase is called. Since you have a reference to the command inside the datatable, the getter method of the table method will also be called during the query phase of the query to find the found row associated with the link.

Go to FacesContext#getCurrentPhaseId() along with the log to see which phase the getter method is called on. Also note that doing a business job (such as calling a database, etc.) inside a managed get bean method is a bad idea.

See also:

0
source

Late, but I had the same problem. Ajax is displayed before the completion of my jsf logic. My decision? Well, I added a confirmation dialog. I know this is not a technical solution, but hey, it works. As soon as the user clicks ok in the dialog box (which takes about a second, at this time the logic should be executed), the component should be visualized. Hope this helps.

Before the changes:

 <h:commandButton action="#{bean.buisnessLogic(param1, param2)}"> <f:ajax execute="components" render="table" /> </h:commandButton> 

After the changes:

 <h:commandButton onclick="javascriptCofirm();" action="#{bean.buisnessLogic(param1, param2)}"> <f:ajax execute="components" /> </h:commandButton> <h:commandButton id="button" style="display: none"> <f:ajax render="table" /> </h:commandButton> 

JavaScript:

 function javascriptConfirm() { bootbox.alert("Se agrego la accion con exito.", function () { var boton = document.getElementById("button"); boton.click(); }); e.preventdefault(); return false; } 

What I've done:

So, before the changes were made. My Button command will display a table before adding registers. For example, I would add line 2, and it would not display the changes until the page was refreshed or line 3 was added. I did some research and I came to the conclusion that jsf translates the ajax tag in javascript, and javascript directly executes the code without waiting for the action to complete.

Decision:

So now I remove the render attribute from ajax, and I create another commandButton, and in the new CommandButton I add a render. The javascriptConfirm method calls the button and "clicks" it. This displays the page, but by the time they confirm the logic, it is complete. So yes. This is probably confusing. It’s good that you just don’t comment, and I will try to answer as quickly as possible (maybe not so fast).

0
source

Source: https://habr.com/ru/post/1400802/


All Articles