Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically ajax-update specific component in backing bean

Is there a way to ajax-update a specific component such as a <h:form> in backing bean?

I tried the following using RequestContext#execute(),

RequestContext context = RequestContext.getCurrentInstance();
context.execute("monitorVehicleForm.update()");

however that didn't seem to have any effect.

like image 998
Venkat Maridu Avatar asked Apr 19 '13 09:04

Venkat Maridu


People also ask

How to update the component from the backing bean?

In order to updte the component from backing bean, we can achieve as below RequestContext.getCurrentInstance ().update ('updatePanelGroup'); Updating the component differs with respect to prima face version.

Can I refresh JSF component from backing Bean by Ajax?

2. Re: refresh jsf component from backing bean Hi. Yes. I want to re-render them by AJAX. I have h:panelGrid with 2 components inside - h:outputText and p:rating (primefaces rating component).

Is it possible to dynamically update components in a component?

Actually the component has a property for dynamically update of components. Unfortunately in the version I was using before there was a bug and these components were not updated. That is why I wanted to do some workaround.

Is it possible to execute JavaScript from the backbean using requestcontext?

The RequestContext is deprecated from Primefaces 6.2. From this version use the following: And to execute javascript from the backbean use this way: Show activity on this post. What I got to do is like having people that I iterate into a ui:repeat and display names and other fields in inputs.


1 Answers

The RequestContext#execute() only executes arbitrary JavaScript code which is been passed-in as argument. It does not ajax-update the client representation of the components.

You need RequestContext#update() instead wherein you just pass the client ID of the to-be-updated component.

context.update("monitorVehicleForm");

This has exactly the same effect as <p:commandXxx ... update="monitorVehicleForm">. This works provided you've a

<h:form id="monitorVehicleForm">

without any NamingContainer parent and thus have a

<form id="monitorVehicleForm" name="monitorVehicleForm" ...> 

in the generated HTML.

See also:

  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
like image 91
BalusC Avatar answered Oct 25 '22 20:10

BalusC