RSS Forums RSS
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1175 | Replies: 2 | Thread Tools  Display Modes
Reply
Join Date: Oct 2007
Posts: 5
Reputation: Melzy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Melzy Melzy is offline Offline
Newbie Poster

Question How do I pass a value for an array element to a bean from a form?

  #1  
Oct 23rd, 2007
The class that my bean uses has an array textFields[407]. I have 407 textfields in my jsp file. I used a loop to make the textfields. So, it looks something like this:

  1. <%for ( int i = 0; i < lineCount; i++ ) {%>
  2. <INPUT TYPE="TEXT" NAME="textFields"+i SIZE="4" MAXLENGTH="7" VALUE=<%= transaction.getTextField(i)%>>
  3. <%}%>

The problem lies in the NAME. What should be its syntax so i can say that I am passing the value of the ith textField in the jsp file to the ith element of the array in the bean?

Is this possible? or should I do another kind of approach?
Last edited by Melzy : Oct 23rd, 2007 at 9:26 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 5
Reputation: Melzy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Melzy Melzy is offline Offline
Newbie Poster

Re: How do I pass a value for an array element to a bean from a form?

  #2  
Oct 23rd, 2007
please help me.

I tried:
NAME="textFields["+i+"]"
NAME="textFields["+<%=i%>+"]"
NAME="textFields[i]"
NAME="textFields[<%=i%>]"

I'm running out of ideas. Could this approach be impossible? but it would be hell if I am gonna give 407 unique names in the bean for the 407 textFields. That isn't approprite. there should be an easier way.
Reply With Quote  
Join Date: Aug 2007
Posts: 74
Reputation: lookof2day is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
lookof2day lookof2day is offline Offline
Junior Poster in Training

Re: How do I pass a value for an array element to a bean from a form?

  #3  
Oct 28th, 2007
The given code might help...
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="person.Person" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<%
	Person [] persons = new Person[3];
	persons[0] = new Person("aaa","aa","dfdd");
	persons[1] = new Person("vvv","vvv","dfgd");
	persons[2] = new Person("ggg","gg","dty");
%>
<body>
	<%
		int i=0;
		for( i=0; i<persons.length; i++){
			String firstName = persons[i].getFirstName();
			%>
			<input type="text" name='f<%=i%>' value="<%=firstName%>">
			<br>
			<%
		}
	%>
</body>
</html>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:55 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC