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 Error testing EL with bean 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 "Error testing EL with bean" Watch "Error testing EL with bean" New topic
Author

Error testing EL with bean

Nimit Shah
Ranch Hand

Joined: Jul 02, 2007
Posts: 53
Hi, Following is the jsp I am using to test EL.
Line Bean : ${requestScope.sniferdog.name} throws exception saying it can not find property name. If anybody finds an answer please let me know.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*"
contentType="text/html" pageEncoding="UTF-8"%>
<%!
class SniferDog{
private String name="Snifer Dog";
private StringBuffer logs=new StringBuffer("No Logs");

String getName(){
return name;
}

void setName(String _name){
this.name=_name;
}

StringBuffer getLogs(){
return logs;
}

void setLogs(StringBuffer _logs){
this.logs=_logs;
}
}
%>
<%
ArrayList list=new ArrayList();
list.add("1");
list.add("dog");
list.add("2");
Map map=new HashMap();
map.put("dog", "Snifer Dog");
map.put("string1", "1");
map.put("Integer1", Integer.valueOf(1));
request.setAttribute("list", list);
request.setAttribute("map", map);
request.setAttribute("sniferdog", new SniferDog());
request.setAttribute("abc", "asdf");
%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Hello World!</h2>
RequestScope : ${requestScope.list["1"+"1"]}<br/>
Map : ${map["Integer1"]} <br/>
Bean : ${requestScope.sniferdog.name} <br/>
<%=((SniferDog)request.getAttribute("sniferdog")).getName()%>
Logical : ${true||false&&false}
</body>
</html>
Ranil Liyana Arachchige
Ranch Hand

Joined: Sep 20, 2008
Posts: 71

Hi,

It seems to be a problem with the access modifiers . EL may not be able to access the property if those are not available through methods which are public. In that case if you make the methods public then the class also has to be changed accordingly. This would work if you change the access modifiers to public in the method level as well as class level.

public class SnifferDog{

public String getName(){}..
public void setName(String name){}...

}

hope that helps

Best Regards,
Ranil


SCJP 1.4 (80%) , SCWCD5.0 (91%) , SCEA / OCMEA
Nimit Shah
Ranch Hand

Joined: Jul 02, 2007
Posts: 53
These methods were public when I started coding. It did not work.

However it all works with <%=((SniferDog)request.getAttribute("sniferdog")).getName()%>
Nimit Shah
Ranch Hand

Joined: Jul 02, 2007
Posts: 53
any help?
Ranil Liyana Arachchige
Ranch Hand

Joined: Sep 20, 2008
Posts: 71

Did you make the Class public ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error testing EL with bean