-
1. Re: jsFunction: how to sync inputText value before actionListener gets invoked
h2g2 May 27, 2011 9:10 AM (in response to ginc)Hi,
there may be other cleaner solution, but this one should do it : instead of managing immediately the event, postpone it and repost it for a later phase (when you model will be updated).
This should look like this with :
public final void aListener(final ActionEvent event) throws Exception {
final PhaseId phaseId = event.getPhaseId();
if (phaseId.equals(PhaseId.ANY_PHASE)) {
// In order to retrieve data updated from the model before the managment of
// the event, we postpone the management of the file upload event
event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
event.queue();
} else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES)) {
// do all your stuffs here
manageMyEvent(event);
}
}
Hope this will help.
-
2. Re: jsFunction: how to sync inputText value before actionListener gets invoked
ginc May 27, 2011 7:25 PM (in response to h2g2)Well, i guess this will work somehow, but as you said it is not a clean way of doing it.
There has to be a way to submit the inputBox value to the backing bean, before the actionlistener invokes!
Can somebody tell me how to achive this? (I still you like to work with jsFunction)
-
3. Re: jsFunction: how to sync inputText value before actionListener gets invoked
ginc May 27, 2011 8:47 PM (in response to ginc)ok, here is what i have done so far:
First, I tried to achive it with a4j:param.
<a4j:jsFunction name="anyName" actionListener="#{Bean.doSomething}" render="test"> <a4j:param name="param1" assignTo="#{Bean.inputValue}" /> </a4j:jsFunction>
if i call the function with "anyName('test')" the value 'test' does get assign to inputValue, but unfortunetely AFTER the actionListener gets invoked.
This is not very useful, since i do need the value in the bean.
So I came up with this (dirty) solution:
Calling another jsFunction (tmpFunction('test')), which calls the actual jsFunction (anyName()).
<a4j:jsFunction name="tmpFunction" oncomplete="anyName()"> <a4j:param name="param1" assignTo="#{Bean.inputValue}" /> </a4j:jsFunction> <a4j:jsFunction name="anyName" actionListener="#{Bean.doSomething}" render="test" />
This seems to be the only way to make sure the value is assigned before the backing bean is invoked.
It works, but I don't like it.
Does somebody know how solve this in a cleaner way??
Thanks
Gregor
-
4. Re: jsFunction: how to sync inputText value before actionListener gets invoked
nbelaevski May 28, 2011 2:42 PM (in response to ginc)For this code:
<a4j:jsFunction name="anyName" actionListener="#{Bean.doSomething}" render="test">
<a4j:param name="param1" assignTo="#{Bean.inputValue}" />
</a4j:jsFunction>Either action instead of actionListener or call doSomething via nested f:actionListener/a4j:actionListener tag.
-
5. Re: jsFunction: how to sync inputText value before actionListener gets invoked
ginc May 28, 2011 3:01 PM (in response to nbelaevski)That's it. This was the input I was looking for.
Thank you very much Nick!
Here is the working solution:
<a4j:jsFunction name="anyName" render="test"> <a4j:param name="param1" assignTo="#{Bean.inputValue}" /> <a4j:actionListener listener="#{Bean.doSomething}" /> </a4j:jsFunction>
calling it with: anyName('valueForInputValue');