Proccess HTML tags to Spring MVC View -


i'm struggling following problem. in spring web application have different content types (e.g. text, images or code). depending on content type need display in different ways:

text: <p>some text</p>

image: <img src="path/to/my.img" />

code <pre>some code</pre>

the html tags should concatened actual content. problem is, if build output text in java class, html tags won't resolved in view, <p>some text</p> displayed.

is somehow possible html tags can resolved in view?

if it's escaping part problem, use:

<c:out value="${model.snippets.html12}" escapexml="false" /> 

(i assuming html string in model.snippets.html12).

of course, whole idea bad. not affiliated mvc police, point of using mvc framework if feel it's idea generate html inside controller , pass it, string - view? point of view it's bit of schizophrenia.

you can save lot of sanity rendering whole thing in switch, inside template. mean like:

  <c:choose>    <c:when test="${thing.type == 'code'}">      <div> code: ${thing.content} </div>   </c:when>    <c:when test="${thing.type == 'image'}">      <img src="${thing.src}" alt="${thing.whatever}" />   </c:when>     <!-- other choices -->     </c:choose> 

even better, create simple tag file let reuse logic anywhere need it.

or ditch mvc - honest.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -