This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Static fields are not populated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Static fields are not populated " Watch "Static fields are not populated " New topic
Author

Static fields are not populated

lokesh rajarathnam
Ranch Hand

Joined: May 17, 2007
Posts: 35
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

Joined: Oct 08, 2009
Posts: 276
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..?


OCJP 6 (93%)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Lorand: Actions are instantiated per-request.

We need to see the JSP in order to help.
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
David Newton wrote:@Lorand: Actions are instantiated per-request.


I know that. :confused:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 08, 2009
Posts: 276
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 17, 2007
Posts: 35
I apologize for incomplete posting of my issue.....
The issue is solved.....

Thanks all for your valuable time.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static fields are not populated
 
Similar Threads
converting string array to string
Generating all the permutations nad combinations of the given alphabets
Unable to compile class for JSP:
Vector vs LinkedHashSet iteration speed
Hibernate Search indexing...w/ Compass