|
|
| Struts and localized HTML options |
|
| Author |
Message |
Anders Steinlein

|
Posted: 7/13/2003 8:08:00 AM |
Top |
java-programmer, Struts and localized HTML options
I have a JSP page where all regular messages are retrieved from property
files using <bean:message ...>. But how do I display a bunch of localized
HTML options in a form? For instance, consider this code snippet:
<html:select property="country" size="1">
<html:options property="countries" />
</html:select>
In this example, the options will be populated from the countries field
in my ActionForm, but then I have to hard-code the countries, which is
not what I want.
Do I have to make an Action that populates the relevant fields in the
ActionForm before the view is pulled up, or is there a more "elegant"
approach? If not, how do I go about doing that (getting the correct
properties by code)?
Thanks in advance for any help!
\Anders
|
| |
|
| |
 |
music

|
Posted: 7/13/2003 10:52:00 AM |
Top |
java-programmer >> Struts and localized HTML options
Can't remember the exact syntax for this (as it has been over a year since I
have done struts) but you can have the options bind to a list (that you can
load up when the server starts up) that is Application Scope or you can have
the options point to a vector(I believe) which has been preloaded.
"Anders Steinlein" <email***@***.com> wrote in message
news:email***@***.com...
> I have a JSP page where all regular messages are retrieved from property
> files using <bean:message ...>. But how do I display a bunch of localized
> HTML options in a form? For instance, consider this code snippet:
>
> <html:select property="country" size="1">
> <html:options property="countries" />
> </html:select>
>
> In this example, the options will be populated from the countries field
> in my ActionForm, but then I have to hard-code the countries, which is
> not what I want.
>
> Do I have to make an Action that populates the relevant fields in the
> ActionForm before the view is pulled up, or is there a more "elegant"
> approach? If not, how do I go about doing that (getting the correct
> properties by code)?
>
> Thanks in advance for any help!
>
> \Anders
|
| |
|
| |
 |
music

|
Posted: 7/13/2003 11:00:00 AM |
Top |
java-programmer >> Struts and localized HTML options
Ok. Now my memory is coming back:
http://jakarta.apache.org/struts/userGuide/struts-html.html#options
Use the collection attribute like so:
<html:select property="client" size="1">
<html:options collection="searchcriterianumeric" property="value"
labelProperty="label"/>
</html:select>
You can have an action (upon form load) that preloads by building the
collection like so:
ArrayList alNumeric = ....; // Fill the array list...
request.getSession().setAttribute("searchcriterianumeric", alNumeric);
Of course there may be a better way to do this but you should never have to
hardcode any of your options...
|
| |
|
| |
 |
Anders Steinlein

|
Posted: 7/13/2003 10:14:00 PM |
Top |
java-programmer >> Struts and localized HTML options
In article <email***@***.com>, email***@***.com
says...
> Ok. Now my memory is coming back:
> http://jakarta.apache.org/struts/userGuide/struts-html.html#options
>
> Use the collection attribute like so:
>
> <html:select property="client" size="1">
> <html:options collection="searchcriterianumeric" property="value"
> labelProperty="label"/>
> </html:select>
>
> You can have an action (upon form load) that preloads by building the
> collection like so:
> ArrayList alNumeric = ....; // Fill the array list...
>
> request.getSession().setAttribute("searchcriterianumeric", alNumeric);
That's what I was thinking. However, how do I load the correct properties
from code? Is there some functianality in Struts to do this, or do I have
to use PropertyResourceBundle directly? The latter seems a bit silly,
since I will have to know the name (and location?) of the property file
in code (they are defined in struts-config.xml)...
Thanks again!
\Anders
|
| |
|
| |
 |
| |
|