struts2 i18n java properties, how to escape characters? - java

I don't know how to escape ' in a java properties file. I'm using struts2 and getText function to fill i18n and text tags.
For example I use:
config.users.title= taula d'usuaris ---> config.users.title= taula d\'usuaris
But in my JSP, I get : taula dusuaris.
I use this to display text on my JSP:
<label for="title"><s:text name="config.users.title" />:</label>
Also I sometimes I use:
<s:select id="categories" name="categories" headerKey=""
headerValue="%{getText('map.categories.all')}"
list="categories" listKey="id" listValue="name"/>
What's the error?
Thanks!

Thanks lucentmind and BalusC foryour repliees
the solution was this: on my properties file I quoted ' as \'' and works fine.
**taula d \''usuaris**
Thanks

try to use double quote as escape character to show single quote on HTML page.
so you can mention value in propertis file like this : taula d "\'"usuaris

Related

Replacing a word with trademark in JSP

I am displaying data from my oracle database onto my JSP page. Requirement is to locate “PEFC” text, remove PEFC and replace with: PEFC™
I am able to replace the word in JSTL but don't know how to put TM at the end. Here is what I have done so far which is not working
<c:out value="${fn:replace(pageScope.searchResultDisplay.productGroup.name,'PEFC','PEFC'+ ™)}" ></c:out>
I am able to resolve the issue by putting
escapeXml="false"
at the end.

How we can get java object value( url ) in Thymeleaf conditional operator?

I want to put one condition in thymeleaf, If my object contain url so i want to print anchor tag with Url so i can open it and if not, then a message should be display.
<span th:utext="${#strings.contains({resultModel.results},'s3')} ? '<a target="_blank" href="${resultModel.results}" >URL</a>' : ${resultModel.results}"></span>
I want to get URL as a java object in href. Please suggest href="${resultModel.results}"
If i use href="http://google.co.in" so it is working but while using href="${resultModel.results}" i am not getting value.
Note: In Above html code else condition is working and getting message as a results.
I wouldn't try and combine that logic... Avoid putting html in html by just splitting the tags out the inner html into its own tags.
<th:block th:with="condition=${#strings.contains(resultModel.results, 's3')}">
<a th:if="${condition}" target="blank" th:href="${resultModel.results}">URL</a>
<span th:unless="${condition}" th:text="${resultModel.results}" />
</th:block>

Storing html file in a String in java

I am sending emails using amazon java sdk. I have to send html template as mail. I have written a program for this and it is working fine. But now I am storing the whole html code in a single String. But whenever i need to edit the template, I have to edit the program (I mean the String variable). And also I have to take care the special characters like " \ ...etc in that html code. Please suggest me an elegant way to solve this issue.
Use a template engine for that and store your template externally either in class path or on a file system. Here is a question that may help you selecting one: https://stackoverflow.com/questions/2381619/best-template-engine-in-java
Use Apache Common Lang api's StringEscapeUtils#escapeHtml, It escapes the characters in a String using HTML entities and return a new escaped String, null if null string input.
For example:
"US" & "UK"
becomes:
"US" & "UK".
Check the Apache Velocity Project. You can create template for several things. From it's user-guide page
Velocity can be used to generate web pages, SQL, PostScript and other output from templates. It
can be used either as a standalone utility for generating source code and reports, or as an
integrated component of other systems.
You can use a VTL(Velocity Template Language) . A example from above link
<HTML>
<BODY>
Hello $customer.Name!
<table>
#foreach( $mud in $mudsOnSpecial )
#if ( $customer.hasPurchased($mud) )
<tr>
<td>
$flogger.getPromo( $mud )
</td>
</tr>
#end
#end
</table>
Better and easiest way is reading the html file line by line using simple file reading operation and append this each line to a single String. And also I found this solution (also a better one, if you are ready to add one more library file to your project) from SO.

Escape characters in JQuery containing Java Codes

I'm working with JSP pages, and I need to append some HTML and Java codes inside a DIV, I only remember that I should escape " like this \", but I don't know about the other characters and I don't know if all non-letter characters should be escaped, here is the String.
String s ="<% ResultSet joinedRooms = myJavaDB.updateJoinedRooms(loginBean.getId());
while(joinedRooms.next()){%> <div id="<%=joinedRooms.getString(1)%>" class="chatRoom">
<div class="chatRoomName"><%=myJavaDB.getRoomName(joinedRooms.getInt(1))%></div></div><% } %>"
No need to roll your own, take a look at Apache Commons StringEscapeUtils.

Disable Struts converting HTML tags into entities

Hi I'm using Struts 1.2 and I installed TinyMCE. The problem is that struts is converting all HTML tags into entities. How do I disable or configure this to allow only selected tags?
Use the filter parameter (taglib).
<bean:write name="someField" filter="false"/>
Thanks, I was looking for this but in Struts 2, and this helped, it's similar:
<s:property value="variable" escape="false" />
I don't think that is a correct response for struts 2. At least on the later versions
escape property does not exist.
There are escapes for html, csv , javascript and xml which needs to be explicitly mentioned.
example for html, it has to be escapeHtml
<s:property value="%{somefield}" escapeHtml="false"/>

Categories