aspose file tools*
The moose likes Struts and the fly likes Problem in displaying multiple search results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in displaying multiple search results" Watch "Problem in displaying multiple search results" New topic
Author

Problem in displaying multiple search results

rakshini nithya
Ranch Hand

Joined: Jun 15, 2006
Posts: 39
Please help me in this issue.

I have the following problem.

Am able to search a person by giving his first name and display the search result

But am not able to display multiple results.

For eg if two persons are having same same first name like Merril and Merril john

Am not getting multiple results for that

Am getting result as Merril John itself twice

How to get Merril and Merril John displayed in the same search results


Search Member Action

Search Member Data


SearchResults.jsp
<logic:iterate id="memberinfo" name="Member" scope="request">


<tr height=20px bgcolor=#FFFFFF>
<td align=left class=tdBorderRightBottom><bean:write name="memberinfo" property="firstName"/></td>
<td align=left class=tdBorderRightBottom><bean:write name="memberinfo" property="lastName"/></td>
<td align=left class=tdBorderRightBottom><bean:write name="memberinfo" property="employeeID"/></td>
<td align=center class=tdBorderRightBottom><bean:write name="memberinfo" property="emailID"/></td>
<td align=center class=tdBorderRightBottom><bean:write name="memberinfo" property="vnet"/></td>
<td align=left class=tdBorderRightBottom><bean:write name="memberinfo" property="extension"/></td>
<td align=left class=tdBorderRightBottom><bean:write name="memberinfo" property="mobileNumber"/></td>
</tr>

</logic:iterate >
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
Hi

I think at this point

you need to specify the 'property' you want to iterate through as well.

You haven't posted code for the ActionForm, so I cannot tell you what this is.

As an aside, declaring variables like this:

or this:

will probably get you lynched by future maintenance programmers. Follow the java coding guidlines, specifically these ones and your code will magically transform into readable statements like


hope this helps
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, all of your seach methods are wrong. In every case, you only create one instance of the MemberInfo bean. Then, in your loop as you read through the result set, you're replacing the data in the same instace of the bean rather than creating a new instance for every row. Then you put that same instance into the array list. You end up having a liast of say, 10 rows, each of which is pointing to the same instance of MemberInfo, which has data for the last row in the ResultSet.

To solve this, move this line:

MemberInfo memberinfo= new MemberInfo();

from its current location to right after:

while(rs.next())
{

Do this in each of your search methods.

You also have a problem in your Action.

Remove the following statement from SearchMemberHNTeamProfileAction:

request.setAttribute("MemberInfo",memberinfo);

It's creating a neame conflict. In your <logic:iterate> tag in the JSP, you are also using a bean name of memberinfo. Here's what you're telling Struts to do when you write this tag:

<logic:iterate id="memberinfo" name="Member" scope="request">

Loop through every element of the ArrayList identified by the name "Member" in request scope. For each item in the array, create a bean with the name "memberinfo" that represents the current item in the loop. Any statements below this can use the name "memberinfo" to identify that bean.
[ July 24, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
rakshini nithya
Ranch Hand

Joined: Jun 15, 2006
Posts: 39
Thanks a lot
I created the instance for member info inside the result set and now
Am Getting multiple search results now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in displaying multiple search results