This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

User Profile Dispay On Clicking on a particular user in user List

 
Vamsi Krishna Varma
Greenhorn
Posts: 5
Java PHP Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,Every one! I am doing a sample application where in i am displaying list of users in a JSP file using struts2 iterator tag.My requirement is if i click on a particular user i want to display his profile with out making another call to Database.So i want to store users list response in a local variable in JSP file and set a attribute(unique id or key) for every user while displaying.If a particular user is clicked then extract the profile information from local variable (holding list of users info) based on attribute set for every user and display the user profile with the corresponding data of the user.Please help me out.Thanks in advance
 
Vamsi Krishna Varma
Greenhorn
Posts: 5
Java PHP Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My requirement is similar to a earlier post in the site




[Post New]posted Friday, February 10, 2012 2:01:44 PM
Quote Report post to moderator
Hello guys..!

I having a doubt regarding accessing an array of arraylist in jsp using iterator tag.

In my action class i used the following codes..,

ArrayList[] arr= new ArrayList[10];

for(int i=0;i<10;i++)
{
arr[i]=new ArrayList<bean>();
}
.
.
.
while(some conditions)
{
arr[i].add(new bean(some values));
i++;
}


My question is, how can i access the values of arr[0],arr[1]...a[10] in JSP page using iterator.

<s:iterator value=???> <s:property value=beanvalues /> </s:iterator>
 
Yogesh Lonkar
Ranch Hand
Posts: 94
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create getter and setter methods for ArrayList arr and then manipulate <s:iterator value="arr"> tag as per your requirements
 
Vamsi Krishna Varma
Greenhorn
Posts: 5
Java PHP Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Yogesh Lonkar

Thanks For Replying

Actually i am using the following code in JSP to display users

<s:iterator value="users" status="stat">

<div class="memberAttrHolder" onclick=memberProfileDisplay(<s:property value="id "/>)>
<div class="memberAttr"><s:property value="id"/></div>
<div class="memberAttr"><s:property value="name"/></div>
<div class="memberAttr"><s:property value="team"/></div>
</div>
</s:iterator>

where users hold the list of users returned from action class

So how can i retrieve a particular user information on click using getter set to array list


And i want to clarify one more thing

I am trying to store the user list returned in a html hidden element using

<s:hidden id="users" value="%{users}" />

When i try to get the value set to it using getElementById Method and alert it i am values that are encrypted.Do anyone know how to parse this so that it can be used as local variable




 
Yogesh Lonkar
Ranch Hand
Posts: 94
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to list hidden in JSP unless you have specific reasons, because that list will not be thrown until you redirect to some other action or same action.
and what you can do is include some thing like this in your iterator

which will guide you to DisplayUser action passing id of user of which info will be Displayed
Now what you have do to is map DisplayUser action to certain method in your CurrentAction.class or create new action class and there you need to get this parameter "id" passed. Then in that method or class obtain specific user by iterating your "users" list.It will look something like this inside that method
 
Yogesh Lonkar
Ranch Hand
Posts: 94
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamsi Krishna Varma wrote:
<s:iterator value="users" status="stat">
<div class="memberAttrHolder" onclick=memberProfileDisplay(<s:property value="id "/>)>
<div class="memberAttr"><s:property value="id"/></div>
<div class="memberAttr"><s:property value="name"/></div>
<div class="memberAttr"><s:property value="team"/></div>
</div>
</s:iterator>

please user Code tags for java codes i forgot to suggest you earlier
 
Vamsi Krishna Varma
Greenhorn
Posts: 5
Java PHP Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai, Yogesh Lonkar I have applied the same solution that you suggested(Add URL for every user(See User),Action mapping for the same,I have mapped it to a function in action class,I am getting parameter (id of every user) from url param using getter and setter).But the problem i am facing is i am getting Null Pointer Exception when i try to get users list for comparing id value and getting info specific to a user.


Any Idea regarding this?


Thanks a lot for your solution !!!
 
Yogesh Lonkar
Ranch Hand
Posts: 94
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamsi Krishna Varma wrote:Hai, Yogesh Lonkar I have applied the same solution that you suggested(Add URL for every user(See User),Action mapping for the same,I have mapped it to a function in action class,I am getting parameter (id of every user) from url param using getter and setter).But the problem i am facing is i am getting Null Pointer Exception when i try to get users list for comparing id value and getting info specific to a user.


Any Idea regarding this?


Thanks a lot for your solution !!!



if you have created different action class for action then you better create getter and setter for users too. that way that list will be available to you in this new class
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic