• Post Reply Bookmark Topic Watch Topic
  • New Topic

EL cannot get my bean attribute with "." operator  RSS feed

 
Tak Ming Laio
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean something like:
public class NormalTestQuestionBean implements Serializable {
private static final long serialVersionUID = -8455246466385706192L;
private int qId;
private String qText;

public int getQId() {
return qId;
}
public void setQId(int id) {
qId = id;
}
public String getQText() {
return qText;
}
public void setQText(String text) {
qText = text;
}
}
and a servlet something like:
public class ControlServlet extends HttpServlet {
private static final long serialVersionUID = 1797971647102217363L;

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
NormalTestQuestionBean[] qList = NormalTestBroker.loadNormalTest();
request.getSession().setAttribute("qList", qList);
getServletContext().getRequestDispatcher("NormalTest.jsp").forward(request, response);
} catch (DBException e) {
request.setAttribute("message", "Database error");
getServletContext().getRequestDispatcher("message.jsp").forward(request, response);
}
}
}
and finally my JSP, like:
<%@ page language="java" contentType="text/html; charset=BIG5" pageEncoding="BIG5"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>Normal Test</title>
</head>
<body>
<form action="ControlServlet" action="post">
<table>
<c:forEach var="question" items="${qList}" varStatus="status">
<tr>
<td align="right"><cut value="${status.count}"/></td>
<td><cut value="${question.qText}"/></td>
</tr>
</c:forEach>
</table>
<input type="submit" value="Done" align="middle">
</form>
</body>
</html>
This JSP give this error:
javax.servlet.ServletException: Unable to find a value for "qText" in object of class "elvis.bean.NormalTestQuestionBean" using operator "."
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.NormalTest_jsp._jspService(NormalTest_jsp.java:65)
What is I doing wrong? Please help!
[ January 21, 2007: Message edited by: Bear Bibeault ]
 
Tak Ming Laio
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reformatted, please help!

I have a bean something like:

and a servlet something like:

and finally my JSP, like:

This JSP give this error:

What is I doing wrong? Please help!
 
Tak Ming Laio
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it myself. If I change the attribute of the bean to id, text instead of qId, qText, it works fine. The getter method become getText instead of getQText, and I use the EL expression ${question.text} to refer it. I am working on Tomcat 5, I wonder whether it is the Tomcat problem or JSTL EL mechanism problem to proper handle bean attributes of the format of xXxxx.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to give some feedback, the problem was caused because of your attribute naming and the getters/setters.

The method getQText actually exposes the javabeans attribute "QText", and not "qText" as you were expecting.
If the first two letters in a getter/setter method are both capitalized, then it does NOT convert the first letter to lower case

Reference:
http://java.sun.com/j2se/1.5.0/docs/api/java/beans/Introspector.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!