I have my validator which implements org.springframework.validation.Validator. When I use errors.rejectValue("myField", "myErrorcode") for some form if in my error code defined in language_it_IT.properties contains HTML entities like à, then it will display as à on html page not as à as I want. How I can achieve that?
Related
I am seeing a code in my project as
${'myproj.label' #i18n, format=[sighltyObj.field1], context='text'}
Intention is pass a variable into i18n text + encode the texts safely. Is this right to use display context along with i18n translations? When I tested with a field1 = "Hello%20World", it is NOT encoding the texts rather rendering as is.
How can I encode html strings while passing the arguments as variables into i18n?
HTL will not decode the text returned by format. I think the confusion comes from the documentation which states for the display context text the following:
Use this for simple HTML content - Encodes all HTML
(Source: HTL Specification Section 1.2.1 Display Context)
But this does not mean that this context decodes anything, it encodes HTML tags.
So if sighltyObj.field1 is Hello%20World it will not be rendered as Hello World but as Hello%20World as you already noticed.
The display context text will encode all HTML tags in the given text so that you can't "smuggle" them into a text (see code injection).
So for example:
${'<p>This is my text</p>' # context='text'}
will create the following HTML
<p>This is my text</p>
Note how the p tags were encoded:
<p> became <p> and </p> became </p>.
The getter for field1 in your sighltyObj will have to do the decoding so that Hello%20World becomes Hello World. There is already a answer on Stackoverflow that shows you how to do this: https://stackoverflow.com/a/6138183/190823
String result = java.net.URLDecoder.decode(url, "UTF-8");
Is there a way to use data-fancybox-type="iframe" with strict xhmtl at all so that it validates? I have everything working except for that error that I get.
Is there a way to write it so that it works with my current doctype?
Since the data-* attribute validates only with HTML5, you may prefer to use the fancybox special class to set the content type, so instead of this :
<a class="fancybox" data-fancybox-type="iframe" href="page.html">open</a>
... try :
<a class="fancybox fancybox.iframe" href="page.html">open</a>
... then your document will validate with your current DOCTYPE and it will have exactly the same effect.
I want to unescape html chars in Spring JSP.
<c:out value="${fn:***unescapeHtml***(item.name)}" />
Is there an unescapeHtml or equivalent ?
Since I did not find a jsp tag to do the same, I had to resort to javascript method. That makes sense to me as I used javascript to escape at the first place, and it works fine.
I have put this into the $.ready() of the page.
$.find(xxxx) {
$(this).text((unescape($(this).text())));
}
My graphic design requires all fields in HTML forms to be lowercase. Example:
<tr><th><label for="id_pressure_Hg">pressure Hg</label></th><td><input
id="id_pressure_Hg" type="text" name="pressure_Hg" /></td></tr>
Django forms, however, per default make my labels with capital first letter. Since I have a lot of fields and many forms are created from a model (through a modelform), the "label" attribute is not a viable solution.
Is there a way to modify the function which translates field names into field labels?
you can try this.
example..
in your forms.py
value = forms.CharField(label=u'', widget=forms.TextInput())
in your HTML file.
<ul>
<li>value Value : {{form.value}}</li>
</ul>
you can modify the form.value in your CSS or JQuery. i has this attribute as an input in html.. id=id_value and name=value
Using Spring 2.5 tag library,
I have an Integer value in a command form that's rendered on my page using <form:input path="budget" htmlEscape="true" />
When the value is > 999, it renders the number as value="x,xxx" on the page. My validation isn't expecting the comma and rejects the value.
Is there a fix for the rendering, or do I need to fix the validation and parsing?
As usual, I was just being blind, and discovered that there was a custom property editor bound to the command form in the controller. It was causing the input field to render with commas.
That would have been fine, if there also wasn't a JavaScript validation that rejected the field for having commas in it.