You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mark Allan <ma...@ed.ac.uk> on 2010/03/23 13:07:49 UTC
Problem with HTML entities and OutputRaw
Hi all,
I'm developing a site which will be available in two different
languages - English and Gaelic. I've localised the pages and can
change easily between the two different versions, however, many terms
in Gaelic include diacritic marks on some of the characters, for
example the word for 'song' translates as 'òran'.
When the string I want to display comes directly from a field in my
Solr database, I don't have any problems and the accented character is
displayed correctly on the page. The problem comes when I need to
hard-code the string into a Java file and then display that string in
my Tapestry 5 template.
I know I can use the OutputRaw element, and most of the time it works
fine, but I can't use that inside an alt tag for my images.
Consider the following snippets.
Results.java:
....
String genreGD = "Òran"; //genreGD will change depending on the
English version pulled from the database
return genreGD;
....
Results.tml:
....
<img src="/images/${thisResult.genre}.jpg" alt="${thisResult.genreGD}
icon" title="${thisResult.genreGD}" />
....
When I hover the mouse over the image or view page source, I get two
unknown characters where the 'O grave' should be, implying some
character set encoding problem somewhere.
My Java file and template file are UTF-8 and the template declares
itself as such. The browsers I've tested (Safari, FF, IE) all detect
the correct encoding.
If I set the genreGD string in my java file to "Òran", then the
entity is carried over entirely and presented to the user exactly like
that - ie the ampersand, entity name and semicolon appear to the user.
Changing
alt="${thisResult.genreGD} icon"
to
alt="<t:outputraw value='thisResult.genreGD' /> icon"
won't work because you can't nest elements/components.
So, I'm stuck! Can anyone suggest a way out please? Adding a Gaelic
genre field to the database isn't an option and wouldn't solve the
real problem anyway. Essentially I think all I want to do is stop the
ampersand from being HTML encoded during the display phase. Can that
be done?
Many thanks for your help.
Cheers,
Mark
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 29 Mar 2010 12:26:46 -0300, Andreas Andreou <an...@di.uoa.gr>
wrote:
> @Thiago of course it's possible to work this way. But i've found than
> when switching OS, IDEs / editors and VCS all the time, it's just
> simpler + safer to keep
> such strings out of java source
I agree with you. :) I was just saying that Tapestry works with accented
characters in Java classes, even this not being the recommended way of
handling string content.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Mark Allan <ma...@ed.ac.uk>.
On 29 Mar 2010, at 4:29 pm, Mark Allan wrote:
> On 29 Mar 2010, at 4:26 pm, Andreas Andreou wrote:
>
>> Are you using the the encoding flag of javac ?
>
> I'll have a look. Right now, I'm just using mvn compile so will try
> and find out what flags it passes to javac.
OK, I've done the following and I still can't get this to do the right
thing.
My java files are definitely UTF-8 (no BOM) - I've been through all 47
source files to make sure each and every one is correct.
My Tapestry templates are UTF-8 and each has the following declaration
at the top:
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
As per http://maven.apache.org/general.html the snippets from my
pom.xml file are:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0
">
....
<build>
<finalName>TAD</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<optimize>true</optimize>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
....
</plugins>
</build>
....
<properties>
<!-- <tapestry-release-version>5.0.17</tapestry-release-
version> -->
<tapestry-release-version>5.1.0.5</tapestry-release-version>
<project.build.sourceEncoding>UTF-8</
project.build.sourceEncoding>
</properties>
</project>
In my ~/.profile I have
MAVEN_OPTS="-Dfile.encoding=ISO-8859-1"
I also tried
MAVEN_OPTS="-Dfile.encoding=UTF-8"
Whenever I changed the .profile, I logged out and back in again (just
an SSH connection), and each time I made any other change, I was
careful to issue 'mvn clean && mvn compile' before issuing 'mvn
jetty:run'.
No matter what I try, I can't seem to get tapestry (or maven - I'm not
sure which I've configured wrongly) to use the correct character
encoding.
Cheers
Mark
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Mark Allan <ma...@ed.ac.uk>.
On 29 Mar 2010, at 4:26 pm, Andreas Andreou wrote:
> Are you using the the encoding flag of javac ?
I'll have a look. Right now, I'm just using mvn compile so will try
and find out what flags it passes to javac.
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Andreas Andreou <an...@di.uoa.gr>.
Are you using the the encoding flag of javac ?
@Thiago of course it's possible to work this way. But i've found than
when switching OS,
IDEs / editors and VCS all the time, it's just simpler + safer to keep
such strings out
of java source
On Mon, Mar 29, 2010 at 16:28, Mark Allan <ma...@ed.ac.uk> wrote:
>
> On 29 Mar 2010, at 2:21 pm, Thiago H. de Paula Figueiredo wrote:
>
>> On Mon, 29 Mar 2010 09:32:05 -0300, Andreas Andreou <an...@di.uoa.gr>
>> wrote:
>>
>>> I've been bitten a few times in the past by having such strings in the
>>> java files
>>
>> My first language is Portuguese, which has a lot of accented characters,
>> and I don't have this problem. But there's one catch: you have to instruct
>> your IDE to use UTF-8 for your templates, Tapestry property files and
>> *classes*. I've just created a simple class that returns a string with
>> accented characters and it worked flawlessly. I suggest Mark Allan to check
>> which encoding is used in the files, as Eclipse uses the operating system
>> default one for source classes, and also check the XML declaration.
>
> The encoding was the first thing I checked when I noticed I wasn't getting
> the correct output. I'm not using an IDE - just a plain text editor which
> supports many text encoding formats and compiling/running from the command
> line. All my .java, .xml and .tml files are UTF-8. How do I check the
> encoding of my class files and under what circumstances would it differ from
> the input java files?
>
> Thanks
> Mark
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Mark Allan <ma...@ed.ac.uk>.
On 29 Mar 2010, at 2:21 pm, Thiago H. de Paula Figueiredo wrote:
> On Mon, 29 Mar 2010 09:32:05 -0300, Andreas Andreou
> <an...@di.uoa.gr> wrote:
>
>> I've been bitten a few times in the past by having such strings in
>> the
>> java files
>
> My first language is Portuguese, which has a lot of accented
> characters, and I don't have this problem. But there's one catch:
> you have to instruct your IDE to use UTF-8 for your templates,
> Tapestry property files and *classes*. I've just created a simple
> class that returns a string with accented characters and it worked
> flawlessly. I suggest Mark Allan to check which encoding is used in
> the files, as Eclipse uses the operating system default one for
> source classes, and also check the XML declaration.
The encoding was the first thing I checked when I noticed I wasn't
getting the correct output. I'm not using an IDE - just a plain text
editor which supports many text encoding formats and compiling/running
from the command line. All my .java, .xml and .tml files are UTF-8.
How do I check the encoding of my class files and under what
circumstances would it differ from the input java files?
Thanks
Mark
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 29 Mar 2010 09:32:05 -0300, Andreas Andreou <an...@di.uoa.gr>
wrote:
> I've been bitten a few times in the past by having such strings in the
> java files
My first language is Portuguese, which has a lot of accented characters,
and I don't have this problem. But there's one catch: you have to instruct
your IDE to use UTF-8 for your templates, Tapestry property files and
*classes*. I've just created a simple class that returns a string with
accented characters and it worked flawlessly. I suggest Mark Allan to
check which encoding is used in the files, as Eclipse uses the operating
system default one for source classes, and also check the XML declaration.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Andreas Andreou <an...@di.uoa.gr>.
I've been bitten a few times in the past by having such strings in the
java files
and i've since considered it a good practice to always move them to
resourcebundles - perhaps it's worth a try...
On Mon, Mar 29, 2010 at 14:11, Mark Allan <ma...@ed.ac.uk> wrote:
> On 23 Mar 2010, at 12:30 pm, Mark Allan wrote:
>
>> On 23 Mar 2010, at 12:14 pm, Thiago H. de Paula Figueiredo wrote:
>>
>>> On Tue, 23 Mar 2010 09:07:49 -0300, Mark Allan <ma...@ed.ac.uk>
>>> wrote:
>>>
>>>> I know I can use the OutputRaw element, and most of the time it works
>>>> fine, but I can't use that inside an alt tag for my images.
>>>
>>> Why don't you write a simple Image component that writes your <img> tag
>>> programatically? It would even make sense even in reusability, as all the
>>> <img> attributes seem to come from the same object.
>>
>> Hi Thiago, thanks for your reply.
>>
>> There are a few reasons I don't want to write a custom component:
>> 1) Once I'm finished developing the software, the front-end of the site
>> needs to be maintained by someone who only knows HTML, so I'm trying to keep
>> the <t: /> components to a minimum. I suspect she'll get confused if she
>> sees Image components being used, and I doubt her validator software would
>> like it either.
>> 2) I'd really like to get rid of all the outputraw components in my Gaelic
>> pages for ease of maintaining the templates in the future.
>> 3) It's not only images I'm having this problem with, I was just using it
>> as an example.
>
> I don't suppose anyone's got any other suggestions for solutions to this
> problem please?
>
> Thanks
> Mark
>
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Mark Allan <ma...@ed.ac.uk>.
On 23 Mar 2010, at 12:30 pm, Mark Allan wrote:
> On 23 Mar 2010, at 12:14 pm, Thiago H. de Paula Figueiredo wrote:
>
>> On Tue, 23 Mar 2010 09:07:49 -0300, Mark Allan
>> <ma...@ed.ac.uk> wrote:
>>
>>> I know I can use the OutputRaw element, and most of the time it
>>> works fine, but I can't use that inside an alt tag for my images.
>>
>> Why don't you write a simple Image component that writes your <img>
>> tag programatically? It would even make sense even in reusability,
>> as all the <img> attributes seem to come from the same object.
>
> Hi Thiago, thanks for your reply.
>
> There are a few reasons I don't want to write a custom component:
> 1) Once I'm finished developing the software, the front-end of the
> site needs to be maintained by someone who only knows HTML, so I'm
> trying to keep the <t: /> components to a minimum. I suspect she'll
> get confused if she sees Image components being used, and I doubt
> her validator software would like it either.
> 2) I'd really like to get rid of all the outputraw components in my
> Gaelic pages for ease of maintaining the templates in the future.
> 3) It's not only images I'm having this problem with, I was just
> using it as an example.
I don't suppose anyone's got any other suggestions for solutions to
this problem please?
Thanks
Mark
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by Mark Allan <ma...@ed.ac.uk>.
On 23 Mar 2010, at 12:14 pm, Thiago H. de Paula Figueiredo wrote:
> On Tue, 23 Mar 2010 09:07:49 -0300, Mark Allan <ma...@ed.ac.uk>
> wrote:
>
>> I know I can use the OutputRaw element, and most of the time it
>> works fine, but I can't use that inside an alt tag for my images.
>
> Why don't you write a simple Image component that writes your <img>
> tag programatically? It would even make sense even in reusability,
> as all the <img> attributes seem to come from the same object.
Hi Thiago, thanks for your reply.
There are a few reasons I don't want to write a custom component:
1) Once I'm finished developing the software, the front-end of the
site needs to be maintained by someone who only knows HTML, so I'm
trying to keep the <t: /> components to a minimum. I suspect she'll
get confused if she sees Image components being used, and I doubt her
validator software would like it either.
2) I'd really like to get rid of all the outputraw components in my
Gaelic pages for ease of maintaining the templates in the future.
3) It's not only images I'm having this problem with, I was just using
it as an example.
Mark
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with HTML entities and OutputRaw
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 23 Mar 2010 09:07:49 -0300, Mark Allan <ma...@ed.ac.uk> wrote:
> Hi all,
Hi!
> I know I can use the OutputRaw element, and most of the time it works
> fine, but I can't use that inside an alt tag for my images.
Why don't you write a simple Image component that writes your <img> tag
programatically? It would even make sense even in reusability, as all the
<img> attributes seem to come from the same object.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org