Fog Creek Software
Discussion Board




Anyone Here Used Jakarta Struts?

I'm trying to use the <bean:message> tag to lookup the text for the title attribute of an HTML hyperlink, e.g:

<html:link action="/Upload.do" title="<bean:message key='app.upload' />">Upload</html:link>

However the title is set to the literal string "<bean:message key='app.upload' />". I've tried using single quotes instead or leaving them out entirely but nothing seems to work! How do you nest tags like this?

Struts Newbie
Wednesday, June 18, 2003

P.S. Haven't been able to find any answers by RTFM! :-(

Struts Newbie
Wednesday, June 18, 2003

You can't call a custom tag in a parameter to another custom tag.

I don't remember the details, but I believe there's a Messages bean that gets put in the session that you can use to pull "app.ulpoad" from your resource bundle.

igor
Wednesday, June 18, 2003

Igor's right, you can't call a custom tag in a parameter to another custom tag.

What I usually do in this case is get the value I want into a string, typically by using a scriptlet unfortunately, a bit like:

<%
    String somevalue = "goats";
%>

then referring to it like:

<tag value="<%=somevalue%>">

where somevalue is my string I have defined earlier.  There may be another way to do this.  If you define a bean inline into your jsp like:

<bean:define id="myValue" >
    <bean:message key="app.upload"/>
</bean:define>


Then you'd want to refer to it elsewhere like this:

<html:link action="/Upload.do" title="<%=myValue%>">Upload</html:link>

This may work.  I'd be interested to see the results.

Konrad
Wednesday, June 18, 2003

Thanks a lot, I'll give it a go.

Struts Newbie
Wednesday, June 18, 2003

You should really be using the JSTL 'fmt' tag library instead :-)

I'm not a great fan of the struts tag library (or indeed struts altogether, but thats another story.) I prefer traditional HTML markup, with the JSTL providing data.

Rhys Keepence
Wednesday, June 18, 2003

I don't really like the Struts tag library either. In fact, the more I'm using the Struts, the less I'm liking it! It's a bit clunky.

I haven't used it, but Tapestry looks promising. See http://jakarta.apache.org/tapestry

Struts Newbie
Thursday, June 19, 2003

Konrad,

For the record, the inline bean approach does work. Thanks.

Struts Newbie
Thursday, June 19, 2003

Cool, I'm glad it works.

I agree about the tag library, I've varied from thinking it was neat to think it requires contortions and then back again.  I can't remember how long I've been using struts, probably 6 months to 9 months, and for me it had quite a steep learning curve.  I think many of the problems on the struts mailing lists can be laid at the door of the tags, and their sometimes inconsistent parameters.  There's a couple of real gotchas I've found in there - I can't remember a specific example but the tag looks and smells like it will take its data from a form bean (name=, property=), but as I remember the semantics of name are completely different.

However it's a great step up from plain JSP and for that I'm grateful.  To be honest I'm a little worried that sooner or later I'll find something (such as Tapestry) that will make so much sense, and I'll have this big struts codebase...  ah well, them the breaks.

Konrad
Thursday, June 19, 2003

For Russian speackers - there's a good overview
of Java technologies in web development.
Struts, Tapestry and JSF are discussed

http://www.prefnews.ru/articles/javawebdev/

Evgeny Goldin
Thursday, June 19, 2003

I started with struts, but am now a big proponent of tapestry. It takes a while to get used to, but the payoff is worth it.

Matt Christensen
Friday, June 20, 2003

*  Recent Topics

*  Fog Creek Home