• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why my 2D float array not showing values in my jsp

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends i am having a two dimentional float array (flowratearray) in my Action Form.In JSP i am having 2D array of text fields representing this property.


i am setting one 2d Array of values to this poperty by calling setter method in Action class execute method.But in my jsp page i am not getting those values, instead i am getting irrelavant values([F@139626c],...) in those text fields.

Here is my jsp code:
-----------------------

<logic:iterate id="row1" name="PumpCalibForm" property='flowarray' indexId="ctr1">
<tr>

<logic:iterate id="row2" name="PumpCalibForm" property='timearray' indexId="ctr2">
<td>
<html-el:text name="PumpCalibForm" property='flowratearray[${ctr1}][${ctr2}]'/>
</td>
</logic:iterate>
</tr>
</logic:iterate>


===============================
Action class execute() method:
=================================

float testarray[][]=new float[i][j];

for(int k=0;k<i;k++)
for(int l=0;l<j;l++){
testarray[k][l]=k+3.5f;
}
pcform.setFlowratearray(testarray);


===========================
My ActionForm code
============================
private float[][] flowratearray;

public float[][] getFlowratearray() {
return flowratearray;
}
public void setFlowratearray(float[][] flowratearray) {
this.flowratearray = flowratearray;
}
public float getFlowratearray(int i, int j) {
return flowratearray[i][j];
}


what else i have to provide. where is the problem.
I will be greatful to u....
thanks..
jakeer ahmed
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing your problem is in where you try to define the property attribute of th e html:text tag. The property attribute expects a string. As far as I know, there is no preprocessing done on the property attribute, so trying to access a specific index in the property won't work.

Of course, I would expect it to throw some PropertyNotFound type exception at that point and apparently it doesn't so maybe I'm way off base here.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The authors of the Struts framework recommend that an action form be made up of Strings and booleans. The <html:text> tag expects text, or in other words a String. Change the getter in your form bean so that it provides a string representation of the float, and change the setter so that it takes a string as a parameter and turns it into a float.
 
jakeer ahmed
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all thanks for response.

I have changed the 2D array property of ActionForm itself from float type to String type.For that getters ,setters are like this.



Still i am getting [[Ljava.lang.String;@1e4605c....] type values in my 2D array text fields.they are not showing the values which i have set.

what to do
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple of things:

1-Struts tags don't do well with overloaded methods. Call the method that retrieves an array something different from the method that retrieves a single value. (e.g. getFlowratearray and getFlowratearrayElement)

2-Try actually converting the floats to Strings. Here's an example for your getter method:



Likewise, your setter method must actually convert a String to a float, not just assign it.
[ February 12, 2006: Message edited by: Merrill Higginson ]
 
jakeer ahmed
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Merril thanks for ur response.

Now i am not using float type array atall. I am using String type two dimensional array.
As you said i tried to remove overloding of methods by changing setter and getter methods.But my jsp view itself is not coming.its not working.
I think for two dimensional array type ActionForm properties some special care has to be taken.I surfed some sites but didnt get anything.
what is the solution?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although I've never used a double indexed array in a Struts form, I saw no reason it wouldn't be possible to use one. However, now I'm beginning to think it would be best just to abandon the double indexed array and use an object graph.

Create an object that represents a single row's worth of data, and then put those objects in an arrayList. Add an indexed getter for a single row in the form bean. Then, in your JSP, use something like this for the property name:

row[${rowIndex}]column[${columnIndex}]
 
jakeer ahmed
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merril thanks for ur suggession.
right now i am only displaying the values of two dimensional string array.
its fine , if i am putting text fields then it was the problem.
For time being its ok.
In future i will try your's suggession of using object graph.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic