If any body else have solution on this please replay.
I'm using Struts2 and getText method to fill i18n and text tags.
For example I use:
free.text.search.label=české On-line Hledat
č is a HTML code for special character č (Czech Republic). I want to use in properties file.
But in my JSP, I get : české On-line Hledat instead of české On-line Hledat
I use this to display text on my JSP:
<s:label for="searchInput" value="%{getText('free.text.search.label')}" />
So what's the error? Actually this problem i am facing for label as well for button.
Use \u010D instead of č
.properties
free.text.search.label=\u010Deské On-line Hledat
.jsp
<s:label key="free.text.search.label" />
Output
české On-line Hledat
How I solved it?
Just paste české On-line Hledat into .properties file in my IDE (Eclipse).
Or
See
Unicode Character 'LATIN SMALL LETTER C WITH CARON'
(Encodings > C/C++/Java source code)
A to Z Index of Unicode Characters
Unicode Character Search
Well i am not able to understand your issue properly
but few points i would like to mention here
<s:label for="searchInput" value="%{getText('free.text.search.label')}" />
use key in place of this to make this more easy to read and maintain
like
<s:label for="searchInput" key="free.text.search.label" />
also since meta tags are no longer applicable to struts2 so you can try using this
<%# page contentType="text/html;charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags" %>
May be this will help you to display special characters correctly
Related
Using spring form, we display an input like this:
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
...
<form:input type="text" cssClass="w50" path="lastName" cssErrorClass="w50 error" placeholder="${msgLastName}" />
Sometimes, the users lastname value may content single quote, eg "Job's". This probkem is that we clean the lastname with the OWASP HTML Project, which causes the lastname to be
Job's
When the input is displayed into the browser, the ascii value is also displayed - whici is bad. I would like to display simply "Job's" into the input.
I tested with a simple JSP input, eg.
<input type="text" cssClass="w50" value="${myobject.lastName}" cssErrorClass="w50 error" placeholder="${msgLastName}" />
In this case, the rendering is fine.
My conclusion is that the problem comes from spring, but how to avoid it?
Finally found the answer.
Spring HTML-escapes the values, it doesn't really output
Job's
but
Job's
As there is an HTML character, it isn't parsed as ascii.
Using Chrome, if I inspect the DOM I cannot see the
&
but if I "edit as HTML" then I see it.
I have a property file without Key and only content and I want to display the content of property file in jsp Page after escaping html tags. How to do this?
property file:
Here is an example of content, messages. <p>
<b>approach<b> <br>
Find out more about our website
</p>
How can I display this in jsp Page using spring? Any help?
message.properties is typically used for internationalization. Usually properties file in general is used for small value(s) and plain text.
For your case, I'd just create a separate jsp file and include it in your jsp.
<%# include file="aboutus.jsp" %>
I have recently started to integrate datatables in my spring mvc 4 + hibernate 4 + tiles 3 Project.
I want it to display header with various language support.
So I started with this link.
As per this page suggests my header shows ???key??? message.
I want to display Id in column header but it is showing ???table.header.id???.
This link says
If the key cannot be found in the bundle, the ???key??? message will be displayed in the column header.
But I have put following in datatables.properties
i18n.locale.resolver=com.github.dandelion.datatables.extras.spring3.i18n.SpringLocaleResolver
global.i18n.message.resolver=com.github.dandelion.datatables.extras.spring3.i18n.SpringMessageResolver
Also have put in global_en.properties
table.header.id=Id
I also copied same file as global.properties.. but not worked.
My jsp file contains
<datatables:table id="users" ...>
<datatables:column titleKey="table.header.id" property="userId" />
<datatables:table />
My Resource folder structure is
Where should I put table.header.id=Id??
Any help is required. Thanks in advance.
Note: I am using AJAX source + server-side processing.
About the location of your messages
You seem to be using the Spring ResourceBundleMessageSource with global as a basename. So it makes sense to put all translations of header columns in global_*.properties files.
About the ???key??? message
It turns out to be a bug introduced in the v0.10.0.
Waiting for the next version to be released, there is a workaround, but working only with DOM sources.
Here follows the steps.
1) Instead of using the titleKey column attribute, you will use the <spring:message> tag. Theorically, they do the exact same thing: lookup a resource in your configured resource bundle.
Begin by declaring the Spring taglib in your JSP:
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
2) Then you need to update the usage of the Dandelion-Datatables taglib. As a workaround, you can use the <datatables:columnHead> (docs here) tag to insert any content in a column header.
Just use it as follows:
<datatables:table id="users" ... row="user" >
...
<datatables:column>
<%-- Everything inside this tag will only appear in the header column --%>
<datatables:columnHead>
<spring:message code="table.header.id" /> <== this will appear in the column header only
</datatables:columnHead>
<%-- Everything else will appear in all cells --%>
<c:out value="${person.id}" /> <== this will appear in all column cells
</datatables:column>
...
<datatables:table />
Some observations:
You need to add the row table attribute if you need to access the object of the collection being iterated on, as it's done with the <c:out> tag of the JSTL
You need to remove the property column attribute, or the content of the <datatables:column> tag will not be evaluated
This is a lot of work for very little return - sorry for that - but waiting for the next version to be released, at least it works.
A new issue has been added.
If you are using AJAX source + server-side processing.
Make a variable first
<spring:message code="table.header.id" var="titleId" />
and added it in
<datatables:column title="${titleId}" property="userId" />
Also a fix is available here. Kindly upgrade to 0.10.1-SNAPSHOT version.
(Disclaimer required by StackOverflow: I'm the author of Dandelion)
I am refactoring an existing web app to use struts tags instead of scriptlets. One of the things occurring multiple tiems is the conditional check like
<%if ("true".equals(requset.getparameter("someParam"))) {%>
some html, javascript
<%else{%>
some other html,javascript
<%}%>
I wish to replace this with struts logic tag to replace scriptlets. Is it possible to do it without storing someParam inside a formbean? By default, it seems the syntax of logic tag works only with formbean parameters.
While not a struts-specific solution: have you thought about using JSTL custom tags? The tags are included in the latest web container specifications and can be easily added older web containers which do not include the JSTL specification by default.
Here is a solution based on JSTL:
<%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
...
<c:choose>
<c:when test="${param.someParam eq 'true'}">
some html, javascript
</c:when>
<c:otherwise>
some other html, javascript
</c:otherwise>
</c:choose>
Unless you are using the struts custom tags to generate your UI components, it is always preferred to use the JSTL standard tags whenever possible. However, if you are set on using struts, here is an example with Struts 1:
<bean:parameter id="paramValue" name="someParam" />
<logic:equal name="paramValue" value="true">
some html, javascript
</logic:equal>
<logic:notEqual name="paramValue" value="true">
some other html, javascript
</logic:notEqual>
You will note that this solution takes the request parameter and puts into into a page scoped attribute (paramValue) that can then be accessed by the struts logic custom tag.
I have seen several examples using
<a href="<spring:url value='/about/' />" >About </a>
I try this and get an error from Jetty
Caused by: org.apache.jasper.JasperException: /WEB-INF/views/footer.jspx(6,22) The value of attribute "href" associated with an element type "null" must not contain the '<' character.
Is there some encoding setting I have overlooked?
This is unfortunate because the other examples of using spring url I have seen are ugly
<spring:url value='/about' var="about_url" />
About MyFit
Do I really need an additional line for every hyperlink in my templates?
Is this something that is fairly trivial and I have overlooked?
You have a .jspx file, which must be a well-formed XML document. In .jsp files it would work fine.