struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lundin, Michael" <Michael.Lun...@SUMMITSITE.COM>
Subject Multiple Fields In Struts
Date Fri, 22 Feb 2002 16:01:19 GMT

Hello,

I am new to struts and am trying to get a set of multiple fields to work on
both the request and response page.  The page needs to be able to display a
set of fields that are determined at runtime (therefore no specific set and
get methods can be used).  I've got it working under a non-struts
environment, but can't get it to work under struts.

My main question is how to turn it into struts and still keep the same
functionality.  If I just change the form elements to Struts HTML elements,
it doesn't function (with an Action object that simply forwards it onto the
results page).  

Here's what I have for the non-struts solution:

Initial Page: 

<html>
<head><title>JSP Page</title></head>
<body>
<jsp:useBean id="multitest" scope="request"
class="com.summitsite.trueimage.MultiBean" />

<form action="MultiResults.jsp">
<%	String[] fieldNames = multitest.getDocumentFieldNames();
	String currentName = null;
	for (int i = 0; i < 10; i++) { 
		currentName = fieldNames[i];
		<p><%= currentName %>: <input type="hidden" name="fieldName"
value="<%= currentName %>" />
		<input type="text" name="documentSearchField" size="40"
/></p>
   <% } %>
	<input type="submit" value="Submit"/>
</form>
</body>
</html>

Results Page:

<html>
<head><title>JSP Page</title></head>
<body>

<jsp:useBean id="multitest" scope="request"
class="com.summitsite.trueimage.MultiBean">
</jsp:useBean>

<%	
	
	String[] setFields =
request.getParameterValues("documentSearchField");
	String[] setNames  = request.getParameterValues("fieldName");
	if (setFields != null) {
		for (int i = 0; i < setNames.length; i++) {
			multitest.setDocumentSearchField(i, setFields[i]);
			multitest.setFieldName(i, setNames[i]);
		}
		for (int i = 0; i < setNames.length; i++) {
			out.println("<p>" + multitest.getFieldName(i) + ": "
+ multitest.getDocumentSearchField(i) + "</p>");
		}
	}
%>

</body>
</html>

Bean:

public class MultiBean extends ActionForm implements Serializable {
	
	private String[] documentSearchField = new String[50];
	private String[] fieldName			 = new String[50];
	
	public MultiBean() {
	}
	
	public String[] getDocumentSearchField() {
		System.out.println("String[] getDocumentSearchField()");
		return documentSearchField;
	}
	
	public void setDocumentSearchField(String[] fields) {
		System.out.println("void setDocumentSearchField(String[]
fields)");
		this.documentSearchField = fields;
	}
	
	public String getDocumentSearchField(int i) {
		System.out.println("String getDocumentSearchField(int i)");
		return documentSearchField[i];
	}
	
	public void setDocumentSearchField(int i, String field) {
		System.out.println("void setDocumentSearchField(int i,
String field)");
		this.documentSearchField[i] = field;
	}
	
	public String[] getDocumentFieldNames() {
		System.out.println("String[] getDocumentFieldNames()");
		String[] array = new String[15];
		
		for (int i = 0; i < array.length; i++) {
			array[i] = "Field " + i;
		}
		
		return array;
	}
	
	
	public String[] getFieldName() {
		return fieldName;
	}
	
	public void setFieldName(String[] fields) {
		this.fieldName = fields;
	}
	
	public String getFieldName(int i) {
		return fieldName[i];
	}
	
	public void setFieldName(int i, String field) {
		this.fieldName[i] = field;
	}
}


Any assistance would be greatly appreciated.  Thanks,

Michael Lundin

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message