Hello all,

I am wondering if anyone knows how to get multiple fields (text input
boxes) on a form to read into a string array in the JavaBean?  Ideally, I
would have 5 input boxes on the form, and use a javabean that has the
get/set methods the same as the input element names. However, 5 input boxes
may turn into 20 one day, and I dont want to keep adding a bunch of private
string types, and multiple get/set methods for each of these boxes.
Instead, since its basically the SAME content (such as address 1, address
2, address 3 ) but may contain different values, I just want to call one
method that somehow determines the specific index in the array to read it
into.

Thus, something like:

<jsp:useBean id="mybean" scope="session" class="com.bm.ui.beans.MyBean" />
<jsp:setProperty name="mybean" property="*" />

<form method="post">
<input type="text" name="data" value="<%= mybean.getData(1) %>"><br>
<input type="text" name="data" value="<%= mybean.getData(2) %>"><br>
<input type="text" name="data" value="<%= mybean.getData(3) %>"><br>
<input type="submit" name="send">
</form>



So, in the above, when they submit the form, the 3 elements would call the
same method, setData(), but store each in the private variable data[0],
data[1], and data[2]. See in the mybean.getData() I pass it a number to
use. This would indicate the index. So how would the bean work calling the
setData(String value) method, to put the data in the appropriate index
automatically? Or would I have to manually enter the set methods for each one?

I would like to write a tag-lib for this one day, and the number of input
boxes will be a variable that can be changed, at a per-page basis if
necessary.

Also, is it ok at the END of the whole transaction, to remove the bean from
the session and set it to null so as to garbage collect it? The reason I
set it to sessional is so if they make a mistake in one of the fields (we
have server-side validation of fields), when it flips the page over showing
the form, it still displays the values they entered previously. Now..I
would rather make it request scope, but I dont know if that works with
request scope (havent tried it myself). Does anyone know this? I want to
kill the objects existence once the form is submitted. I assume the
<jsp:useBean..> puts the bean on the session. In the second page, the
"finished" page that the bean forwards to to let them know they have been
approved, that would have some scriplet code that would remove the mybean
bean from the session if it exists (which it should), and set it to null.
Is this a good way of doing this?

Thanks for any help.

Kevin Duffey
Software Engineer
[EMAIL PROTECTED]

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to