• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

problem using s:action tag

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic