Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hidden field can carry any type of java objects ?  RSS feed

 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to use hidden variable to carry some big objects (like very long arraylist, String[][]), is there any known issue or restriction for hidden variable to carry such objects ?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can store objects that you have described in a single hidden field.

Better you put in to session, if you to pass those objects to the next link.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can store objects that you have described in a single hidden field.


No, you can't. Like all other input types, you are restricted to strings.
 
Jack Wiesenthaler
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you are you talking about hidden FORM fields? The concept of "hidden" applies only as a flag to the browsers HTML rendering engine... the browser has no concept of Java objects!!!
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, to clarify, I was talking about hidden form field like
<FORM ACTION="/myaction" >

<type="radio" name="..", value="..">...
....

<type="HIDDEN" name="hidden_obj" value="<%= request.getAttribue("obj") %>">

</FORM>

So, I do want to get an object passed. Can I do that this way ?
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't put an object there at all. Just a string. Remember what the <%= operator does, it prints out a String. Now Java has a little feature, where if you try and print out an object, it automatically calls the objects toString() function.

So what you have to do if you really want to do this, is convert it to a string, for example using ";" characters to seperate each string in the array. Then you have to read the string back in and create the objects from it again, for example using a StringTokenizer.

Other things you can consider are like said above, putting the objects on the Session object.

Perhaps just putting an 'id' in a hidden field, which refers to an item in a structure which is held at the application level.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks folks. So, it seems the only way to carry the "objects" over pages is to use "session" ? I am wondering how people handle such things when "HttpSession" was not available to java developers ? Furthermore, how do those ASP, Cold fusion people do it ? interesting.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why wouldn't you have a session or be unable to create one?
If you have an Http server you have sessions, they're not some magical Java feature that some servers have and other don't.

Read up on the servlet specification and the HTTP specifications, you might learn a thing or two.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
Why wouldn't you have a session or be unable to create one?
If you have an Http server you have sessions, they're not some magical Java feature that some servers have and other don't.

Read up on the servlet specification and the HTTP specifications, you might learn a thing or two.


I was just asking questions about "hidden fields", and I guess it has nothing to do with "whether session is better or can I use session ?"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!