put a "do" before "implement" and ELs are just scripting in disguise. Bloody Aussie. -----Original Message----- From: Andrew Hill [mailto:andrew.david.hill@gridnode.com] Sent: Wednesday, July 16, 2003 8:23 AM To: Struts Users Mailing List Subject: RE: [OT] Re: 4th Of July Struts Challenge... Strictly speaking, JavaBeans do not contain a constructor and implement Serializable. Dont they just need to make sure a noargs constructor is available? Are they allowed to implement serializable if they want though? Be kinda funny if they couldnt... I wouldnt count expression evaluation languages as scripting myself. I reckon to be a script you need to be able to script stuff (in addition to having some kind of expression syntax): ie: do this and this and this... whereas an expression is merely a statement of value. Ie: a script would be "add 1 + 1 and get the result" whereas an expression is merely "the value of 1 + 1". I guess you've been using LISP too long to understand the difference eh? ;-> -----Original Message----- From: Mark Galbreath [mailto:mark_galbreath@qat.com] Sent: Wednesday, 16 July 2003 20:12 To: 'Struts Users Mailing List' Subject: RE: [OT] Re: 4th Of July Struts Challenge... A few comments: 1. I got runtime errors when I declared a DynaActionForm bean of type Map; I had to declare it of type HashMap. 2. You may be using JSTL, but it still looks like scripting to me..... 3. Strictly speaking, JavaBeans do not contain a constructor and implement Serializable. Mark -----Original Message----- From: Rick Reumann [mailto:r@reumann.net] Sent: Tuesday, July 15, 2003 11:44 PM To: Struts Users Mailing List Subject: [OT] Re: 4th Of July Struts Challenge... Kris... this was just awesome! Thanks. You da 'man:) On Tue, Jul 15,'03 (11:25 AM GMT-0400), Kris wrote: > As it turns out, some of my ideas about a "standard" property of type > Map versus a "mapped property" were a bit off. So, if you're still > interested, here's something I hacked together. You'll notice I used a > session scoped form so that Struts doesn't choke when it tries to > populate the form. > > struts-config.xml: > ------------------ > > > type="org.apache.struts.action.DynaActionForm"> > > > > > > type="com.dotech.EditEmployeesAction" > name="employeesForm" > scope="session" > validate="false"> > > > type="org.apache.struts.actions.ForwardAction" > parameter="/viewEmployees.jsp" > name="employeesForm" > scope="session" > validate="false"/> > > > > editEmployees.jsp: > ------------------ > > <%@ taglib prefix="bean" > uri="http://jakarta.apache.org/struts/tags-bean" %><%@ taglib > prefix="c" uri="http://java.sun.com/jstl/core" %><%@ taglib > prefix="html" uri="http://jakarta.apache.org/struts/tags-html" %> > > <%-- dynamically get a handle to the form --%> > > > > > > > > > > > > > > > Edit Employees > > > > > > > > > > > > > > >
> name=" value="employeesMap(${entry.key}).name"/>" > value=""> > > name=" value="employeesMap(${entry.key}).age"/>" > value=""> >
>
> > > > > > EmployeeBean.java: > ------------------ > > package com.dotech; > > public class EmployeeBean { > > private String name; > private String age; > > public EmployeeBean(String name, String age) { > this.name = name; > this.age = age; > } > > public String getName() { return this.name; } > public void setName(String name) { this.name = name; } > > public String getAge() { return this.age; } > public void setAge(String age) { this.age = age; } > } > > > EditEmployeesAction.java: > ------------------------- > > package com.dotech; > > import java.util.*; > import javax.servlet.http.*; > import org.apache.commons.beanutils.*; > import org.apache.struts.action.*; > > public class EditEmployeesAction extends Action { > > public ActionForward execute(ActionMapping mapping, > ActionForm form, > HttpServletRequest request, > HttpServletResponse response) throws > Exception { > Map empMap = new HashMap(); > empMap.put("1111", new EmployeeBean("John Doe", "33")); > empMap.put("2222", new EmployeeBean("Loser Boy", "22")); > PropertyUtils.setProperty(form, "employeesMap", empMap); > return mapping.findForward("success"); > } > } > > > viewEmployees.jsp: > ------------------ > > <%@ taglib prefix="bean" > uri="http://jakarta.apache.org/struts/tags-bean" %><%@ taglib > prefix="c" uri="http://java.sun.com/jstl/core" %> > > <%-- dynamically get a handle to the form --%> > > > > > > > > > > > > > > > View Employees > > > > > > > > > > >
> > > > > Quoting Kris Schneider : > > > Okay, so that's way too much work ;-). I'm not sure, but I think one > > of the issues you're running into is the difference between a > > "standard" property of type Map and a "mapped property". The first > > is declared like: > > > > public Map getEmployeesMap() > > public void setEmployeesMap(Map m) > > > > The second is declared like: > > > > public Object getEmployeeMapped(String key) > > public void setEmployeeMapped(String key, Object value) > > > > For a mapped property, you'd use a reference like > > "employeeMapped(1111)" to get the object stored under the "1111" > > key. I really haven't played much with either of the above cases, so > > I may be off base... > > > > Quoting Rick Reumann : > > > > > Ok stupid subject line, but now I can get back to something I was > > > curious about that I posted around a week ago. I'm really curious > > > how to do accomplish this and yes have tried it a bunch of > > > different ways... > > > > > > Here's the challenge.... > > > > > > First challenge is just with a regular ActionForm... > > > > > > 1) Your ActionForm has to have a property of type Map. For this > > > adventure call it employeesMap. > > > > > > 2) Each map will hold for the key and employeeID ( String ssn - > > > social security number whatever). The value will be an > > > EmployeeBean. For testing sake just have it have two properties > > > String name, String age. > > > > > > 3) Put two employees into the Map and put this Map into your > > > ActionForm: HashMap empMap = new HashMap(); > > > empMap.put( "1111", new EmployeeBean("John Doe", "33" ) ); > > > empMap.put( "2222", new EmployeeBean("Loser Boy", "22" ) ); > > > setEmployeesMap( empMap ); > > > > > > 4) Now have a jsp form iterate over this Map and provide text > > > fields to edit the name and age of each employee. When the form is > > > submitted there should be a way that it will submit this Map with > > > updated EmployeeBeans with the new names and ages for each key > > > (1111 and 2222 ). Pull the map out of the action you submit to and > > > print the properties of the EmployeeBeans to test. > > > > > > > > > Second challenge... is do the above using your employeesMap as a > > > property of a DynaActionForm. > > > > > > Preferably use JSTL and/or struts-el also would be nice. > > > > > > (First one to successfully complete this challenge will win 100 > > > dollars for each person that they forward this e-mail to, as > > > Microsoft will be monitoring all the e-mails as well. That kid > > > doing this project for his science fair project to see how far > > > e-mails travel will also be involved, so please reply to him. The > > > 100 dollars will come from that African tribe leader with that > > > money he is just dying to give away if you just contact him. Some > > > of the money might come from the stolen tourist kidney sales in > > > Mexico, but I'm not positive of that). > > > > > > -- > > > Rick > > > > -- > > Kris Schneider > > D.O.Tech > -- Rick --------------------------------------------------------------------- To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: struts-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: struts-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: struts-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: struts-user-help@jakarta.apache.org