I have several lists that I wish to use in forms and result pages for checkboxes and options. These lists (all 50 states, various majors/options for college, etc.) will appear on several pages across the application and their values placed in the database when selected. I want to cache or quickly pull these lists for use via tag libraries.
My current implementation is as follows:
I have my lists stored in xml files with the following design:
<!ELEMENT list (set+)> <!ELEMENT set (label, value) (#CDATA)> <!ELEMENT label (#CDATA)> <!ELEMENT value (#CDATA)>
Example: <list> <set> <label>New York</label> <value>NY</value> </set> </list>
I have a class called LabelValueListBean that houses an ArrayList of LabelValueBeans. It has two methods of importance - populate(String filename) and getList().
-- getList() returns the ArrayList containing the LabelValueBeans
-- populate(String filename) is a static method that takes an xml file of the above format and uses Digester to create a LabelValueBean for each set element and to place all LabelValueBeans in an instance of LabelValueListBean
I then have a class that extends Plug-In to instantiate my application-wide objects. All of my xml files are listed by filename in my ApplicationResources file. I then use the messages as filename arguments for the populate() method of each LabelValueListBean.. I then set each LabelValueListBean as an attribute in the application scope.
Current code: // msgres is a MessageResources object // sc is the ServletContext object String statesList = msgres.getMessage("list.states"); statesNew = LabelValueListBean.populate(sc.getRealPath(statesList)); sc.setAttribute("statesNew", statesNew); // I now print out the LabelValueListBean System.out.println(statesNew.toString());
The above executes without fail and the println shows that the LabelValueListBean is indeed populated.
I hope the above is enough background information to work with.
I have tried various methods, all of which failed, of accessing the LabelValueListBean object in a JSP page via tag libraries for use in html:optionsCollection and the like.
Attempts: (<app:xxx> is the Jakarta application tag library)
<html:select property="homeState"> <app:attributes id="statesTest" name="statesNew"> <html:optionsCollection name="statesTest" property="list"/> </app:attributes> </html:select>
The above returns the following:
javax.servlet.ServletException: No getter method for property list of bean statesTest
In my desperation:
<html:select property="homeState">
<html:optionsCollection name='${applicationScope.statesNew}' property="list"/>
</html:select>
javax.servlet.ServletException: Cannot find bean Label: Alabama --- Value: AL
Label: Alaska --- Value: AK
Label: Arizona --- Value: AZ
... (the rest of the toString() of LabelValueListBean)
What am I doing wrong? How can I fix this? I am going about this a totally wrong way? I figure the solution is probably quite simple and under my foolish nose. Any help would be greatly appreciated.
Regards,
Kevin
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]