On 7/12/06, Iakouchev Alexander-EAL027C <[EMAIL PROTECTED]> wrote:
Is this possible to pass dynamically information from a beans as a
shale method parameter?
Alex.
In JSF 1.1, you cannot do this (it's not a Shale issue, it's the basic
functionality of JSF method binding expression). In JSF 1.2, you can ...
but only for calls to static methods.
A better general strategy is to invoke a method that takes no parameters,
but ensure that the called method can extract whatever it needs. For
example, consider the standard JSF call to your action method (which takes
no parameters). There are at least two ways for the called method to access
request parameters on the incoming request:
* Via JSF programmatic APIs:
// Retrieve the value of the "foo" parameter
FacesContext context = FacesContext.getCurrentInstance();
String foo = (String)
context.getExternalContext().getRequestParameterMap().get("foo"0;
* By managed beans expression evaluation. This example requires
a bit more setup to configure, but is much easier to use because
the values are injected for you. Consider again that you want to
extract the value of the "foo" parameter and use it in your myAction()
action method. Define your managed bean entry like this:
<managed-bean>
<managed-bean-name>mybean</managed-bean-name>
<managed-bean-class>com.mypackage.MyBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>foo</property-name>
<value>#{param.foo}</value>
</managed-property>
</managed-bean>
and set up your bean class like this:
package com.mypackage;
public class MyBean {
...
private String foo = null;
public String getFoo() { return this.foo; }
public void setFoo(String foo) { this.foo = foo; }
...
public String myAction() {
// Get the value of the "foo" request parameter
String foo = getFoo();
...
}
...
}
The formula #{param.foo} is evaluated when the managed bean is created, and
extracts the value of the request parameter named "foo" and calls setFoo()
on your bean. By the time the action method is called, the value will be
there already.
Craig