On 2/18/07, Rodrigo Pereira <[EMAIL PROTECTED]> wrote:
Is there any way of passing parameters to the action instead of form fields?
I mean, I have a value on a managed bean and I'd like to pass it to
the action, how can I do that?
If the managed bean has been created already, and you know what scope
it is in, you can just use the normal mechanism to get a request
attribute, or a session attribute, and so on. But often, in a JSF
based app, that is not always the case. For that scenario, there is a
way to evaluate value binding expressions programmatically that will
work inside your action, *if* it has been forwarded to from a JSF post
(which means that the JSF lifecycle created a FacesContext for it):
FacesContext fc = FacesContext.getCurrentInstance();
ValueBinding vb = fc.getApplication().createValueBinding("#{mybean.param}");
String param = (String) vb.getValue(fc);
This will cause the managed bean named "mybean" to be created (if
necessary), then the getParam() method to be called, and that value to
be returned. In this example I presumed that the data type was a
string, but it can be any object type.
Thanks,
Rodrigo Pereira
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]