Category: Web

couple of JSTL hints

How to implement if-else logic

<c:choose>
<c:when test="${pageControl.adCategory == 'health'}">
 ...
</c:when>
<c:when test="${pageControl.adCategory == 'travel'}">
 ...
</c:when>
<c:when test="${pageControl.adCategory == 'science'}">
 ...
</c:when>
<c:otherwise>
 ...
</c:otherwise>
</c:choose>

How to handle checkboxes in forms in Spring

<input type="checkbox" name="wantsEmail" id="signup-checkbox" value="true" <c:if test="${signupCredentials.wantsEmail == true}">checked</c:if> >

Tomcat stuck, no app is running, doesn’t show any log (catalina.out) messages either

This happened when I tried to restart a tomcat server.
While starting, catalina.out shows no messages related to the apps that should be loading.
Apps, as expected, don’t work either.
To get more information about what is going on, kill tomcat in a particular way:
While killing tomcat use:
kill -3 [pid]
This tells JVM to kill the process and dump the thread stack, which will show right in catalina.out.
In my case, this happened because I initialized a Spring bean which makes a request to another service, which was not running.
Service was not running, because it was being deployed on the same Tomcat server.
Deadlock occurred because my app was stuck waiting for the service app, which, probably, was down the line but never had a chance to start.

Absent Code attribute in method

I needed to include @RolesAllowed annotation into the project.
For that I’ve used the following IVY dependency:
<dependency org=”javax” name=”javaee-api” rev=”6.0″ conf=”compile->default”/>
This dependency basically provides interface to most of java ee components without implementation.
Hence, it is usually used to compile the project, because implementation is usually within the web container (eg. Tomcat).

However, the project used to fail with an error above whenever I ran ant test task.
Mock of HttpServletRequest object was failing. My guess is that reflection was trying to go deeper into actual implementation which dependency above does not provide.

It was even harder to spot, because IDE was running all tests just fine. Probably, because classes were loaded in a different order in IDE and in ANT.
JVM grabs whichever class is loaded first and ignores the next one, hence error did not show in IDE.
IDE was loading full implementation, while ANT was loading interface (dependency above) first.

Getting a smaller jar file that contains implementation of javax.annotation.security package helped solve the problem.
<dependency org=”javax.annotation” name=”jsr250-api” rev=”1.0″ conf=”compile->default”/>

Good times!

Java frameworks popularity trends

I couldn’t compare words such as Struts and Spring, because they are used very extensively in other contexts as well.

Hence, I used, as a common denominator, word JAVA. Which might under-estimate the frequency of such words as GWT, because it is not usually used together with “Java” word.  Nevertheless, we can see the trends, at least the growth rates.

java jsf, java spring, java struts, java gwt, java ejb

Things to notice:

– Spring is steady, and seems to be the most popular so far

– Struts is dying

– JSF started very well, but seems to be steady now (still not as popular as Struts though)

– GWT is not mainstream, but again it is hard to say anything for sure

Raphael JS framework

Really, really, really NEAT thingie! Planning to implement a new project using Raphael, it seems to fit it nice.

However, researching it was a little troublesome, because it’s a new framework and there are some JS alternatives already. Comparison of SVG and Canvas gets a little confusing at first. Presentation podcast from the author, Baranovskiy, was quite convincing though. And I like his attitude… 🙂

We already managed to implement resizing and rotation (think: trigonometry & tangents) using mouse events, which was not very hard. This is gonna be my first BIG and serious JS work, which, I guess, will require a lot of optimization (which I “pervertedly” seem to enjoy somehow 🙂 ).

If setting charset using meta tag doesn’t seem to work

Been busy those days. But when I came across this problem I couldn’t resist not writing about it because I definitely had it before but always left unresolved … now, finally I know how to solve it 🙂

1. If your file encoding is definitely UTF-8

2. If you definitely have the right version of META tag, that is: <meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″> (note that you don’t necessarily need to close this tag… )

3. If browser still shows page in some encoding but not UTF-8 (by checking in View->Character Encoding menu in a browser)

It means there is only 1 place left to look for, it’s in WebServer 🙂

Solution is simple, while page is being served WebServer, apparently, notifies web browser about what is coming in page headers (you can check it using Firebug)… and in my case it was windows-1251 (Russian). Hence, you will need to modify what your WebServer sends in headers.There are 2 solutions for this:

1. Change settings of your WebServer

2. Change the charset of the page dynamically when it is being served (which is more viable, because usually we don’t have access to the WebServer settings…. or we don’t want to change those settings not to break something else)

Ex: In PHP this is done using “header” function (this should be called before anything else) as follows:

<?php header(‘Content-type: text/html; charset=utf-8’);?>

About layering DIVs and IMGs

Recently I was making a JS slideshow and because requirements were unusual using a third party slideshow was not an option.

Images were supposed to be rendered in a particular fixed width and length (even if they do not actually fit proportionally, well that’s what client wants… ). Being lazy (and because client did not ask for performance), I just resized images “in-browser”.

I had to create a function that renders it right (without loosing quality) both in IE and other browsers. Old IE (dough! as usually… ) don’t support automatic ALPHA image rendering (basically that’s smoothening when image is resized), so I had to manually forcefully do it in the function.

But that was an easy part!

Apparently, in IE, when resized images and DIVs are used together as layers (z-index), positioning (TOP, TOP-MARGIN etc…) starts behaving VERY weird. I guess that’s because even if image is resized, it’s pixels are still treated as actual pixels (those before resizing). So style TOP:-50px; might actually be a proportion of resized image, hence less than 50.

Well good thing is that there is a solution! Tadaah! 🙂

Use all your DIV elements first, and IMG at the end. Thus, even if your DIV elements are at the bottom, place them first in the code and then just move them DOWN (which will require to lift an IMG element up). The strange thing is that moving IMG element up (as well as moving DIV element down ) does not cause any problems.

Automating Office Applications on the Server Side

If the aim of the automation is to use a predefined template, then it is not a good idea.
Read article from microsoft:
http://support.microsoft.com/kb/257757/en-us

Hence, ASP.NET code used on the server side sometimes fails to execute due to internal “Interop” reasons.
Also, important to note that during debugging code works OK.
The problem arises only when website is published on the IIS.
Same occurs for both Vista and Windows Server 2003.

The workaround is to call EXE windows forms application from ASP.NET code and then use the file generated by EXE.