On Mon, 2006-01-09 at 19:11 -0500, Elam Daly wrote:
> Hi all,
> 
> I got the code below from the JSF spec, and it works fine except for
> the fact that I don't know how to put values recieved from the query
> string of a servlet into my Managed beans so that they are displayed
> when the first page initially comes up.  In fact, I can't get a
> childCount from the UIViewRoot component till after the call to
> lifecycle.render(), which calls the render response phase, which is
> the last phase in the cycle.
> 
> Any help is much appreciated.

When you're using JSP as the view technology, then the first time the
page is rendered, the components are created as rendering is done. So
obviously before lifecycle.render they won't exist. There's just no way
to explicitly "push" the values into the components before rendering.

However your query params are just keys in the request scope, so they
can be accessed using EL expressions like #{someQueryParamName} from the
JSP pages.

You should also be able to "inject" values into any request-scope
managed beans, as shown below. Note that I haven't got a web.xml example
handy, so the xml element names are only very rough :-)

  <managed-bean>
    <bean-name>myBean</beanName>
    <bean-class>example.MyBean</bean-class> 
    <scope>request</scope>
    <managed-properties>
      <managed-property>
        <name>somePropertyName</name>
        <value>#{someQueryParamName}</value>
      </managed-property>
   ....

When the jsp page refers to #{myBean}, the bean will be created "on
demand", and initialised as defined in the managed bean mapping. The
expression #{someQueryParamName} is evaluated by looking in
request/session/app scope - where it will find the query param value.

Note that the bean *must* be request-scope however, as it's forbidden to
initialise a session or app scoped bean with a request-scoped value (for
obvious reasons).


Or your backing bean can just call: 
    FacesContext.getCurrentInstance().
      getExternalContext().getRequestMap().
        get(someQueryParamName);

Regards,

Simon

Reply via email to