aspose file tools*
The moose likes Struts and the fly likes list empty using s:select tag with Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "list empty using s:select tag with Struts 2" Watch "list empty using s:select tag with Struts 2" New topic
Author

list empty using s:select tag with Struts 2

Harsha Mulani
Greenhorn

Joined: May 13, 2006
Posts: 13
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

Joined: Sep 29, 2008
Posts: 12617

You're giving a listKey and listValue for a list with objects that have no such properties.
Harsha Mulani
Greenhorn

Joined: May 13, 2006
Posts: 13
Thank David.

But I have a question here, does this mean, I can do without listkey and listvalue?
Harsha Mulani
Greenhorn

Joined: May 13, 2006
Posts: 13
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

Joined: May 17, 2010
Posts: 67
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

Joined: Sep 29, 2008
Posts: 12617

"applicationlist" is not the same as "applicationList", which is how you've named the property per your getter.
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
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

Joined: Sep 29, 2008
Posts: 12617

@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

Joined: May 13, 2006
Posts: 13
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

Joined: Aug 03, 2008
Posts: 9305
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harsha Mulani
Greenhorn

Joined: May 13, 2006
Posts: 13
My bad .. I did not check the basics

Thanks Ankit for pointing out what's wrong; I've corrected it and it works now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: list empty using s:select tag with Struts 2