aspose file tools*
The moose likes Struts and the fly likes Basic Struts2 Java Function Usage 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 "Basic Struts2 Java Function Usage" Watch "Basic Struts2 Java Function Usage" New topic
Author

Basic Struts2 Java Function Usage

Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Hey Guys-

I am starting on a new web project here at work that I've decided to use Struts2 for. I wrote my last project in straight JSP with servlets, and I wanted something a bit more structured this time, with easier form management. I ordered a Struts2 book, but it hasn't come in yet, and in the meantime I've been trying to tinker around with the framework to try to get a feel for it.

I've been trying to make a checkboxlist but I can't seem to get the tag to read my array variable right.

What do I all need to have in my Java classes to make a variable "readable" by the Struts tags in JSP?

Right now, I have 2 classes, one (Register) which extends ActionSupport and provides the interface to modifying the Person class from the JSP (or so I gather). In the person class, I have a String array and a getter for it (no setter, since I just want it to display a few options). When I try to create a checkboxlist, I call:


I get an exception saying that:
tag 'checkboxlist', field 'list', name 'Test List': The requested list key 'personBean.testList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location].

Am I missing something that's required to access my testList array? It's declared as a String[] and filled in the normal manner.

Here's my Person code (I'm using http://www.brucephillips.name/blog/index.cfm/2008/10/7/Introduction-toThe-Struts-2-Java-Web-Application-Framework as my basis, and modifying the code):



Thanks for any help you can give me!
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Struts2 uses the name attribute to specify the property that you want to use to display which fields in the list have been selected. So its cheching your action class for the property and it isn't finding anything. Change the name attribute to reference a property and I think this will work better.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

Firstof all your list name comes from Action which is not contains space.

in your jsp write

<s:checkboxlist name="testList" list="testList" />


Your Action class looks like this.
private String[] testList;

then getter and setter method


/**
* @return the testList
*/
public String[] getTestList() {
return testList;
}

/**
* @param testList the testList to set
*/
public void setTestList(String[] testList) {
this.testList = testList;
}

one method which gives Struts.xml to which jsp include

public String excecute(){

return "success";
}



Thanks,
Nishan Patel.


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic Struts2 Java Function Usage