This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes adding hidden values that is a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "adding hidden values that is a list" Watch "adding hidden values that is a list" New topic
Author

adding hidden values that is a list

steve kelly
Ranch Hand

Joined: Feb 15, 2012
Posts: 36
Whats the syntax for declaring a hidden field thats a list? And adding to it etc? I want to be able to store some rows when a user saves.

I currently have a screen with a spreadsheet where the user can collapse and expand rows via a plus/minus button. I want the screen to remember after the save which rows where collapsed or expanded and refresh accordingly.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

All form elements with the same name will participate in the same request parameter of that name. The array of values can be retrieved from the request within the servlet via request.getParameterValues().


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
steve kelly
Ranch Hand

Joined: Feb 15, 2012
Posts: 36
how do I implement it...like below?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

steve kelly wrote:how do I implement it...like below?


Does that seem like valid HTML to you? Remember, everything you do at the browser is just HTML. Any JSP-isms are just to iniitally generated the HTML page to send the browser.

As I said, all form elements with the same name become the array of values. So to create an array of "rowID" values:


Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
Hi,

As for the original question, if you want to have a dropdown list that's hidden, then in your drop down element use
if that's what you want. Otherwise if you want an array follow Bear's post


Programming is about thinking, NOT coding
steve kelly
Ranch Hand

Joined: Feb 15, 2012
Posts: 36
OK I this is what I am doing...

I have this declaring my hidden field on jsp page


When user saves I have this code that iterates through the plus/minus rows and determines if they needed to ba added to a variable "rowID"



later when I want to access this variable the alert below is always undefined. I want to access whats been stored. How do I do this?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

Your row variable is declared deep within a function. It will only be available within that function. Declare it at a higher scope.

Though I'm still not exactly sure what you are trying to accomplish. What are you actually trying to collect?
steve kelly
Ranch Hand

Joined: Feb 15, 2012
Posts: 36
Basically the rows are collapsing plus/minus nested rows in a spreadsheet form. So I want the ability for user to click save and the screen to remember which lines they had previously expanded or collapsed after the save/submit.

Right now after saving I re-expand all lines and its very inconvient if you have lots of lines. Maybe I am just going about this totoally wrong?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

And each row has a unique id, and you want to just send this list of ids to the server? (So that you can use the list to determine which rows are "open" next time the page is viewed?)
steve kelly
Ranch Hand

Joined: Feb 15, 2012
Posts: 36
Bear Bibeault wrote:And each row has a unique id, and you want to just send this list of ids to the server? (So that you can use the list to determine which rows are "open" next time the page is viewed?)

what you said in the bold. yes
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

Are you doing this at submit time? If so, how can it be determined if a row is opened or closed?

In any case, to send the info back to the server you can:
  • Create multiple hidden inputs as I detailed in a previous reply. If they all have the same name, the values can be retrieved as an array.
  • "Cheat" and create a single hidden input that contains the list as a comma-separated string that you can parse at the server.

  • The latter involves less logic on the page, and more on the server. The former, just the opposite.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: adding hidden values that is a list