You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Givler, Eric" <eg...@state.pa.us> on 2005/08/03 20:01:56 UTC

JSTL 1.0 problem with Bayern Ch 11 example...

I'm having a heck of a time trying to get the Bayern example from chapter 11 working, and I'm really not sure why....

I created an enterNumber.jsp page:

<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
  <form action="parseNumberCarefully.jsp" method="post">
  Enter your favorite number <input type="text" name="favorite"/>
  <br/><input type="submit" name="submit" value="Submit"/>
  </form>
  </body>
</html>


I created an parseNumberCarefully.jsp page:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>

<html>
  <head>
    <title>parseNumberCarefully.jsp</title>
  </head>
  <body>
    <p>You entered "<c:out value="${param.favorite}"/>"</p>
    <c:catch var="parsingError">
      <fmt:parseNumber var="fav" value="${param.favorite}"/>
      <p>As far as I can tell, this corresponds to the number
        <c:out value="${fav}"/>.
      </p>
      <p>If you multiply this number by 2 and add 1, you get
        <c:out value="${fav * 2 + 1}"/>. I like that number better.
      </p>
    </c:catch>
    <c:if test="${not empty parsingError}">
       Sorry, this doesn&rsquo;t look like a number to me. Perhaps you&rsquo;re in the wrong country?
    </c:if>
  </body>
</html>


If I run the first page, enter a valid#, then click [submit], I get correct results.
If I run the first page, enter an invalid # (i.e. abcd), then click [submit], I get correct results.
However, if I enter an invalid#, click [back], then enter a valid number, I keep getting parse errors.  It's as if the <catch> keeps RECREATING the parsingError exception on subsequent requests even though the data has changed and is valid.

The reason I tried to do this simple example was that I was creating a multi-record entry form, and trying to validate with JSTL.  When I did this, as soon as the form would detect bad data, every record after it would be considered "invalid data".  In these cases, I'd end up either clearing the rest of the data, or it would retain the first "good data" and ovewrite all subsequent records, or I'd get a stack trace.  I thought all of the code that I was writing was "syntactically" correct, but it did not produce the results that I wanted.

If parseNumberCarefully.jsp has an errorPage attribute defined, and you remove the <c:catch> tag, and enter an invalid value, an error page is displayed. Now, if you hit [back] to goto the entry page, and enter a valid value, it works fine.

What am I missing?

I'd appreciate any assistance on this.

I'm running this against Oc4J (oracle jdeveloper's embedded server) for Jdeveloper 10g, version 10.1.2, on a Windows 2000 box.


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


Re: JSTL 1.0 problem with Bayern Ch 11 example...

Posted by Martin Cooper <mf...@gmail.com>.
On 8/3/05, Givler, Eric <eg...@state.pa.us> wrote:
> I'm having a heck of a time trying to get the Bayern example from chapter 11 working, and I'm really not sure why....
> 

It looks like there's a bug in your container. I just tried out your
code on Resin 3.0.14, and everything works as expected.

--
Martin Cooper


> I created an enterNumber.jsp page:
> 
> <%@ page contentType="text/html;charset=windows-1252"%>
> <html>
>   <head>
>     <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
>     <title>untitled</title>
>   </head>
>   <body>
>   <form action="parseNumberCarefully.jsp" method="post">
>   Enter your favorite number <input type="text" name="favorite"/>
>   <br/><input type="submit" name="submit" value="Submit"/>
>   </form>
>   </body>
> </html>
> 
> 
> I created an parseNumberCarefully.jsp page:
> 
> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
> <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
> 
> <html>
>   <head>
>     <title>parseNumberCarefully.jsp</title>
>   </head>
>   <body>
>     <p>You entered "<c:out value="${param.favorite}"/>"</p>
>     <c:catch var="parsingError">
>       <fmt:parseNumber var="fav" value="${param.favorite}"/>
>       <p>As far as I can tell, this corresponds to the number
>         <c:out value="${fav}"/>.
>       </p>
>       <p>If you multiply this number by 2 and add 1, you get
>         <c:out value="${fav * 2 + 1}"/>. I like that number better.
>       </p>
>     </c:catch>
>     <c:if test="${not empty parsingError}">
>        Sorry, this doesn&rsquo;t look like a number to me. Perhaps you&rsquo;re in the wrong country?
>     </c:if>
>   </body>
> </html>
> 
> 
> If I run the first page, enter a valid#, then click [submit], I get correct results.
> If I run the first page, enter an invalid # (i.e. abcd), then click [submit], I get correct results.
> However, if I enter an invalid#, click [back], then enter a valid number, I keep getting parse errors.  It's as if the <catch> keeps RECREATING the parsingError exception on subsequent requests even though the data has changed and is valid.
> 
> The reason I tried to do this simple example was that I was creating a multi-record entry form, and trying to validate with JSTL.  When I did this, as soon as the form would detect bad data, every record after it would be considered "invalid data".  In these cases, I'd end up either clearing the rest of the data, or it would retain the first "good data" and ovewrite all subsequent records, or I'd get a stack trace.  I thought all of the code that I was writing was "syntactically" correct, but it did not produce the results that I wanted.
> 
> If parseNumberCarefully.jsp has an errorPage attribute defined, and you remove the <c:catch> tag, and enter an invalid value, an error page is displayed. Now, if you hit [back] to goto the entry page, and enter a valid value, it works fine.
> 
> What am I missing?
> 
> I'd appreciate any assistance on this.
> 
> I'm running this against Oc4J (oracle jdeveloper's embedded server) for Jdeveloper 10g, version 10.1.2, on a Windows 2000 box.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
>

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