Re: Struts - How to recover collection element
I think I am not grokking your complete workflow, however, you said in your first post: "Once a user selects an option, the option value (rather than the description) is recorded in a form bean, and the form bean is forwarded to another form." So, the 'key' is the value that the user picked from the select control on the first page. I use 'key' as the name of the property on the form that holds that value. In your case, it looks like that would be the 'surveyType' property. So maybe you would use 'surveyForm.surveyType' instead of 'MyForm.key' ... Also, I am a little confused by your JSP. It looks you are trying to hold the description in a hidden field on the form--this should not be necessary--I was under the impression that you wanted to render the description on the page following this JSP. [EMAIL PROTECTED] wrote: Superb answer Bill. I've coded the following which correctly gets the OptionsCollection, but I'm stumped as to what to substitute in place of 'MyForm.key': Type: - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts - How to recover collection element
Superb answer Bill. I've coded the following which correctly gets the OptionsCollection, but I'm stumped as to what to substitute in place of 'MyForm.key': Type: There are a couple of ways of doing this. I think the best approach is to wrap your collection in a JavaBean that is stored in the session. Something like the following: public class OptionsHolder { Map options = new HashMap(); public OptionsHolder() { options.put("key1", new LabelValueBean("foo","key1")); options.put("key2", new LabelValueBean("foo","key1")); } public Collection getOptionsCollection() { return options.values(); } public Map getOptionsMap() { return options; } } You can then use the getOptionsCollection() method to render the options in the first form. Then in the page where you want to display the value for the key, you can use JSTL. Assuming the ServletContext attribute name were "optionsHolder" and the key was in the property 'key' on the form: Another alternative is to create a mapped property in the OptionsHolder bean; then use Struts support for mapped properties in the bean:write tag. Finally, a third alternative would be to fetch the value in the action that processes the form. Extract the desired value then set it as a request attribute for display on the subsequent JSP. With this approach you might not need to use the OptionsHolder class and instead just iterate over the collection looking for a match. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts - How to recover collection element
There are a couple of ways of doing this. I think the best approach is to wrap your collection in a JavaBean that is stored in the session. Something like the following: public class OptionsHolder { Map options = new HashMap(); public OptionsHolder() { options.put("key1", new LabelValueBean("foo","key1")); options.put("key2", new LabelValueBean("foo","key1")); } public Collection getOptionsCollection() { return options.values(); } public Map getOptionsMap() { return options; } } You can then use the getOptionsCollection() method to render the options in the first form. Then in the page where you want to display the value for the key, you can use JSTL. Assuming the ServletContext attribute name were "optionsHolder" and the key was in the property 'key' on the form: Another alternative is to create a mapped property in the OptionsHolder bean; then use Struts support for mapped properties in the bean:write tag. Finally, a third alternative would be to fetch the value in the action that processes the form. Extract the desired value then set it as a request attribute for display on the subsequent JSP. With this approach you might not need to use the OptionsHolder class and instead just iterate over the collection looking for a match. [EMAIL PROTECTED] wrote: I've loaded a collection of valid options and their descriptions as a ServletContext attribute, for use in an tag. It works as intended in a generated html tag. Once a user selects an option, the option value (rather than the description) is recorded in a form bean, and the form bean is forwarded to another form. So far so good. What I'd like to do in the next form is display the description of the selected option, using the option as a lookup key to the original collection. Is there an existing struts tag that will allow me to do this? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Struts - How to recover collection element
I've loaded a collection of valid options and their descriptions as a ServletContext attribute, for use in an tag. It works as intended in a generated html tag. Once a user selects an option, the option value (rather than the description) is recorded in a form bean, and the form bean is forwarded to another form. So far so good. What I'd like to do in the next form is display the description of the selected option, using the option as a lookup key to the original collection. Is there an existing struts tag that will allow me to do this? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]