[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: Indexed Properties
From:       "Chris Miller" <kiwi () vardus ! co ! uk>
Date:       2000-07-24 12:57:35
[Download RAW message or body]

I have the following strings declared in my resources.properties file:

month.1=January
month.2=February
... and so on.

I am currently then doing the following in my JSP's:


<%-- Load the month names --%>
<%
  MessageResources resources = (MessageResources)
config.getServletContext().getAttribute("org.apache.struts.action.MESSAGE");

  // Load in the month value/label pairs
  String[][] months = new String[2][12];
  for (int i = 0; i < 12; i++) {
    months[0][i] = String.valueOf(i + 1);
    months[1][i] = resources.getMessage("month." + String.valueOf(i + 1));
  }
  pageContext.setAttribute("monthValues", months[0]);
  pageContext.setAttribute("monthLabels", months[1]);
%>


Then further down I'm doing something like...


<struts:select property="activationMonth" value="6">
  <struts:options name="monthValues" labelName="monthLabels"/>
</struts:select>


...to dynamically populate the month names on a form.

This works fine. However, I would like to move the code looking up the month
names out into a .java file (to clean things up, and so that all my pages
can call the same code). What I'm not quite sure on is, do I have to move
this into a servlet? Or can I use a bean? I think a bean would be more
suitable(?), but then how do I access the MessageResources - would I have to
pass the 'config' object to the bean each time I wanted to get the month
array? Any ideas on the best way to set this up would be appreciated! I'm
new to all this Java/JSP/Servlet stuff, so I'm not quite sure of the best
approach.

Thanks,

Chris Miller

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic