Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring is eating </textarea> tags

In my web application (my first with Java, Spring, OR Roo), I'm building a form that has nothing to do with any JPA objects, it's just a form. I really don't want to use JSTL to build my forms here, because there's no data backing for them at this point. I'm using tiles to assemble the pages, so the guts of this form comes from a view, but apart from that there's nothing JSPish about it; it's just a form.

Inside that form, I have a text area that I've written:

<textarea id="whatever" name="whatever"></textarea>

When that comes to the screen, the </textarea> tag is gone. Different browsers deal with that differently, up to and including swallowing up the whole rest of the body HTML inside the text area field.

So I tried putting some content inside that textarea. Spaces and line breaks don't change its behavior, but it appears that any non-space character does. If I go

<textarea>.</textarea>

... it respects my close textarea tag. But then of course my text area renders on the screen with a dot in it, which isn't what I want.

Is this a known issue? Am I doing something wrong?

EDIT: @bozho: Here's a pertinent chunk of my jsp:

<div id="notes" class="detailPanel">
    <div class="panelLabel">Notes</div>
    <table >
    <thead><tr><th>Date</th><th>By</th><th>Note</th></tr></thead>
    <tbody id="notesBody"></tbody>
    </table>
    <textarea id="newNote" rows="5" cols="80" >.</textarea>
    <button id="addNewNote" onClick="saveNote();">Add New Note</button>
</div>

Absolutely nothing fancy going on here (I populate the tbody with rows on the client, is why that's empty). Without the dot in the third-to-last line, the closing textarea tag does not come out in the resulting HTML.

EDIT2 (Solution):

This URL became googlable after hearing some key words from people responding here: http://www.jroller.com/komu/entry/textareas_with_jspx

Turns out that when jspx pages are parsed, empty tags are collapsed into a single self-closing tag, which breaks text areas. The solution is to put an empty jsp:text in the middle:

<textarea><jsp:text /></textarea>

(Which is STAGGERINGLY stupid, but there it is.)

like image 863
Dan Ray Avatar asked Oct 20 '11 12:10

Dan Ray


1 Answers

You are using jspx files right? In general jspx remove something (or in your case it shorten it: check this: I expect that it addes a slash to the former opening tag, so it becomes: <textarea id="whatever" name="whatever"/> ) where it belives that is not needed. What exactly depends ona bit on the implementation.

So put a <jsp:text> tag in the text area tag to prevent it from "closing"

<jsp:text>
    <textarea id="whatever" name="whatever"></textarea>
</jsp:text>

<textarea id="whatever" name="whatever"><jsp:text /></textarea>

for an more complex example have a look at this answer: websphere 7 (and Spring Roo) incompatible with javax.el.ELException

like image 134
Ralph Avatar answered Nov 13 '22 04:11

Ralph