• 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

EL/JSTL Help

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

This is my bean code

package Foo;
public class Bean {
private int a;
public int getIntA(){return a;}
public void setIntA(int a){
this.a =a;
}
}

My Servlet Code

Bean []MyBeanArray = {new Bean(), new Bean(),new Bean()};
for (int i=0; i<MyBeanArray .length;i++){
MyBeanArray[i].setIntA(i);
}
request.setAttribute("MyObject",MyObject);
request.getRequestDispatcher("/jsp/MyJsp.jsp").forward(request,response);


This is my Jsp code


<%@ page isELIgnored = "false" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:forEach var = "myBean" items= "${requestScope.MyObject}" varStatus ="MyBeanCounter">
Bean value of ${MyBeanCounter.count} is ${myBean.IntA}
</c:forEach>

myBean.IntA prints the beanOject "Foo.Bean@10c94a7"
How do I print the actual value ?



[ October 11, 2005: Message edited by: Luke ]
[ October 11, 2005: Message edited by: Luke ]
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Luke,
Try doing the following..

Either you can change the line

private int a;

to private int intA;

OR change the getter and setter methods to getA() and setA(int a) respectively.

Thanks,
Chandra A
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

without trying it out (so I could very well be wrong ), the only thing that I can see that looks like it needs changing is the ${myBean.IntA} shoud be ${myBean.intA} the EL parser will change this to myBean.getIntA() which you have.

HTH

Mat
 
Luke
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chandra

Thanks for your reply. Is that change required for EL to work? As far as i remember that is necessary in tag classes. Is that required for beans?

Luke
 
Chandra Atla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.. It is required for beans.

If the bean property name is say "price" the getter method name should be "getPrice()" and the setter method name should be "setPrice(int value)".

(I am assuming that price is of int type).

Thanks,
Chandra
 
Luke
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mat

Thanks a lot. It worked.

Thanks
Luke
 
Luke
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chandra

You are correct. The bean law 2 on Pg 350 says that.

Thanks
Luke
reply
    Bookmark Topic Watch Topic
  • New Topic