This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static fields are not populated

 
lokesh rajarathnam
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Im new to Struts, I try to execute few of the examples and I struck in one of the issue.
Issue : The action class has static field which is a list. How to populate that list in jsp.

Action Class

struts.xml


while i try to populate the list I got an error ------> str is not a collection/arrray/list (similarly to this)
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's static, it will be shared across the instances of the action and it will be accessed from multiple threads, you'll have to synchronize access to the list!

Why did you make it static? Probably there is a better solution...

while i try to populate the list I got an error ------> str is not a collection/arrray/list (similarly to this)


Can you show us the code..?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Lorand: Actions are instantiated per-request.

We need to see the JSP in order to help.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:@Lorand: Actions are instantiated per-request.


I know that. :confused:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lorand Komaromi wrote:
David Newton wrote:@Lorand: Actions are instantiated per-request.


I know that. :confused:

Besides that it's a read-only list in the context of a JSP option tag, it's much, much less important to worry about static action properties, unlike in Struts 1. Even a user with multiple tabs/windows open would be hard-pressed to cause a problem.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:
Besides that it's a read-only list in the context of a JSP option tag, it's much, much less important to worry about static action properties, unlike in Struts 1.


Correct me, if I'm wrong, but whether the action gets instantiated for each request or not has nothing to do with the thread safety of a static member, it's still accessed from multiple threads!

And it was not obvious to me that by "populating that list" he referred to the the UI tag in the JSP, I thought he wanted to insert elements in the List... :rolleyes:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lorand Komaromi wrote:Correct me, if I'm wrong, but whether the action gets instantiated for each request or not has nothing to do with the thread safety of a static member, it's still accessed from multiple threads!

Oh, I understand what you're saying. Yeah, you're right, although my impression was still that it wasn't populating the dropdown as the original poster expected.

I'm not exactly sure what I was thinking, really.
 
lokesh rajarathnam
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for incomplete posting of my issue.....
The issue is solved.....

Thanks all for your valuable time.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic