JSF "viewstate" parameter - what is it doing?

J

Jan Thomä

Hello,

i am currently trying to get some better knowledge around Java Server
Faces and did a small tutorial on it. I created more or less a hello
world page. Inside the page i had a form and JSF magically created a
hidden field called ViewState which contains a lot of hex digits. From
what I read on the net this field is holding some state information
however i was unable to find out how the field is actually filled and
if it is needed at all. Therefore I'd like to ask for further pointers
on where i could read up more about this ViewState thing - web
addresses, books etc.

Thank you.

Best regards,
Jan
 
A

Arved Sandstrom

Hello,

i am currently trying to get some better knowledge around Java Server
Faces and did a small tutorial on it. I created more or less a hello
world page. Inside the page i had a form and JSF magically created a
hidden field called ViewState which contains a lot of hex digits. From
what I read on the net this field is holding some state information
however i was unable to find out how the field is actually filled and if
it is needed at all. Therefore I'd like to ask for further pointers on
where i could read up more about this ViewState thing - web addresses,
books etc.

Thank you.

Best regards,
Jan

I wouldn't be able to tell you exactly how the state is created, but in
the later JSF implementations it is often Base64 encoded and also
compressed. The view state can be stored either on the server (in which
case all that's sent to the client is a view ID) or all of it is sent to
the client. You can control this in your web.xml with the
javax.faces.STATE_SAVING_METHOD context-param, values either 'server' or
'client'.

If you choose 'client' and look at the source of your page, you'll likely
see one hidden element with the state for each form.

If the request contains a javax.faces.ViewState parameter, which it will
in either case, JSF will know that this is a postback.

The view state, in a nutshell, is everything associated with a page that
you need to reconstruct its state. Basically the values of UIComponents.
For example, the current value of an inputText.

I have no idea where you can get nitty-gritty details, other than the JSF
source.

AHS
 
A

Arne Vajhøj

Jan said:
i am currently trying to get some better knowledge around Java Server
Faces and did a small tutorial on it. I created more or less a hello
world page. Inside the page i had a form and JSF magically created a
hidden field called ViewState which contains a lot of hex digits. From
what I read on the net this field is holding some state information
however i was unable to find out how the field is actually filled and if
it is needed at all. Therefore I'd like to ask for further pointers on
where i could read up more about this ViewState thing - web addresses,
books etc.

I can not find anything about it in the JSF specs or java docs.

So my assumption is that is is implementation specific.

Obviously inspired by ASP.NET !

Arne
 
L

Lew

Jan said:
i [sic] am currently trying to get some better knowledge around Java Server
Faces and did a small tutorial on it. I created more or less a hello
world page. Inside the page i [sic] had a form and JSF magically created a
hidden field called ViewState which contains a lot of hex digits. From
what I read on the net this field is holding some state information
however i [sic] was unable to find out how the field is actually filled and
if it is needed at all. Therefore I'd like to ask for further
pointers on where i [sic] could read up more about this ViewState thing -
web addresses, books etc.
I can not find anything about it in the JSF specs or java docs.

So my assumption is that is is implementation specific.

Obviously inspired by ASP.NET !

You are likely correct. There is a brief mention of it on
<http://java.sun.com/developer/EJTechTips/2006/tt0225.html>
(and repeated verbatim [plagiarized?] on at least one other site I googled).

It seems to have something to do with "Specifying Where State Is Saved",
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnaxj.html#bnaxn>

There are many links, some to this clj.programmer thread, in a search for
"Java JSF ViewState". GIYF.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top