tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Delisle <pierre.deli...@sun.com>
Subject Re: c:set can't set JavaBean property
Date Wed, 18 Dec 2002 18:47:01 GMT
Mike,

This NullPointerException is caused by the fact that a write method does not exist
in your bean for property 'day'. 

For example, this would happen if you had a getDay() method, but not
a setDay() method on your bean.

However, from the code snippet you've sent, it looks like that property
is defined... but the VM says it is not. In these situations I tend
to trust the VM rather than the programmer :-)

So... Why don't you isolate your problem in a single JSP file that you
could send to this alias. If we have the full story, it will be easier
to help you debug this problem.

I've included below the test I ran and which worked for me.

    -- Pierre

[I'll file a bug so that a proper error message is returned when
this situation occurs (rather than the NPE)]

-----------------------------

<%@ page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<h3> Test &lt;c:set&gt;</h3>
<%!
    public class Foo {
      Date date = new Date();

      public void setDay(int day) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
 
        int max = cal.getMaximum(Calendar.DAY_OF_MONTH);
        day = (day > max) ? max : day;
 
        cal.set(Calendar.DAY_OF_MONTH, day);
        date = cal.getTime();
      }

      public Date getDate() {
        return date;
      }
    }
%>

<%
    Foo foo = new Foo();
    pageContext.setAttribute("foo", foo);
%>

<c:out value="${foo.date}"/><br>
<c:set target="${foo}" property="day" value="1"/>
<c:out value="${foo.date}"/>

-----------------------


Mike Cantrell wrote:
> 
> I'm seeing some really strange problems while trying to use JSTL's
> <c:set> action to set a property of a JavaBean. It's throwing a
> NullPointerException (see below for stackTrace).
> 
> It doesn't like to set my property "day". If I create a setter method
> with a different name (day2 for instance), which simply calls the
> original setter method (day), everything works fine (code included below).
> 
> I'm a bit stumped. Maybe I'm missing something obvious here but I'm just
> not seeing what the problem is. Can anyone offer any advice?
> 
> JSP:
> ===============================
> 
> <jsp:useBean class="com.alcatel.date.AlaDate" id="start" scope="request"/>
> <jsp:useBean class="com.alcatel.date.AlaDate" id="end" scope="request"/>
> 
> <c:choose>
>   <c:when test="${param.mode eq 'month'}">
>    <c:set target="${start}" property="deltaMonth" value="-1"/>
>    <%-- <c:set target="${start}" property="day" value="1"/>  --%>
>    <c:set target="${start}" property="day2" value="1"/>
> 
>    <c:set target="${end}" property="deltaMonth" value="-1"/>
>    <%-- <c:set target="${end}" property="day" value="31"/> --%>
>    <c:set target="${end}" property="day2" value="31"/>
>   </c:when>
>   <c:otherwise>
>    <c:set target="${start}" property="deltaDay" value="-7"/>
>   </c:otherwise>
> </c:choose>
> 
> JavaBean:
> ===============================
> 
>    public void setDay(int day) {
>      GregorianCalendar cal = new GregorianCalendar();
>      cal.setTime(date);
> 
>      int max = cal.getMaximum(Calendar.DAY_OF_MONTH);
>      day = (day > max) ? max : day;
> 
>      cal.set(Calendar.DAY_OF_MONTH, day);
>      date = cal.getTime();
>    }
> 
>    public void setDay2(int day) {
>      this.setDay(day);
>    }
> 
> Exception:
> ===============================
> java.lang.NullPointerException
>         at
> org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSupport.java:172)
>         at
> jrun__push__caseSummary2ejsp15._jspService(jrun__push__caseSummary2ejsp15.java:188)
>         at jrun.jsp.runtime.HttpJSPServlet.service(HttpJSPServlet.java:43)
>         at jrun.jsp.JSPServlet.service(JSPServlet.java:106)
>         at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
>         at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
>         at
> jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:241)
>         at
> jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
>         at
> jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:198)
>         at
> jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:348)
>         at
> jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
>         at
> jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:294)
>         at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
> 
> --
> To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>


Mime
View raw message