Escaping dollar sign and curly brackets

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Escaping dollar sign and curly brackets

mcarreira
Hey,

In my action I'm using getText(myKey) to get a localized string. This
string has some placeholders of mine, in ${placeholder} format. Consider
my original key is defined as this in my properties file:

     myKey = Some text ${placeholder} more text.

I've read in Struts documentation that it uses MessageFormat. So, if I
want literals, I need to use single quotes. This is what I did in my
properties file:

     myKey = Some text '${placeholder}' more text.

However, when I call getText(myKey) I get: Some text ' more text. Why
does this happen?

I also noticed that the problem is the dollar sign AND curly brackets
without any character in between. If I have this definition:

     myKey = Some text '$' text '{placeholder}' more text.

It gets resolved to: Some text $ text {placeholder} more text.

Can somebody explain me how can I escape the dollar and curly brackets
characters?

Thanks in advance, have a nice weekend.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Escaping dollar sign and curly brackets

Yasser Zamani-2
>From: Micael Carreira <[hidden email]>
>Sent: Friday, February 1, 2019 6:56 PM
>To: [hidden email]
>Subject: Escaping dollar sign and curly brackets
>
>Hey,
>
>In my action I'm using getText(myKey) to get a localized string. This string has
>some placeholders of mine, in ${placeholder} format. Consider my original key is
>defined as this in my properties file:
>
>     myKey = Some text ${placeholder} more text.
>
>I've read in Struts documentation that it uses MessageFormat. So, if I want
>literals, I need to use single quotes. This is what I did in my properties file:
>
>     myKey = Some text '${placeholder}' more text.
>
>However, when I call getText(myKey) I get: Some text ' more text. Why does this
>happen?

It seems firstly ${placeholder} is evaluated to empty by Struts then '' is evaluated to ' by MessageFormat.

>
>I also noticed that the problem is the dollar sign AND curly brackets without any
>character in between. If I have this definition:
>
>     myKey = Some text '$' text '{placeholder}' more text.
>
>It gets resolved to: Some text $ text {placeholder} more text.
>
>Can somebody explain me how can I escape the dollar and curly brackets
>characters?

I guess '$'{placeholder} or $'{placeholder}' or '$''{placeholder}' should work :\ could you please report back the result for each one? And which Struts version you test?

Thanks for using Struts!

Kind Regards.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Escaping dollar sign and curly brackets

Lukasz Lenart
In reply to this post by mcarreira
Using ${} or %{} is a proper way to inject values into a message
https://struts.apache.org/getting-started/message-resource-files.html#message-resource-property-files

In your case a "getPlaceholder()" will be used to fetch the value from
the current action.


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

pt., 1 lut 2019 o 16:25 Micael Carreira <[hidden email]> napisał(a):

>
> Hey,
>
> In my action I'm using getText(myKey) to get a localized string. This
> string has some placeholders of mine, in ${placeholder} format. Consider
> my original key is defined as this in my properties file:
>
>      myKey = Some text ${placeholder} more text.
>
> I've read in Struts documentation that it uses MessageFormat. So, if I
> want literals, I need to use single quotes. This is what I did in my
> properties file:
>
>      myKey = Some text '${placeholder}' more text.
>
> However, when I call getText(myKey) I get: Some text ' more text. Why
> does this happen?
>
> I also noticed that the problem is the dollar sign AND curly brackets
> without any character in between. If I have this definition:
>
>      myKey = Some text '$' text '{placeholder}' more text.
>
> It gets resolved to: Some text $ text {placeholder} more text.
>
> Can somebody explain me how can I escape the dollar and curly brackets
> characters?
>
> Thanks in advance, have a nice weekend.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Escaping dollar sign and curly brackets

mcarreira
In reply to this post by Yasser Zamani-2
Hey Yasser,

Thanks for your reply. I tought I tried every combination you suggested,
but it seems that I missed the *$'{placeholder}'* variant.

This works for me. Thanks for your help!


On 02/02/19 13:25, Yasser Zamani-2 [via Struts] wrote:

>> From: Micael Carreira <[hidden email]>
>> Sent: Friday, February 1, 2019 6:56 PM
>> To: [hidden email]
>> Subject: Escaping dollar sign and curly brackets
>>
>> Hey,
>>
>> In my action I'm using getText(myKey) to get a localized string. This string has
>> some placeholders of mine, in ${placeholder} format. Consider my original key is
>> defined as this in my properties file:
>>
>>      myKey = Some text ${placeholder} more text.
>>
>> I've read in Struts documentation that it uses MessageFormat. So, if I want
>> literals, I need to use single quotes. This is what I did in my properties file:
>>
>>      myKey = Some text '${placeholder}' more text.
>>
>> However, when I call getText(myKey) I get: Some text ' more text. Why does this
>> happen?
> It seems firstly ${placeholder} is evaluated to empty by Struts then '' is evaluated to ' by MessageFormat.
>
>> I also noticed that the problem is the dollar sign AND curly brackets without any
>> character in between. If I have this definition:
>>
>>      myKey = Some text '$' text '{placeholder}' more text.
>>
>> It gets resolved to: Some text $ text {placeholder} more text.
>>
>> Can somebody explain me how can I escape the dollar and curly brackets
>> characters?
> I guess '$'{placeholder} or $'{placeholder}' or '$''{placeholder}' should work :\ could you please report back the result for each one? And which Struts version you test?
>
> Thanks for using Struts!
>
> Kind Regards.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Escaping dollar sign and curly brackets

mcarreira
In reply to this post by Lukasz Lenart
Hey Lukasz, thanks for your reply.

Actually, I don't want to use struts tag replacement mechanism, but one
of my own.

I already solved my problem as you probably read by now.

Cheers and thanks for your help.

On 04/02/19 10:10, Lukasz Lenart wrote:
> Using ${} or %{} is a proper way to inject values into a message
> https://struts.apache.org/getting-started/message-resource-files.html#message-resource-property-files
>
> In your case a "getPlaceholder()" will be used to fetch the value from
> the current action.
>
>
> Regards

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]