You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Eurig Jones <eu...@gmail.com> on 2006/08/24 23:03:18 UTC

Accessing a request parameter after submission

I have a simple request bean which handles user input. The form then 
goes to an action which saves, and set's the request bean property A.

...but when I try and access value A from the "success" page which the 
acion forwards to, it returns me a null yet I can access all other 
properties which the user has entered.

Is this normal behavior?  If so how can I access that property A from 
the success page?

Regards,
Eurig Jones

Re: Accessing a request parameter after submission

Posted by Andrew Robinson <an...@gmail.com>.
If it is request scoped, and you need to keep it in the session longer
than one request use t:saveState

On 8/24/06, Eurig Jones <eu...@gmail.com> wrote:
> I have a simple request bean which handles user input. The form then
> goes to an action which saves, and set's the request bean property A.
>
> ...but when I try and access value A from the "success" page which the
> acion forwards to, it returns me a null yet I can access all other
> properties which the user has entered.
>
> Is this normal behavior?  If so how can I access that property A from
> the success page?
>
> Regards,
> Eurig Jones
>

Re: Accessing a request parameter after submission

Posted by Martin Marinschek <ma...@gmail.com>.
Your managed bean is request-scoped, so all data is lost on the next request.

The data the user entered will still be applied to the newly created
managed bean in the next request - so you don't loose this data. This
data comes from the input-fields the user has filled out, and will
naturally be applied to your backing bean.

But the id goes down the gully - cause the user hasn't entered it, and
the bean is recreated from scratch. Bye, bye, Mr. Id.

Go with Andrews suggestion and use a t:savestate to save this value.
How does it work, you'll ask?

Simple:

<f:view>
<t:saveState value="#{mymanagedbean.id}"/>

regards,

Martin

On 8/24/06, Eurig Jones <eu...@gmail.com> wrote:
> Andrew Robinson wrote:
> > How about a little code example? Maybe there is something there. My
> > coffee hasn't kicked in yet, so maybe just tired.
> >
>
> Ok :-)
>
> A Request Bean
>
> public class NewUserBean
> {
>     private Integer id;
>     private String username;
>
>     <...getters and setters...>
>
>     public void createNewUser()
>     {
>         User user = new User();
>         user.setUsername(getUsername());
>
>         // at this point id is NULL;
>         int id = whatever.save();
>         setId(id);
>        // id is now not null
>     }
> }
>
> ..Now on the request page which shows after the createNewUser() action:
> I can output #{newUserBean.username} but outputting #{newUserBean.id}
> gives me nothing
>
>
> Hope that made sense :-)
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Accessing a request parameter after submission

Posted by Andrew Robinson <an...@gmail.com>.
Odd. I don't see anything obvious, but still tired. Okay, stabs in the dark:

1) what does setId(id) do, could you try "this.id = new Integer(id)" instead?
2) Is #{newUserBean.username} bound via EL anywhere that the value
could be being injected?
3) in your createNewUser() add "System.out.println(this);" and in the
EL in the result page add "<t:outputText value="#{newUserBean}" />"
and see if the head pointer is still the same (assuming you didn't
override the toString function on the bean)

-Andrew

On 8/24/06, Eurig Jones <eu...@gmail.com> wrote:
> Andrew Robinson wrote:
> > How about a little code example? Maybe there is something there. My
> > coffee hasn't kicked in yet, so maybe just tired.
> >
>
> Ok :-)
>
> A Request Bean
>
> public class NewUserBean
> {
>     private Integer id;
>     private String username;
>
>     <...getters and setters...>
>
>     public void createNewUser()
>     {
>         User user = new User();
>         user.setUsername(getUsername());
>
>         // at this point id is NULL;
>         int id = whatever.save();
>         setId(id);
>        // id is now not null
>     }
> }
>
> ..Now on the request page which shows after the createNewUser() action:
> I can output #{newUserBean.username} but outputting #{newUserBean.id}
> gives me nothing
>
>
> Hope that made sense :-)
>

Re: Accessing a request parameter after submission

Posted by Eurig Jones <eu...@gmail.com>.
Andrew Robinson wrote:
> How about a little code example? Maybe there is something there. My
> coffee hasn't kicked in yet, so maybe just tired.
>

Ok :-)

A Request Bean

public class NewUserBean
{
    private Integer id;
    private String username;

    <...getters and setters...>

    public void createNewUser()
    {
        User user = new User();
        user.setUsername(getUsername());

        // at this point id is NULL;
        int id = whatever.save();
        setId(id);
       // id is now not null
    }
}

..Now on the request page which shows after the createNewUser() action: 
I can output #{newUserBean.username} but outputting #{newUserBean.id} 
gives me nothing


Hope that made sense :-)

Re: Accessing a request parameter after submission

Posted by Andrew Robinson <an...@gmail.com>.
How about a little code example? Maybe there is something there. My
coffee hasn't kicked in yet, so maybe just tired.

On 8/24/06, Eurig Jones <eu...@gmail.com> wrote:
> But the property in question is the database ID of the object which I
> have just saved in the action. So i can't get to that value until the
> action is run.
>
> On my success page I can still access the user's entered properties, but
> the property which I have set in the action just gives me nulll!!
>
> Brian.S wrote:
> > You may need to make the property a managed property in faces-config
> >   <managed-bean>
> >     <managed-bean-name>myBean</managed-bean-name>
> >     <managed-bean-class>jsf.beans.myBean</managed-bean-class>
> >     <managed-bean-scope>request</managed-bean-scope>
> >     <managed-property>
> >         <property-name>propA</property-name>
> >         <value>someValue</value>
> >     </managed-property>
> >   </managed-bean>'
> >
> > Value can be a constant, or an el expression.  You can use this to make the
> > property another managed bean
> > <value>#{ObjectA}</value>
> >
> >
> > Eurig Jones-4 wrote:
> >
> >> I have a simple request bean which handles user input. The form then
> >> goes to an action which saves, and set's the request bean property A.
> >>
> >> ...but when I try and access value A from the "success" page which the
> >> acion forwards to, it returns me a null yet I can access all other
> >> properties which the user has entered.
> >>
> >> Is this normal behavior?  If so how can I access that property A from
> >> the success page?
> >>
> >> Regards,
> >> Eurig Jones
> >>
> >>
> >>
> >
> >
>
>

Re: Accessing a request parameter after submission

Posted by Eurig Jones <eu...@gmail.com>.
But the property in question is the database ID of the object which I 
have just saved in the action. So i can't get to that value until the 
action is run.

On my success page I can still access the user's entered properties, but 
the property which I have set in the action just gives me nulll!!

Brian.S wrote:
> You may need to make the property a managed property in faces-config
>   <managed-bean>
>     <managed-bean-name>myBean</managed-bean-name>
>     <managed-bean-class>jsf.beans.myBean</managed-bean-class>
>     <managed-bean-scope>request</managed-bean-scope>  
>     <managed-property>
>         <property-name>propA</property-name>
>         <value>someValue</value>
>     </managed-property>
>   </managed-bean>'
>
> Value can be a constant, or an el expression.  You can use this to make the
> property another managed bean
> <value>#{ObjectA}</value>
>
>
> Eurig Jones-4 wrote:
>   
>> I have a simple request bean which handles user input. The form then 
>> goes to an action which saves, and set's the request bean property A.
>>
>> ...but when I try and access value A from the "success" page which the 
>> acion forwards to, it returns me a null yet I can access all other 
>> properties which the user has entered.
>>
>> Is this normal behavior?  If so how can I access that property A from 
>> the success page?
>>
>> Regards,
>> Eurig Jones
>>
>>
>>     
>
>   


Re: Accessing a request parameter after submission

Posted by "Brian.S" <un...@hotmail.com>.
You may need to make the property a managed property in faces-config
  <managed-bean>
    <managed-bean-name>myBean</managed-bean-name>
    <managed-bean-class>jsf.beans.myBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>  
    <managed-property>
        <property-name>propA</property-name>
        <value>someValue</value>
    </managed-property>
  </managed-bean>'

Value can be a constant, or an el expression.  You can use this to make the
property another managed bean
<value>#{ObjectA}</value>


Eurig Jones-4 wrote:
> 
> I have a simple request bean which handles user input. The form then 
> goes to an action which saves, and set's the request bean property A.
> 
> ...but when I try and access value A from the "success" page which the 
> acion forwards to, it returns me a null yet I can access all other 
> properties which the user has entered.
> 
> Is this normal behavior?  If so how can I access that property A from 
> the success page?
> 
> Regards,
> Eurig Jones
> 
> 

-- 
View this message in context: http://www.nabble.com/Accessing-a-request-parameter-after-submission-tf2161220.html#a5972978
Sent from the MyFaces - Users forum at Nabble.com.