Pages

Wednesday, November 9, 2011

Working with s:bean in Struts 2 - Beware Begineers


Well well... this simple silly stuff gave me a head ache for a while. Because I broke the rules and so paid the price.
I was wondering why s:bean won’t work for me while I was able to work with other stuffs like controls, context params, stream processing, Ajax etc….
My Eclipse IDE kept telling that it was not able to recognize what s:bean is. Neither did it realize s:param and s:property.

I was puzzled. Even a few java guys felt that it was a problem with the IDE. How demoralizing. I stopped toying with it for a while and later after a couple of days, I found the culprit.

It was so simple. I got a bit comfortable with basic JSPs and Struts that I did not notice this.

The following was my jsp page’s content

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bean Tag Example</title>
</head>
<body>
<s:bean name="currencyConverter">
 <s:param name="dollars" value="100" />
 100 Dollars = <s:property value="rupees" /> Rupees
</s:bean>

</body>
</html>

And the issue was I did not add the following code to the top of that page

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

God bless me…. I just want to cry now. How could I ever forget to miss it … bummer

Hope this saves some one else at least :)

No comments:

Post a Comment