You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rifqiyusuf <ri...@gmail.com> on 2017/03/23 15:05:08 UTC
Load Message from database using ResourceBundle
I would like to retrieve database value from a table.
let's say i have table_message that looks like this :
| ID | KEY | MESSAGE |
| 1 | app.label1 | Your First Name |
| 2 | app.label2 | Your Last Name |
then I would like to get Your First Name band Your Last Name through
app.label1 and app.label2 using a JSP ( i use struts 2 frameworks ) that
might look like this.
<s:textfield label="app.label1" name="firstName"/>
<s:textfield label="app.label2" name ="lastName"/>
those text fields should populate with Your First Name and Your last Name
without requiring *.properties file.
if anyone know how to do this , please let me know.
Thank you
--
View this message in context: http://struts.1045723.n5.nabble.com/Load-Message-from-database-using-ResourceBundle-tp5720946.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Load Message from database using ResourceBundle
Posted by Adam Brin <ab...@digitalantiquity.org>.
That’ll help in a few places, but technically you want a custom implementation of the TextProvider. A quick google search suggests:
http://struts.1045723.n5.nabble.com/Stuts-2-and-Custom-TextProvider-td3494753.html
--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
> On Mar 23, 2017, at 8:20 AM, Snowball RC <cr...@gmail.com> wrote:
>
>
>
> On 2017-03-23 16:05 (+0100), rifqiyusuf <ri...@gmail.com> wrote:
>> I would like to retrieve database value from a table.
>>
>> let's say i have table_message that looks like this :
>>
>> | ID | KEY | MESSAGE |
>> | 1 | app.label1 | Your First Name |
>> | 2 | app.label2 | Your Last Name |
>>
>>
>> then I would like to get Your First Name band Your Last Name through
>> app.label1 and app.label2 using a JSP ( i use struts 2 frameworks ) that
>> might look like this.
>>
>> <s:textfield label="app.label1" name="firstName"/>
>> <s:textfield label="app.label2" name ="lastName"/>
>>
>> those text fields should populate with Your First Name and Your last Name
>> without requiring *.properties file.
>>
>> if anyone know how to do this , please let me know.
>>
>> Thank you
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://struts.1045723.n5.nabble.com/Load-Message-from-database-using-ResourceBundle-tp5720946.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> Hi,
>
> To do that you have to override all Struts 2 getText method to pass your label code and then to do some request to your database instead of properties files.
>
> for example :
> @Override
> public String getText(String key) {
> return getText(key, key);
> }
> etc..
> And finally have a method that call your database service to retrieve your label.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Load Message from database using ResourceBundle
Posted by Snowball RC <cr...@gmail.com>.
On 2017-03-23 16:05 (+0100), rifqiyusuf <ri...@gmail.com> wrote:
> I would like to retrieve database value from a table.
>
> let's say i have table_message that looks like this :
>
> | ID | KEY | MESSAGE |
> | 1 | app.label1 | Your First Name |
> | 2 | app.label2 | Your Last Name |
>
>
> then I would like to get Your First Name band Your Last Name through
> app.label1 and app.label2 using a JSP ( i use struts 2 frameworks ) that
> might look like this.
>
> <s:textfield label="app.label1" name="firstName"/>
> <s:textfield label="app.label2" name ="lastName"/>
>
> those text fields should populate with Your First Name and Your last Name
> without requiring *.properties file.
>
> if anyone know how to do this , please let me know.
>
> Thank you
>
>
>
>
>
>
> --
> View this message in context: http://struts.1045723.n5.nabble.com/Load-Message-from-database-using-ResourceBundle-tp5720946.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Hi,
To do that you have to override all Struts 2 getText method to pass your label code and then to do some request to your database instead of properties files.
for example :
@Override
public String getText(String key) {
return getText(key, key);
}
etc..
And finally have a method that call your database service to retrieve your label.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Load Message from database using ResourceBundle
Posted by Lukasz Lenart <lu...@apache.org>.
2017-03-23 16:05 GMT+01:00 rifqiyusuf <ri...@gmail.com>:
> I would like to retrieve database value from a table.
>
> let's say i have table_message that looks like this :
>
> | ID | KEY | MESSAGE |
> | 1 | app.label1 | Your First Name |
> | 2 | app.label2 | Your Last Name |
>
>
> then I would like to get Your First Name band Your Last Name through
> app.label1 and app.label2 using a JSP ( i use struts 2 frameworks ) that
> might look like this.
>
> <s:textfield label="app.label1" name="firstName"/>
> <s:textfield label="app.label2" name ="lastName"/>
>
> those text fields should populate with Your First Name and Your last Name
> without requiring *.properties file.
>
> if anyone know how to do this , please let me know.
Implementing a custom TextProvider is the way to go as mentioned by
Adam. With the next version of Struts this will change a bit to avoid
problems when using different DI library (e.g. Spring), instead
implementing TextProvider interface only you will have to implement
TextProviderFactory as well.
https://github.com/apache/struts-examples/tree/master/text-provider
https://issues.apache.org/jira/browse/WW-4756
Right now I'm adding some docs how to implement custom TextProvider &
TextProviderFactory
https://cwiki.apache.org/confluence/display/WW/Localization
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org