Monday, October 15, 2007

Paper submission

Just the time I'm trying to write a paper, I came across this. Just the same problem.
Hmmm interesting... :)



Ref: PHD Comics

Wednesday, June 13, 2007

Correction: JSTL and expression language problem

In my older post I wrote about problem in using JSTL.
For a summary, my problem is I kept seeing this error message:
According to TLD or attribute directive in tag file, attribute value does not accept any expressions

And I find out that problem occurs because I was using JSTL-1.0 in a JSP-2.0 environment. Details can be found here.

Lately, when working on my project and using JSTL again I come against a strange problem. I am trying to use <c:out value="${foo.bar}" /> and it simply prints ${foo.bar}.

After a quick inspection I found the source of the problem. Again I made mistake using auto-complete in IntelliJ ( sometimes i found this after error occurs, like this time:) ).
So using auto complete, i define core taglib definition like this:
<%@ taglib prefix="c" 
uri="http://java.sun.com/jsp/jstl/core"%>

This definition is for JSTL-1.1 and guess what I am using JSTL-1.1 jar and Servlet-2.3/JSP-1.2 web-app(due to some code-generation issues). So i fix this error by changing tld description like this:
<%@ taglib prefix="c" 
uri="http://java.sun.com/jstl/core"%>

In conclusion of my older post I state :

So here is the summary for all of my words:
  • Servlet 2.3/JSP 1.2 + JSTL 1.0 - OK
  • Servlet 2.3/JSP 1.2 + JSTL 1.1 - OK
  • Servlet 2.4/JSP 2.0 + JSTL 1.1 - OK
  • Servlet 2.4/JSP 2.0 + JSTL 1.0 - PROBLEM

If problem occurs first check web.xml and JSTL verisons.
Upgrade if you can (highly recommended), if you can't then use "c-rt.tld"

This is still true. BUT if you want to use Servlet 2.3/JSP 1.2 + JSTL 1.1 option, you should avoid using JSTL-1.1 tld definition.

Saturday, May 26, 2007

Usability

Veeeerry important and funny :))



ref: comic from Bokardo.com

Wednesday, April 18, 2007

Works on my machine

Love this certification program
If you have any problems in your group you can use this certification ;)

lol




reference 1: Joseph Cooney
reference 2: Jeff Atwood

Monday, April 16, 2007

JSTL and expression language problem

First let me give you a small introduction then I will talk about my problem :)

Small Introduction
I've been using JSTL in my projects partially quite some time (partially because of my company's internal taglib). JSTL is a useful tag library for JSPs. You can use expression language (EL) features easily, cause they save you writing a lot of code and they are really simple.

This is a simple example for creating a simple select input


<%@ page contentType="text/html;charset=UTF-8"
language="java" %>
<%@ taglib prefix="fmt"
uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c"
uri="http://java.sun.com/jstl/core" %>
<fmt:setbundle basename="com.foo.Application">

...

<select name="wfn">
<option value=""><fmt:message
key="form.select.choose"></option>
<c:forEach items="${workflows}" var="wf">
<c:set var="selected" value=""/>
<c:if test="${param.wfn==wf.name}">
<c:set var="selected" value="selected"/>
</c:if>
<option value="<c:out value="${wf.name}">"
<c:out value="${selected}"> >
<c:out value="${wf.label}">
</option>
</c:forEach>
</select>


There may be some other (and simple) ways for this routine but if you are not able to use some other [powerful] tag libraries this can save you from confusing scriptlets and provides easily understandable and maintainable code. In this example you can see iteration, flow control, assignment, output and internationalization features provided by standard tag library.

THE PROBLEM
After this small introduction let me tell you about my problem and a solution that I found about it.

Lately I've started to learn about Spring (and MVC). I will try to write about that in the future. Anyway, I've downloaded "spring-framework-1.2.9-with-dependencies" and start inspecting some tutorials. On my sample I use jars from the package I downloaded.

But when i try to use JSTL in pages I keep getting exception:
"According to TLD or attribute directive in tag file, attribute value does not accept any expressions"

After a small inspection i found the source of the problem. In c.tld file I found these lines:

...
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
...

When I change rtexprvalue to true it works. But I never encountered such problem (and web.xml file is defined by Servlet 2.4 descriptor:

<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
...

I mentioned that JSTL uses EL. When JSTL 1.0 released JSP technology(Sevlet 2.3/JSP 1.2) was not supporting EL. So JSTL handled EL by its own. When JSP 2.0 (Sevlet 2.4/JSP 2.0) technology came out, it is now supporting EL and starting from JSTL 1.1 it uses JSP support for EL. You can find these in specifications of both JSTL and JSP.

My IDE (IntelliJ) generated web.xml file and I don't copy it from tutorial. When I compare web.xml file from the tutorial and my sample (and my other projects) I found that they are all defined by Servlet 2.3.
When I use Servlet 2.3 my sample works. After small inspection I found out that I was using JSTL-1.0. Spring distribution comes with JSTL-1.0 and it isn't denoted on jar file. It simply says "standard.jar" not "standard-1.0" and I thought it was JSTL-1.1

That explains why comments like "If you want to use EL in JSPs you must define web.xml by 2.4 version". Since it is correct for using EL in JSPs it creates conflicts with JSTL-1.0. If you want to use JSTL-1.0 in this configuration you should use "c-rt.tld" file.

So here is the summary for all of my words:
  • Servlet 2.3/JSP 1.2 + JSTL 1.0 - OK
  • Servlet 2.3/JSP 1.2 + JSTL 1.1 - OK
  • Servlet 2.4/JSP 2.0 + JSTL 1.1 - OK
  • Servlet 2.4/JSP 2.0 + JSTL 1.0 - PROBLEM

If problem occurs first check web.xml and JSTL verisons.
Upgrade if you can (highly recommended), if you can't then use "c-rt.tld"

Note: if you want to use Servlet 2.3/JSP 1.2 + JSTL 1.1 option, you should avoid using JSTL-1.1 tld definition. Details are in here

I try to explain it as simple as I can.
Here are some links about JSTL:
- JSR 52 - place where you can download JSTL specifications
- JSR 152 - place where you can download JSP specification
- java.sun.com - you can find API and some documentation
- Jakarta Apache - Apache implementation of JSTL