You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rodrigo Pereira <ro...@gmail.com> on 2007/02/18 13:56:37 UTC

Struts-Faces: parameter

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?

Thanks,
Rodrigo Pereira

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts-Faces: parameter

Posted by Craig McClanahan <cr...@apache.org>.
On 2/18/07, Rodrigo Pereira <ro...@gmail.com> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org