Adding dynamic parts to texts

When I try to put some dynamic parts in my texts that will be used by the <s:text> in Struts 2, these parts are replaced with the params that I defined.

This is how I write my sentences in my file.properties :

 my_error=The event {0} doesn't exist 

This is how I try to display it:

 <s:text name="my_error"> <s:param>Event01</s:param> </s:text> 

But as a result, the expression {0} NOT replaced, and I have no error in the log. What's wrong?

+6
source share
3 answers

I really can't understand. I selected this example , so I have this in the jsp file:

 <s:text name="msg.error"> <s:param >Event01</s:param> </s:text> <br /> <s:text name="name.msg.param" > <s:param >mkyong</s:param> </s:text> 

and this is in my .properties:

 msg.error = This event doesn't exist: {0} name.msg.param = This is a message from properties file - param : {0} 

But the result:

 This event does not exist: {0} This is a message from properties file - param : mkyong 

I canโ€™t find the real difference.

+2
source

The message must be in the resource set with the same name as the action with which it is associated.

If the named message is not found in the properties file, then the body tag will be used as the default message.

Create or place the resource package for the locale that you are using in a location that is better described using the search order in the localization guide .

+1
source

i guess {0} refers to the first index of the list to be passed as a parameter to the getText method.

Now, when you use s: text and pass the parameter, it should be a list type variable containing the element with the value "Event01" in the first index.

Try to implement the same. That might work :)

0
source

Source: https://habr.com/ru/post/946057/


All Articles