Meaningless Drivel is fun!*
The moose likes Struts and the fly likes problem using s:action tag 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 "problem using s:action tag" Watch "problem using s:action tag" New topic
Author

problem using s:action tag

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Here is a small test application that does following things

1. ask user to enter his name and submit - (index.jsp)
2. as a result of index.jsp is the welcome.jsp page that asks user to select his/her blood group

index.jsp



struts.xml


SelectBloodGroup.java



welcome.jsp



Struts is unable to identify bglist as a collection or Array or List or iterator. WHAT SHOULD I ASSIGN TO list ATTRIBUTE IN THE s:select TAG IN THE FILE welcome.jsp

What is wrong with the code please tell me in detail. If you could send me the correted version. WHY IS THE s:action Tag not working ?

This is the error i am getting

Apr 13, 2010 1:49:19 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list': The requested list key 'bglist' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't like the use of the action tag for this purpose.

That said, use the "var" attribute (or "id" if you're still using Struts 2.0) to put the action on the value stack. If you use "foo" as the attribute value, access the list with "#foo.bglist".

The next answer is "because there aren't any public getters."
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Thanks alot i purchased a copy of your book "Apache Struts 2
Web Application Development"and it solved my problem! after a little googling i came to know that there are loopholes with the action tag. Although i have done this using the action tag, but the performance is very poor.

is there another way to work around this problem, - How to populate the option based components select, combo etc from within the result jsp. is there any other way except using action tag.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why would you want to populate them from the JSP? In general, JSPs should be used only for view-related things, not gathering data.
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
but i dont see any other way of doing it. what can we do when we need to populate our select box residing in your result jsp.
here it is



the SelectSubject.jsp has a small dropdown menu which contains various subjects (Math, Phy, Chem..etc). is there anyother way of populating the dropdown except using a list returned by a method in another class say Subject.java.

how would you populate this dropdown without hardcoding the subjects. what else can i use, like bean or push or set. what is the best way to do it?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If the same data is being used by multiple actions I'd refactor out the creation of that list and have the actions use that. For example, in the apps I've worked on, data like that would come from a service. The actions that needed that data would have a service that could retrieve it. When the action is executed it grabs the data from the service and exposes it to the JSP.

If the data *never* changes it could just be put into application scope on app startup.
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
thanks alot ! now i got. Why do books do not also talk about the best way to use various features of a language. As a developer the most frustrating is when you have tools/concepts to work on, and you also understand them but you dont understand the most efficient way of using them. I think books must also talk about the best practices.

I am happy that your book is satisfying this craving of a programmer. Thanks alot once again
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Examples are tough: if you do everything "just right" it'd be too big. There's almost always a trade-off between readability, size, effectiveness, and completeness.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem using s:action tag
 
Similar Threads
Need help - cannot find resource welcome.do
problem calling static method using OGNL
New to Struts, where did I go wrong?
Struts 2 client side validation not working with xml configuration
how to dynamically generate struts2 form tags and populate with action