File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL/JSTL Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL/JSTL Help" Watch "EL/JSTL Help" New topic
Author

EL/JSTL Help

Luke
Greenhorn

Joined: Sep 14, 2005
Posts: 10
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 ]
Chandra Atla
Ranch Hand

Joined: Jul 21, 2004
Posts: 91
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
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
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

Joined: Sep 14, 2005
Posts: 10
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

Joined: Jul 21, 2004
Posts: 91
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

Joined: Sep 14, 2005
Posts: 10
Mat

Thanks a lot. It worked.

Thanks
Luke
Luke
Greenhorn

Joined: Sep 14, 2005
Posts: 10
Chandra

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

Thanks
Luke
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL/JSTL Help
 
Similar Threads
Garbage Collection for out of scope objects references
jsp:useBean && forEach
Simple Question
Jstl foreach iterate over arraylist containing map object using paramvalues
How to do this with JSTL 1.1?