On Wed, 12 Nov 2014 19:08:44 -0200, Paul Stanton <[email protected]>
wrote:
How do I execute some javascript in the render phase of a component
which creates an object and then refer to that object when handling an
async event for the same component?
It seems you want to invoke a page or component method from JavaScript. Is
this correct? If yes, you need to do something like this in some render
phase event handler method:
private static final String EVENT_NAME = "yourEventName";
@Inject
private JavaScriptSupport javaScriptSupport;
public setupRender() { // It could by afterRender() or beginRender() too.
Link eventLink = resources.createEventLink(EVENT_NAME);
String eventUrl = eventLink.toAbsoluteURI(); // this is your event URL
javaScriptSupport.require("yourModuleName").with(eventUrl); // you pass
the event URL to our JavaScript.
}
/** This method will be invoked */
@OnEvent(EVENT_NAME)
JSONObject handleMyAjaxEvent() {
JSONObject object = new JSONObject(); The object containing the response,
if any.
....
return object;
}
The object part is basically having a field, very probably @Persist'ed,
initialized on setupRender() and accessed in your new event handler. Of
course, the best way of dealing this object is very dependent on its
nature, so the answer above isn't very precise. What exactly are you
trying to do? What does this object represent? Why do you need to access
it through AJAX after the component or page render?
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]