aspose file tools*
The moose likes Struts and the fly likes How to display string array value in  jsp for html:text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to display string array value in  jsp for html:text box" Watch "How to display string array value in  jsp for html:text box" New topic
Author

How to display string array value in jsp for html:text box

Ravi Petchimuthu
Greenhorn

Joined: May 31, 2007
Posts: 15
Hi All,

I need to display string array[]in my jsp that to in html:text which is coming from my formBean.

Please Guide me guys...
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You will need to use indexed properties for this. See question 6 of the JavaRanch Struts FAQ for more information.


Merrill
Consultant, Sima Solutions
Ravi Petchimuthu
Greenhorn

Joined: May 31, 2007
Posts: 15
I have a list of String Array in my form I need to display it in jsp with in html:text. Here, I am facing a problem like, I have given the html:text property name as my string array method name. Instead of showing the value it is showing some junk values.

My Question is. Can I able to iterate my string array in jsp.

Here I am sending you the jsp content.Kindly guide me on this.

<TR>
<TD class="border01">
Firm:  <html:text name="flm0030FormBean" property="prevExpFirm" size="50"></html:text> 

Address: <html:text name="flm0030FormBean" property="prevExpAddr" size="72"></html:text><BR>

From: <html:text name="flm0030FormBean" property="prevExpFrom"></html:text> 

to: <html:text name="flm0030FormBean" property="prevExpTo"></html:text>   

Position:  <html:text name="flm0030FormBean" property="prevExpPosition"></html:text>  

Type of business: <html:text name="flm0030FormBean" property="prevExpBusType" size="27"></html:text><BR>

Remarks: <html:text name="flm0030FormBean" property="prevExpRemarks" size="46"></html:text><BR><BR>
</TD>

These property items are declared as String array.
Ranjit Gopinathan
Ranch Hand

Joined: Jul 03, 2007
Posts: 46
Use String instead of String Array for these properties.
Ravi Petchimuthu
Greenhorn

Joined: May 31, 2007
Posts: 15
Ranjith,

I have given this one as sample, am using 3-4 rows like this code. So I should use String[] only...Give me some sample,how to retrieve data from my jsp using String[].

Ranjith/Anyone please explain.

Regards,
Ravi.P
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If I understand correctly, you are allowing the user to list previous experience, and there could be many instances of previous experience. Here's my advice:

Having a bunch of String arrays is not a good design, and it does not take advantage of the power of OOD. I'd suggest you create a PrevExperience object that has addr, from, to, comments, etc. properties. Then have an ArrayList of these objects in your ActionForm. Then read the link I gave you in my last post that tells you how to use indexed properties.
Ravi Petchimuthu
Greenhorn

Joined: May 31, 2007
Posts: 15
Thanks Merrill Higginson,

Yes I tried, but if the list is empty the logic iterate is not showing any more text boxes there in my jsp. By defaults i need to show the three rows to allow the user to insert/update the values. So if the list is empty(when coming from BackEnd) the text box rows should be populate to capture the values.

Am i making you clear. Kindly help me on this.

Thanks and Regards,
Ravi.P
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Just put logic in your action class such that if the model returns an empty list, create three empty instances of the PrevExperience object and place them in the list. That way, the logic:iterate tag will show three blank rows even if there is nothing in the database.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display string array value in jsp for html:text box
 
Similar Threads
Array of Beans in ActionForm does not retrieve any input
Collections in Struts jsp
displaying data from arrays with html:text
Display Array data in JSP
Nasty code pls