www.webdeveloper.com
Results 1 to 2 of 2

Thread: struts: accessing list-backed properties in JSP

  1. #1
    Join Date
    Apr 2005
    Posts
    10

    Exclamation struts: accessing list-backed properties in JSP

    hi. im trying to make a dynamic form(request time) using list-backed property, following the struts user guide

    http://struts.apache.org/userGuide/b...n_form_classes

    public FooForm extends ActionForm {

    private final List values = new ArrayList();

    public void setValue(int key, Object value) {
    values.set(key, value);
    }

    public Object getValue(int key) {
    return values.get(key);
    }
    }

    however, im not sure of what they mean by:

    "In your presentation pages, you access individual entries in a list-backed property by using a different special notation: listname[index]. The braces in the bean property name indicate that the bean property named listname is indexed (probably backed by a List), and that Struts should look for get/set methods that take an index parameter in order to find the correct sub-property value."

    how can i access the property? heres my jsp:

    <%@ taglib uri="/tags/struts-html" prefix="html" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@page isELIgnored = "false" %>

    <html>
    <body>
    <html:form action="/indextest">

    <c:forEach begin="0" end="2" var="cnt">
    <html:text property="listname[${cnt}]"/>
    <br/>
    </c:forEach>

    <html:submit>Submit</html:submit>
    </html:form>
    </body>
    </html>


    any help appreciated...

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    what you should do is create a bean/class with 2 properties in it e.g
    Code:
    public class User{
     private String name;
     private String id;
    
     public String getName(){
       return this.name;
     }
    
     public void setName(String name){
       this.name = name;
     }
    
    public String getId(){
       return this.Id;
     }
    
     public void setId(String id){
       this.id = id;
     }
    
    }
    once you have that thne you create this class and set its properties once you have that then you put these in a list and then when you acess it in the struts page you access it by the name of properties such as name and id
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles