• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Basic Struts2 Java Function Usage

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic