The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

JSP/JSTL question couldnt find answer anywhere else

I have a jsp jstl question.  It is actually kind of simple, but I still couldnt get an answer.  And it is more of a design question.

How do you do 'processing' or manipulation of a string value 'after' it has been processed through 'el' jstl?

"I am having trouble doing basic view manipulation on data output from the expression language. I dont 'think' I need custom tags for this, and dont think this logic should occur at the controller or model? But for example, if I want to modify a value before it is display to the user but after it has been evaluated: Ie."

This is my current approach.
Would it have been more logical to place:

"<jsp:useBean id="concatValue" class="org.spirit.servlet.bean.BotListConcatValue" />
<jsp:setProperty name="concatValue" property="maxLen" value="20" />"

Within the 'forEach' bracket?

Logic in the bean:

    public String getWord() {
        if (word != null && (word.length() > (maxLen + 3))) {
            word = word.substring(0, (maxLen - 1)) + "...";
        return word;

<jsp:useBean id="concatValue" class="org.spirit.servlet.bean.BotListConcatValue" />
<jsp:setProperty name="concatValue" property="maxLen" value="20" />
<c:forEach items="${linklistings}"
  var="listing" varStatus="status">
<c:set target="${concatValue}" property="word" value="${listing.urlTitle}"/>                                            
<c:out value="${concatValue.word}" />
Bot Berlin
Wednesday, January 03, 2007
jsp:setProperty is evil and very broken. If the value is blank it doesn't get set at all. I honestly would never use this tag. YMMV.
Wednesday, January 03, 2007
I would actually code getWord() as a custom tag.

I'm guessing you want a function that will take any string of arbituary length, and if it's more than the maxLength, it truncates the string to size and adds the trailing periods after it.

If I'm right, I can see potentially more uses for this function than strings generated by beans and retrived from properties. One possible situation - the user will add some lengthly text to a form and when you acknowledge the form has been submitted, you may want to quote back a small portion of the text.

If I'm wrong (which is quite likely), I admit to being suspicious of the way you're using c:set. I'm not familiar with JSTL but it doesn't appear to me that setting the word property to the URL title actually calls your getWord() function.
Wednesday, January 03, 2007
The custom tag sounds like a good idea. You could also wrap the list in a custom-list that provides the conditional string truncation/substitution you want. That's easy to unit test and it keeps your jsp cleaner. Massaging data to simplify the jsp/jstl seems a good design tradeoff to me.  Does someone have another perspective on that?
ted Send private email
Monday, January 22, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz