Greetings All,
What I'm trying to accomplish is this. I want to have a listbox(listA) pass it's selected (multiple) values to a bean which in turn will create a dynamic list for the second listbox(listB). My setProperty pulls in the the values which is defined as a
String array. The getProperty I have defined takes the array and concatenates the values and returns a single String.
I referenced Frank's post (
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=001041 ) but it doesn't cover multiple values.
However in doing this, my
JSP reports that it "Can't find a method to write property 'area' in a bean of type 'PrefillFormView'". Do the values of the getter and setter need to be of the same type?
I was able to workaround this by creating another getter method(getAreaOut) with a different name that does the conversion for me, instead of the original getter method(getArea). Is there a way to do this without using this workaround? Please keep in mind, I am attempting to do this without using any code in my JSPs...
My bean...
import java.sql.*;
import java.net.*;
public class PrefillFormView
{
private String[] _prefillArea;
private String[] _prefillAreaOut;
public PrefillFormView()
{
_prefillArea = new String[] { "" };
}
public String[] getArea()
{
return _prefillArea;
}
public String getAreaOut()
{
StringBuffer list = new StringBuffer();
String[] myarray = _prefillArea;
if ( myarray != null )
{
for (int i = 0; i < myarray.length; i++)
{
list.append( myarray[i] + "\n");
}
}
return list.toString();
}
public void setArea(String[] sArea)
{
_prefillArea = sArea;
}
}
My JSP...
<%@ page language="java" contentType="text/html" import="PrefillFormView" %>
<jsp:useBean id="prefills" class="PrefillFormView" scope="request" />
<HTML>
<HEAD>
<title>CAMI Automotive Downtime Reporting</title>
<BODY>
<FORM NAME="myForm" ACTION="index.jsp" METHOD="POST"
<TABLE width="100%">
<TR>
<TD width="15%">Area:</TD>
<TD width="1%"></TD>
<TD width="84%">
<SELECT MULTIPLE size=5 name=lstArea onBlur="submit();">
<OPTION SELECTED VALUE="A">ITEM A</OPTION>
<OPTION VALUE="B">ITEM B</OPTION>
<OPTION VALUE="C">ITEM C</OPTION>
<OPTION VALUE="D">ITEM D</OPTION>
<OPTION VALUE="E">ITEM E</OPTION>
<jsp:setProperty name="prefills" property="area" param="lstArea"/>
</SELECT>
<BR/>
</TD>
</TR>
<TR>
<TD width="15%">Area Selected:</TD>
<TD width="1%"></TD>
<TD width="84%">
<TEXTAREA NAME="MYTEXT" ROWS=5 COLS=40><jsp:getProperty name="prefills" property="areaOut" />
<%
StringBuffer list = new StringBuffer();
String[] myarray = prefills.getArea();
if ( myarray != null )
{
for (int i = 0; i < myarray.length; i++)
{
list.append( myarray[i] + "\n");
}
}
out.println(list.toString());
%>
</TEXTAREA>
<BR/>
</TD>
</TR>
</TABLE>
<HR/>
<INPUT type=submit value="View Report" name=cmdReport>
</FORM>
</BODY>
</HTML>