I'm trying to fill select element with . List has three items with one of them is json data. When gsp page is rendreded this is what is in html:
<option a":"aa11","b":"bb33","cc":"cc44"}"="" value="{">label </option>
Is this a bug in Grails 2.0.4 ?
You should escape HTML characters in optionKey
Example :
<g:select optionKey="id" optionKey="${{it.toString().encodeAsHTML()}}" name="book.title" from="${bookList}" />
Related
I have an application that uses Spring MVC, before sending the response to the view (JSP) it adds an item to the spring model (org.springframework.ui.ModelMap), let's say the name of that item is element1 and the value is: <b>This</b> is an <br/> example
In the JSP, using a) and b) produce different results
a) <c:out value="${'<b>This</b> is an <br/> example'}" escapeXml="false"/>
b) <c:out value="${element1}" escapeXml="false"/>
a) produces
b) produces
I have been wrapping my head around this, I do not see any difference, except that b) uses a variable and a) uses the value but in both cases I am using the same tag (c:out) with the same value for the escapeXml attribute (false).
Any help will be greatly appreciated.
I am new to Vue.js and I am currently trying to figure out how to maintain whitespaces in the options of my HTML "select" drop-down. I am using v-for to populate the list like this:
<option
v-for="category in displayCategories"
:key="category">
{{ category }}
</option>
And the list items look like this (in a string array):
`SECTOR`,
` Food and Drink`,
` Education`,
` Transport`
Currently, something seems to be trimming out the space characters. I'm not sure if the problem lies with Vue or HTML...
Thanks for your time,
Josh
I have created a drop down where I want either blank, ® , or ™ to be inserted into my db field.
<select name="copyright_symbol" id="copyright_symbol">
<option value='' {if !isset($product->copyright_symbol or $product->copyright_symbol == '')}selected="selected"{/if} >{l s='None'}</option>
<option value='®' {if $product->copyright_symbol == '®' }selected="selected"{/if} >{l s="reg"}</option>
<option value='™' {if $product->copyright_symbol == '™' }selected="selected"{/if} >{l s="trade"}</option>
</select>
This automatically converts my value to the symbol ® or ™. I dont want to save the symbol, I want the literal characters in the database. Any thoughts on escaping the html entity? Thanks
If a character has special meaning in HTML and you want it to be treated as data instead of having that special meaning then you represent it as an entity.
So if you want & to mean an ampersand instead of start of an entity, then represent it as an entity: &
value='®'
I am trying to render this string:
"<p>bold: <i>test</i> food <b>journal</b> entry</p>"
using jstl like these:
1) <c:out value="${topic.text}" escapeXml="true"/>
2) <c:out value="${topic.text}" escapeXml="false"/>
3) ${topic.text}
None of these work as expected. I want the text to be shown as html. However the results are (as printed on the browser):
1) <p>bold: <i>test</i> food <b>journal</b> entry</p>
2) bold: test food journal entry
3) bold: test food journal entry
How can I get:
test food journal entry
The last one you have ${topic.text} will output the raw string exactly as it is with no escaping, if that one isn't working the string is probably not what you think it is. Is there a chance that something is modifying the string such as the getText getter?
Use this.
<c:set var="str" value="<p>bold: <i>test</i> food <b>journal</b> entry</p>" />
<c:set var="str1">${str}</c:set>
${str1}
How can I display my list in a TestArea line after line with no additional spaces. i.e:
this
that
the
other
Here is my attempt:
<div class="text">
<label for="output_string">Output:</label> `
<textarea rows="10" cols="20">
<c:forEach var="x" items="${messagelist}">${x}</c:forEach>
</textarea>
</div>
Here's a guess (which I'll try out in just a sec in one of my own pages):
<c:forEach var='x' items='${messagelist}'><c:out value='${x}\r\n'/></c:forEach>
edit — no that doesn't seem to work at all. However, what did work was for me to add a message catalog entry like this:
linebreak={0}\r\n
Then you can use <fmt:message key="linebreak"><fmt:param value="${x}"/></fmt:message> to produce the string terminated by line breaks.
Note that JSP will put spaces before the first entry according to the indentation in your .jsp source file before the <c:forEach>, so you'll have to line everything up at the left edge if you don't want that.
If I had to do this a lot, I'd write an EL add-on function of my own to echo back a string followed by CRLF.
edit — If you want to write an EL add-on, you need two things:
The function itself, which should be a public static method of some class. I keep a class around called "ELFunctions" for most of mine. You can arrange them any way you want.
A ".tld" file, if you don't already have one. It should end up in your webapp somewhere under "WEB-INF". Mine goes in a subdirectory called "tld", but you can put it anywhere.
So you would write a little function like this, in some class:
public static String linebreak(final String msg) {
return msg + "\r\n";
}
Then your ".tld" file would look like this (assuming it's the only thing you've got; if you have an existing ".tld" file just add the clause):
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<description>Your Favorite Description</description>
<display-name>Make Something Up</display-name>
<tlib-version>4.0</tlib-version>
<short-name>whatever</short-name>
<uri>http://yourdomain.com/tld/whatever</uri>
<function>
<description>
Return a string augmented with trailing line break (CR - LF pair)
</description>
<name>linebreak</name>
<function-class>your.package.name.YourClass</function-class>
<function-signature>
java.lang.String linebreak(java.lang.String)
</function-signature>
</function>
(Boy, XML is so annoying.) Now somewhere you probably already have a little file that pulls in taglibs for your pages (for <c:...> tags at least). In there, or at the top of any page, add a line like this:
<%# taglib prefix="whatever" uri='http://yourdomain.com/tld/tango' %>
I think that the JSP runtime searches for ".tld" files by looking through the WEB-INF subtree, and in .jar files in WEB-INF/lib, matching by that "uri" string. Anyway, once you've done that, in your JSP file you can say:
<c:forEach var='x' items='${messagelist}'>${whatever:linebreak(x)}</c:forEach>
and it'll invoke your function.
<c:set var="xv"></c:set>
<c:forEach items="${messagelist}" var="x">
<c:if test="${not empty x}">
<c:choose>
<c:when test="${idx.first}"><c:set var="xv" value="${x}"></c:set></c:when>
<c:otherwise><c:set var="xv" value="${xv},${x}"></c:set></c:otherwise>
</c:choose>
</c:if>
</c:forEach>
<textarea cols="45" rows="5">${xv}</textarea>