Its the name/property specified on the html:select tag that causes
OptionsCollection to set selected - in your case the select tag needs to
look at he country property of the customer bean - if optionsCollection
finds a value that matches that, it will set selected.
html:select name=customer property=country
html:optionsCollection ./
/select
Niall
- Original Message -
From: Frank Schaare [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, March 11, 2004 11:49 AM
Subject: rePost: How to set the selected value in an select rendered by
optionsCollection
Hi all,
i´m reposting my problem trying to be a little bit more specific. This
problem is very important for me, though i made another 'book like'
example to show where i am.
There are three beans playing in my theatre:
1. the CommonValuesBean which stores frequently asked data for my JSP
HTMLForms
2. the CustomerBean which is an buisiness objekt representing a customer
3. the DynaForm which stores data coming from my JSP HTMLForms.
First of all, the CommonValuesBean is initialised. Therefore, i´ve got
the sessionListener that puts data in it, anytime a new session is creatd:
public void sessionCreated(HttpSessionEvent event) {
CommonValuesBean commonValuesBean = new CommonValuesBean(); // create
new bean instance
HashMap countries = new HashMap(); // Create new map
countries.put(countryCode1,country1)
countries.put(countryCode2,country2)
countries.put(countryCode3,country3)
countries.setCountries(countries); // Our example map is now stored
HttpSession session = event.getSession();
session.setAttribute(commonValuesBean,CommonValuesBean);
}
Now we begin to deal with the customers. There is listCustomers Action
that shows all of the customers. You can klick one to
get more detailed information using the customersDetailsAction:
public class customersDetailsAction extends Action
{
private Customer customer = new Customer();
public ActionForward execute(ActionMapping mapping,ActionForm
form,HttpServletRequest req,HttpServletResponse res)
throws IOException, ServletException
{
customer.setFirstName(Frank);
customer.setLastName(Schaare);
customer.setCountry(country2);
req.setAttribute(customer,customer); // storing customer in request
return mapping.findForward(customerShowDetails); // mapped to
customerShowDetails.jsp
}
}
The customerShowDetails.jsp looks like this:
html:form action=/BenutzerBearbeitungSubmit
.
. tons of markup
.
html:select property=country size=1
html:optionsCollection name=commonValuesBean
property=countries label=value value=key/
/html:select
.
. again: tons of markup
.
/html:form
The problem is, that the html:optionsCollection renders a select like
this:
select name=country
option value=countryCode1country1/option
option value=countryCode2country2/option
option value=countryCode3country3/option
/select
i desperately NEED to render the select like this:
select name=country
option value=countryCode1country1/option
option selected value=countryCode2country2/option
option value=countryCode3country3/option
/select
because my customer lives in country2 !
Is there any way to tell Struts to do this ?
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]