• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

list empty using s:select tag with Struts 2

 
Harsha Mulani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help for a s:select tag

i have an action that returns a Collection:
In the jsp page I wrote


This is the code of my action



In the list I want see app1, app2 app3 added to application list.
when I execute my application there are no errors but my list is empty?What I can do?
Please help me!!!
Thank you!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're giving a listKey and listValue for a list with objects that have no such properties.
 
Harsha Mulani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank David.

But I have a question here, does this mean, I can do without listkey and listvalue?
 
Harsha Mulani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I changed my code as below and now I am getting an error:



Changes done to code:

Included application.java file below:


Action class updated to include:

jsp updated to:


struts.xml as:

 
suraj savaratkar
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
if you want to get a values in '.jsp' with some collections you have to put into the session or request and get access
by using OGNL expressin in '.jsp'. You already written getter and setter methods for that collections.

public String getApplication()
{
return application;
}

public void setApplication(String application)
{
this.application = application;
}


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"applicationlist" is not the same as "applicationList", which is how you've named the property per your getter.
 
suraj savaratkar
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be does like,
HttpServletRequest request;

declare a setter and getter methods for request,
set your list into request and access in '.jsp' using <s:property value="#request.listName"/>
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@suraj: Please stop confusing the issue: the reason "applicationlist" wasn't resolved is because the getter is written as "getApplicationList()", meaning the correct OGNL expression would be "applicationList". Also, "#request" is *already present* in the value stack--not only would adding a getter be redundant, your expression is incorrect, since "#request" would refer to a *named* value stack object rather than one present on the stack itself. If there was a (again, redundant) "getRequest()" in the action it would be accessed with "request" in OGNL, not "#request".
 
Harsha Mulani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem I face is funny It is similar to the initial problem I posted in this thread.

David, thank you, with your comment to check the case of "applicationlist",I was able to populate the applicationlist.

Now, I have another list declared in the same fashion; the details are as below and it is empty. I think I am missing something; can someone please check?

Jsp:


Issue.java:


Action.java:


I fail to understand what could be going wrong; I have cross checked the code for issueList field with the applicationList field and all looks fine to me

Thanks
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again the name of your getters don't match the name you specify in listKey and listValue. Your getters in Issue class are getAppId and getAppName not getIssueId and getIssueName. So your properties are not matching...
 
Harsha Mulani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad .. I did not check the basics

Thanks Ankit for pointing out what's wrong; I've corrected it and it works now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic