?
Solved

Struts Form containing Vector

Posted on 2004-11-24
5
Medium Priority
?
931 Views
Last Modified: 2012-06-21
My Struts Form Contains a vecotor. how do i display the contents of the Vector using struts iterate?
0
Comment
Question by:sharath_kulal
5 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12667707
<logic:iterate id="vector" name="myHash" type="java.util.Vector">
<logic:iterate id="myVal" name="vector" type="java.lang.Whatever">
//do something
</logic:iterate>
</logic:iterate>

-----------------
or try
-----------------
<logic:iterate id="myVal" collection="<%= vector %>" type="java.lang.Whatever">
//do something
</logic:iterate>



Note: neither of these were tested.
0
 

Accepted Solution

by:
vsaritha_9 earned 375 total points
ID: 12668385
Where is your Vector?
Is it in Session scope or request scope?
if you don't specify scope attribute in logic:iterate then it looks for your vector in session scope.

<logic:iterate id="mList" scope="session"  name="yourVectorName" type="data type of objects that vector holds">

For Example:
If your vector contains  the collection of descriptions of type String and it is named as myVector and added to the session scope then you logic:iterate tag would look like this

<logic:iterate id="mList" scope="session"  name="myVector" type="java.lang.String">
   <bean:write  name="mList" property="description"/>
</logic:iterate>

Hope this helps
0
 

Expert Comment

by:ClazzeFlits
ID: 12670232
If the elements in the Vector are Strings, I don't think you need to specify a property.

Example:
<logic:iterate id="elementId" name="yourVector" type="java.lang.String">
   <bean:write name="elementId"/>
</logic:iterate>

0
 

Expert Comment

by:vsaritha_9
ID: 12670811
yes your right, Property is required if the collection contains javabean

Thank you for correcting me
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12671416
Hi sharath_kulal,

Well, I hope that my example can help you to understand how to iterate vector in JSP using iterate tags.

<html>

<%
    Vector a = new Vector();
    a.add("1");
    a.add("2");
   
    request.setAttribute("Vector", a);
%>
<body class="bodycontent">
<logic:iterate id="test" name="Vector">
    <bean:write name="test" />
</logic:iterate>
</body>
</html>

Thanks.

Regards
Dave
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question