wood burning stoves 2.0*
The moose likes Struts and the fly likes Retrieve values from Object[][] using iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieve values from Object[][] using iterator" Watch "Retrieve values from Object[][] using iterator" New topic
Author

Retrieve values from Object[][] using iterator

Chen-Chien HUNG
Greenhorn

Joined: May 14, 2003
Posts: 5
In my Action code, I got the value type Object[][]. How can I get the correct value in my JSP with <logic:iterator>? following is my action code:



And the script for the method:


And my jsp code is:


And the result of my jsp is:
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You are getting these values because you are printing an object instead of a String. If you supply your Linked and Micromodule objects with "toString" methods, they will be called and print the value you specify. Also, you have the option of printing a property of the object. Example:


Merrill
Consultant, Sima Solutions
Chen-Chien HUNG
Greenhorn

Joined: May 14, 2003
Posts: 5
Does that mean I add the method "toString" in my class "Linked" & "Micromodule"? like:


If so, where should I call this method? In my jsp file?

Beside, I tried to print the property of the object with the code:


Then I got the error message:
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Every object has a toString method that prints out the object ID. Those strange looking values the printed on your page were Object IDs. What I was suggesting is that you override the toString method of your objects to print something meaningful to you. For example, the toString method of an address object might be:

If you provide a toString method, it is called automatically by Struts when you specify the object with no property in the <bean:write> tag.

The reason it didn't work when you specified a property is that you specified it incorrectly. Change your tag to

and make sure the object has a getLocalnb method.
[ September 12, 2008: Message edited by: Merrill Higginson ]
Chen-Chien HUNG
Greenhorn

Joined: May 14, 2003
Posts: 5
Following your suggestion, I override toString method in my two classes: Linked & Micromodule and modified my jsp code to see what happended. Now my jsp code is:


And the result is :


I don't know why the values in "row" is still the strong IDs and why only in the second result we can have the values that are readable. If I add the property (localnb) to show in the jsp, then I got the same error, that means there is not getter method, however, this method does exist in my class Micromodule. After all, I went through my scripts and have following questions:
1. Basically my 2 dimension array has the type Object[Linked][Micromodule], in the jsp file, does "row" mean the content of "Linked" and "col" for "Micromodule"?
2. In side the "Linked" class, there are the fields of type of user defined, like "Kchip", "Bundles". I tried to override toString method of these two classes, when I run the application, I got the error "java.lang.StackOverflowError". Without overriding toString inside these two classes, I got the result as above. Why? Does this cause the value like "[Ljava.lang.Object;@64eff0 " in the result

Thanks a lot for your help!
 
 
subject: Retrieve values from Object[][] using iterator
 
Similar Threads
From an input-field into a form
nested logic:iterate
logic:iterate in struts
Struts1.1 ( TreeView & Paging)
logic:empty tag question