[Webwork-user] WebWork components: Works!!!
Brought to you by:
baldree,
rickardoberg
From: Rickard <ri...@jb...> - 2000-11-30 10:48:29
|
All, I've been fiddling a bit with generic WebWork components. It works GREAT! Here's a somewhat complex example. This generic JSP component "selectgroupmap.jsp": <%@ taglib uri="webwork" prefix="webwork" %> <SELECT NAME="<%=request.getParameter("name")%>"> <webwork:iterator name="$list"> <OPTGROUP LABEL="<webwork:property name="key"/>"> <webwork:iterator name="value"> <OPTION VALUE="<webwork:property name="key"/>" <webwork:equals name="key" value="$value">SELECTED</webwork:equals>><webwork:property name="value"/></OPTION> </webwork:iterator> </OPTGROUP> </webwork:iterator> </SELECT> included like this in a form: Country:<jsp:include page="CountryMap.action?result=selectgroupmap.jsp" flush="true"> <jsp:param name="name" value="country"/> <jsp:param name="list" value="countries"/> <jsp:param name="value" value="country"/> </jsp:include> where CountryMap.java is: public class CountryMap extends ActionSupport { // Attributes ---------------------------------------------------- Map countries; // Public -------------------------------------------------------- public Map getCountries() { return countries; } // Action implementation ----------------------------------------- public Object execute() throws Exception { countries = new HashMap(); Map continent = new HashMap(); continent.put("sv", "Sweden"); continent.put("uk", "United Kingdom"); continent.put("ge", "Germany"); countries.put("Europe", continent); continent = new HashMap(); continent.put("ch", "China"); continent.put("in", "India"); continent.put("ru", "Russia"); countries.put("Asia", continent); continent = new HashMap(); continent.put("us", "USA"); continent.put("ca", "Canada"); countries.put("North America", continent); return getResult(); } } and the form that uses this control has getCountry() and setCountry() (used for the "name" and "value" params to get the currently selected item), results in this HTML: Country: <SELECT NAME="country"> <OPTGROUP LABEL="Europe"><OPTION VALUE="sv" >Sweden</OPTION> <OPTION VALUE="ge" >Germany</OPTION> <OPTION VALUE="uk" >United Kingdom</OPTION> </OPTGROUP> <OPTGROUP LABEL="North America"><OPTION VALUE="ca" >Canada</OPTION> <OPTION VALUE="us" >USA</OPTION> </OPTGROUP> <OPTGROUP LABEL="Asia"><OPTION VALUE="ru" >Russia</OPTION> <OPTION VALUE="in" >India</OPTION> <OPTION VALUE="ch" >China</OPTION> </OPTGROUP> </SELECT> --- Is that cool or what!?! I've done a couple of other "controls" or components, and it's just incredibly easy to work with and use. I'm doing a bunch of these as examples and am including them with WebWork, and am also doing an example form that shows how to use them. Web development nirvana, here we come :-) regards, Rickard -- Rickard Öberg Email: ri...@jb... |