PDA

View Full Version : Problem with String array from a javabean


dlainger
07-25-2009, 02:49 AM
Hello-
I am trying to write a web app which uses JSP and Java Beans.
My java bean parses an xml file and loads a String array with "Labels" which I then display in an input tag of type text which is read only.
The problem is that there are 5 labels which should be returned.
The only one that shows up is the last item in the array.
Here is my .jsp file:
<HTML>
<HEAD></HEAD>
<link rel="StyleSheet" href="goldenBoy.css">
<BODY BGCOLOR="#6699FF">
<jsp:useBean id="view" class="webton.init"/>
<jsp:setProperty name="view" property="defview" value="Bollux" />
<CENTER>
<H3><jsp:getProperty name="view" property="defview" /></H3>
<HR>
<FORM METHOD=get>
<CENTER>
<jsp:useBean id="parse" class="webton.parseView"/>
<jsp:setProperty name="parse" property="viewtoparse" value="http://localhost:8080/webtonto/Home.view" />
<jsp:setProperty name="parse" property="item" value="dummy" />

<%

String Labels[] =parse.getLabeldata();
%>
<%

for(int t=0;t<Labels.length;t++){
Integer IT = new Integer(t);
String item = IT.toString();
%>
<INPUT TYPE="text" VALUE=<%=parse.getItem(item)%> size="150" readonly="readonly" onclick="clickcolor(this)" onblur="clickwhite(this)" />
<P>t= <%= t%></P>
<%}%>
<!--<P>View Name: <%= parse.getName()%></P>
<P>View Target: <%= parse.getTarget()%></P>
<P>View App: <%= parse.getApp()%></P>-->
</FORM>
<script type="text/javascript">
function clickcolor(thisfield) {

thisfield.style.background= "#C5ECF4";

}

function clickwhite(thisfield) {
thisfield.style.background= "#FFFFFF";
}
</script>
</BODY>
</HTML>
My java bean was tested in eclipse and seems to work correctly.
Does anyone see anything wrong with this code?
Is there something about java beans which does not allow String arrays to be used as properties?
When I run the app as I mentioned the only label that appears is the last one and it appears as the first label in the list of input textfields.
The four remaining input textfields have labels which say null.
-D

dlainger
07-25-2009, 11:40 PM
Me again-
Well I think I've decided to skip the string array approach and so in my java bean I return a concatenated string (comma delimited) and just get my array in the .js file using the 'split' method.
This seems to work.
I would be interested, though, if anyone can shed some light on this string array problem.
-Cheers
-D.