Announcement Announcement Module
Collapse
No announcement yet.
How to treverse List in JSP. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to treverse List in JSP.

    Hi with spring MVC 3.0.5 and jsp, I tried to treverse a List of beans, but it thrown the following exception:

    ...
    02:15:53,992 ERROR [org.springframework.web.servlet.tags.form.LabelTag] (http--192.168.1.20-8080-3) Invalid property 'article' of bean class [LuxuryLiving.manager.pagebean.ProductBean]: Bean property 'article' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?: org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'article' of bean class [LuxuryLiving.manager.pagebean.ProductBean]: Bean property 'article' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:707) [spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.BeanWrapperImpl.getNeste dBeanWrapper(BeanWrapperImpl.java:555) [spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.BeanWrapperImpl.getBeanW rapperForPropertyPath(BeanWrapperImpl.java:532) [spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    ....

    jsp code:

    Code:
    <c:forEach var="article" items="${productbean.articles}" >
                       <tr>
                                <td><form:label for="article.header" path="article.header" > Header:</form:label></td>
                                <td colspan="2"><form:textarea path="article.header" value="${article.header}"   /></td>
                        </tr>
                    </c:forEach>
    productbean class:

    Code:
    public class ProductBean {
        private static final Logger logger = Logger.getLogger(ProductBean.class);
            
            private String productId = "";
    	@Size(min=6, max=80, message="Product name must be between 6 and 80 characters")
            private String productName = "";
            private List<ProductArticleBean> articles;
    ...
    public List<ProductArticleBean> getArticles() {
            return articles;
        }
    
        public void setArticles(List<ProductArticleBean> articles) {
            this.articles = articles;
        }
    ProductArticleBean class:

    Code:
    public class ProductArticleBean {
    protected String header = "";
        protected String pointForm = "";
        protected String productDesc = "";
    public String getHeader() {
            return header;
        }
    
        public void setHeader(String header) {
            this.header = header;
        }
    
        public String getPointForm() {
            return pointForm;
        }
    
        public void setPointForm(String pointForm) {
            this.pointForm = pointForm;
        }
    
        public String getProductDesc() {
            return productDesc;
        }
    
        public void setProductDesc(String productDesc) {
            this.productDesc = productDesc;
        }
    I know the problem is in my jsp file, but I couldn't figured out how to correct the error.
    Any suggestion is very appreciated.
    Thanks
    Sam

  • #2
    If I tried with <c:out only, it works:

    Code:
    <c:forEach var="article" items="${productbean.articles}" >
                       <tr>
                            <td><c:out value="${article.productId}"/> </td>
                                <td><c:out value="${article.productDesc}"/> </td>
                                
                        </tr>
                    </c:forEach>
    But I need Path and Value from spring, so that I can pass the values to my backing bean.

    Comment


    • #3
      Please use the search and read the reference guide that should answer your question. Also the stacktrace should be a giveaway.

      Path should be the path to the property on your form object, your formobject doesn't have a article property. You should use the index to retrieve it.

      Code:
      <c:forEach var="article" items="${productbean.articles}" varStatus="status" >
                         <tr>
                                  <td><form:label for="article.header" path="articles[status.index].header" > Header:</form:label></td>
                                  <td colspan="2"><form:textarea path="articles[status.index].header" /></td>
                          </tr>
                      </c:forEach>
      Also the value is pretty useless as that is already provided by spring, that is the reason for bind tags in the first place.

      Comment

      Working...
      X