hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Lowe" <chris.lowe...@gmail.com>
Subject Re: Facing problems to send viewstate value through post method
Date Fri, 28 Nov 2008 15:07:10 GMT

I'll try to give a mini overview but I'm no expert myself.

When JSF produces a page it creates a structure of JSF components from your
jspx or facelets definition.  These components have state which may not
necessarily be obvious 'visible' data such as the component value, for
instance there may be properties used by the component implementation.

When you make a GET request for a page, then there is no previous state and
a new component heirarchy is generated.  When you post back to a JSF page,
the first thing JSF does is enter the RESTORE_VIEW phase where (I think) it
tries to access existing view state.  Without this, it cannot match the
inbound form values to components and, if I've got this right, this might be
causing you problems (esp. if you're relying on default component id

When storing view state, JSF generally has 2 modes (some implementations
bring other modes into the mix, but let's not complicate things): client
state management and server state management.  If you're using server mode,
then view state value you get in your hidden field will most likely be a
key/token that is used to retrieve view state that has been left somewhere
at the server.  If you're using client state saving mode, then the view
state value is Base64 encoded raw data of your page view state (and is
usually quite a lot of data!).  The view state can also be compressed and/or
encrypted prior to Base64 encoding depending on your JSF settings.

So if two identical forms are served then they *may* have the same client
view state (*if* your JSF implementation behaves like that, there's no
guarantee, and *if* no security features are turned on), but I think it's
unlikely they'd have the same server token.

By initially doing a get request you're ensuring that the view state,
regardless of whether it's stored at the client or server, is valid for your
post back.

Also check that the generated HTML for your form and input id attribute
values are not auto generated.  If this is the case, then you'll have more
work to do since you'll need to also extract and match up these.

I hope that helps, however I'd say that it's probably a good time to Google
on JSF and get an overview of the JSF application lifecycle and the state
saving modes ;)



2008/11/28 <sivasaibabu.parupalli@bt.com>

> Hi Chris,
> Thank you very much for that information.
> Here I need bit more clarification.
> If we parse the content resulting from GET Request and send it back will
> it be surely the same value? why because I was under the impression that
> it gets changed dynamically every time.
> And please also tell me what is viewstate will it be any string value or
> any certificate. I do not know any thing about JSF
> Thanks and Regards,
> Sai,
> pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich,
> Suffolk, IP1 2EQ,UK
> +44 1473 348748
> -----Original Message-----
> From: Chris Lowe [mailto:chris.lowe.uk@gmail.com]
> Sent: 28 November 2008 13:34
> To: HttpClient User Discussion
> Subject: Re: Facing problems to send viewstate value through post method
> Sai,
> It's not advisable to just copy the view state from your form - it will
> break the second you change your page structure.  Also, recent JSF 1.2
> implementations can be configured to expire view state as a security
> measure.
> Usually I do a GET request to the form URL first, parse the resulting
> content (a simple regex will suffice) in order to get viewstate value
> and then post back the form data with the view state.
> I hope that helps,
> Chris.
> 2008/11/28 <sivasaibabu.parupalli@bt.com>
> >
> > Hi,
> > I am trying to post data to one page through post method It is working
> > fine from IE When I am trying to get the page from my java program by
> > sending input data the same page is coming but I am not getting the
> > results page based on the input.
> >
> > When I examined the page there is one hiddenvalue '_viewstate' as that
> > page is developed by using JSF From the result page I am extracting
> > the viewstate value and when post all the input including viewstate I
> > am getting  HTTP/1.1 405 Method Not Allowed
> >
> > Please guide me how to procede
> >
> >
> >
> >
> >
> >
> > Thanks and Regards,
> > Sai,
> > pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich, Suffolk, IP1 2EQ,UK
> > +44 1473 348748
> >
> >
> >
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message