File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Dynamic Data Input and Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Dynamic Data Input and Bean" Watch "Dynamic Data Input and Bean" New topic

Dynamic Data Input and Bean

S Santosh Kumar
Ranch Hand

Joined: Mar 14, 2004
Posts: 43
I am stuck up in following problem.. I've to use this concept in my application.
getter and setter methods are used in Beans for getting/setting values from JSP.
So far I've seen only one data 'string' in setter methods when it is set thru JSP.
What to do when we want to set "array of strings" thru JSP.
Suppose application prompts user to give size of a two dimensional string array( a X b)
If user enters 2 X 3 , then next JSP page should give a grid to enter data in 2 X3 format.
Now how to take these values in variables and user setter methods of bean to take value in two dimensional array ??
How the variables in JSP/HTML will be named in such case when columns and rows both are variables ???
Please HELP ???

Early bird catches the worm, but remember "early worm" gets caught by bird.
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
You can use javascript/HTML form field to receive the input from the user (the value of each cell in the 2D array).
Use a loop to generate the HTML, otherwise, you'll be hardcoding <TD> tags forever if your 2D array is large. For instance,

Now, as part of your form, you will have a table cell with the name of the row, followed by a '#' delimiter, and then the column(i.e. "0#0", "0#1", "1#0", "1#1"...). This makes it easy to parse the names. When you submit this form, the page which accepts the submission will have a similar loop to iterate through each parameter and store the value in your Java 2D array.
Hope this helps,

for (int i = today; i < endOfTime; i++) { code(); }
I agree. Here's the link:
subject: Dynamic Data Input and Bean
jQuery in Action, 3rd edition