You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <r...@reumann.net> on 2003/07/03 20:03:28 UTC
4th Of July Struts Challenge...
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
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Micael <ca...@harbornet.com>.
The no-argument constructor is available from default ONLY if you do not
have another constructor, Mark. If you have another constructor with an
argument, then the no-argument constructor is not there by default and must
be coded. There is no need to test this. It is that way.
I would always make a class serializable in this situation.
At 10:29 AM 7/16/03 -0400, you wrote:
>I have not found this in the spec, but I believe the no-argument constructor
>is available at anytime for a concrete class. This would be a good one to
>test....
>
>
>-----Original Message-----
>From: Michael Duffy [mailto:duffymo@yahoo.com]
>Sent: Wednesday, July 16, 2003 10:27 AM
>To: Struts Users Mailing List
>Subject: RE: [OT] Re: 4th Of July Struts Challenge...
>
>
>
>It's my understanding that you ONLY get the default if
>there are no other constructors written. The minute
>you write ANY constructor, you're on your own. If you
>still want a default ctor, you've gotta supply it.
>
>I'll be happy to learn something if this is incorrect.
>- MOD
>
>
>--- Mark Galbreath <ma...@qat.com> wrote:
> > The no-argument constructor is the default and does
> > not have to be declared.
> > You have a 2-arg constructor. As for JSTL (or any
> > EL) acting like straight
> > scripting, I've never had an argument with using
> > scripting where
> > appropriate. Pragmatism should be the rule of the
> > day. Finally, I don't
> > know why declaring DynaActionForm beans as Maps
> > didn't work for me, but
> > neither is it a big issue. I realize the constraints
> > of declaring a variable
> > as a concrete/abstract class vs. as an interface.
> >
> > Besides, I like what you've created. :-)
> >
> > -----Original Message-----
> > From: Kris Schneider [mailto:kris@dotech.com]
> > Sent: Wednesday, July 16, 2003 8:55 AM
> > To: Struts Users Mailing List
> > Subject: RE: [OT] Re: 4th Of July Struts
> > Challenge...
> >
> >
> > Quoting Mark Galbreath <ma...@qat.com>:
> >
> > > 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.
> >
> > Not sure what you're doing, but the example works as
> > coded. If it matters,
> > post some details and we'll see if something needs
> > fixing.
> >
> > > 2. You may be using JSTL, but it still looks like
> > scripting to
> > > me.....
> >
> > Fair enough. What's your recommended alternative to
> > JSTL when using JSP for
> > your view layer?
> >
> > > 3. Strictly speaking, JavaBeans do not contain a
> > constructor and
> > > implement Serializable.
> >
> > Strictly speaking, a JavaBean *does* contain a
> > construtctor (or even more
> > than one), just like any other Java class. It's just
> > that a "real" bean
> > needs to have a no-arg constructor. The actual code
> > that I uploaded to Rick
> > includes a no-arg construtctor for EmployeeBean but
> > omitted implementing
> > Serializable or Externalizable. The bean also fails
> > to act as an event
> > source and it doesn't check for things like null
> > values passed to either its
> > construtctor or its set methods.
> >
> > > 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:
> > > > ------------------
> > > >
> > > > <form-beans>
> > > > <form-bean name="employeesForm"
> > > >
> > type="org.apache.struts.action.DynaActionForm">
> > > > <form-property name="employeesMap"
> > type="java.util.Map"/>
> > > > </form-bean>
> > > > </form-beans>
> > > >
> > > > <action-mappings>
> > > > <action path="/employees/edit"
> > > >
> > type="com.dotech.EditEmployeesAction"
> > > > name="employeesForm"
> > > > scope="session"
> > > > validate="false">
> > > > <forward name="success"
> > path="/editEmployees.jsp"/>
> > > > </action>
> > > > <action path="/employees/save"
> > > >
> > type="org.apache.struts.actions.ForwardAction"
> > > > parameter="/viewEmployees.jsp"
> > > > name="employeesForm"
> > > > scope="session"
> > > > validate="false"/>
> > > > </action-mappings>
> > > >
> > > >
> > > > 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 --%> <bean:struts
> > > > id="mapping"
> > mapping="/employees/save"/> <c:set
> > > > var="attribute" value="${mapping.attribute}"/>
> > <c:set var="scope"
> > > > value="${mapping.scope}"/> <c:choose>
> > > > <c:when test="${scope eq 'request'}">
> > > > <c:set var="form"
> > value="${requestScope[attribute]}"/>
> > > > </c:when>
> > > > <c:otherwise>
> > > > <c:set var="form"
> > value="${sessionScope[attribute]}"/>
> > > > </c:otherwise>
> > > > </c:choose>
> > > >
> > > > <html>
> > > >
> > > > <head><title>Edit Employees</title></head>
> > > >
> > > > <body>
> > > > <html:form action="/employees/save">
> > > > <table>
> > > > <c:forEach var="entry"
> > items="${form.map.employeesMap}">
> > > > <tr>
> > > > <td><c:out
> > value="${entry.key}"/></td>
> > > > <td>
> > > > <input type="text"
> > > > name="<c:out
> > > >
> > value="employeesMap(${entry.key}).name"/>"
> > > > value="<c:out
> > value="${entry.value.name}"/>">
> > > > </td>
> > > > <td>
> > > > <input type="text"
> > > > name="<c:out
> > > >
> > value="employeesMap(${entry.key}).age"/>"
> > > > value="<c:out
> > value="${entry.value.age}"/>">
> > > > </td>
> > > > </tr>
> > > > </c:forEach>
> > > > <tr>
> > > > <td align="center"
> > colspan="3"><html:submit/></td>
> > > > </tr>
> > > > </table>
> > > > </html:form>
> > > > </body>
> > > >
> > > > </html>
> > > >
> > > >
> > > > 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 --%> <bean:struts
> > > > id="mapping"
> > mapping="/employees/save"/> <c:set
> > > > var="attribute" value="${mapping.attribute}"/>
> > <c:set var="scope"
> > > > value="${mapping.scope}"/> <c:choose>
> > > > <c:when test="${scope eq 'request'}">
> > > > <c:set var="form"
> > value="${requestScope[attribute]}"/>
> > > > </c:when>
> > > > <c:otherwise>
> > > > <c:set var="form"
> > value="${sessionScope[attribute]}"/>
> > > > </c:otherwise>
> > > > </c:choose>
> > > >
> > > > <html>
> > > >
> > > > <head><title>View Employees</title></head>
> > > >
> > > > <body>
> > > > <table>
> > > > <c:forEach var="entry"
> > items="${form.map.employeesMap}">
> > > > <tr>
> > > > <td><c:out
> > value="${entry.key}"/></td>
> > > > <td><c:out
> > value="${entry.value.name}"/></td>
> > > > <td><c:out
> > value="${entry.value.age}"/></td>
> > > > </tr>
> > > > </c:forEach>
> > > > </table>
> > > > </body>
> > > >
> > > > </html>
> > > >
> > > > Quoting Kris Schneider <kr...@dotech.com>:
> > > >
> > > > > 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 <r...@reumann.net>:
> > > > >
> > > > > > 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 <ma...@dotech.com>
> > > > > D.O.Tech <http://www.dotech.com/>
> > > >
> > >
> > >
> > > --
> > > Rick
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
> >
> >
>---------------------------------------------------------------------
> > 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
> >
>
>
>__________________________________
>Do you Yahoo!?
>SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
>
>---------------------------------------------------------------------
>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
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Kris Schneider <kr...@dotech.com>.
Quoting Michael Duffy <du...@yahoo.com>:
>
> It's my understanding that you ONLY get the default if
> there are no other constructors written. The minute
> you write ANY constructor, you're on your own. If you
> still want a default ctor, you've gotta supply it.
>
> I'll be happy to learn something if this is incorrect.
> - MOD
That's correct.
8< snip >8
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re[2]: [OT] Re: 4th Of July Struts Challenge...
Posted by Dirk Markert <di...@dr-markert.de>.
Hello Mark,
***************************************************************
MG> I have not found this
but I have:
If the source code for a class contains no declared constructors, the Java compiler
automatically supplies a constructor with no parameters. Adding one or more
constructor declarations to the source code of such a class will prevent this default
constructor from being supplied automatically, effectively deleting a constructor,
unless one of the new constructors also has no parameters, thus replacing the
default constructor.
JLS, page 267
MG> in the spec, but I believe the no-argument constructor
MG> is available at anytime for a concrete class. This would be a good one to
MG> test....
MG> -----Original Message-----
MG> From: Michael Duffy [mailto:duffymo@yahoo.com]
MG> Sent: Wednesday, July 16, 2003 10:27 AM
MG> To: Struts Users Mailing List
MG> Subject: RE: [OT] Re: 4th Of July Struts Challenge...
MG> It's my understanding that you ONLY get the default if
MG> there are no other constructors written. The minute
MG> you write ANY constructor, you're on your own. If you
MG> still want a default ctor, you've gotta supply it.
MG> I'll be happy to learn something if this is incorrect.
MG> - MOD
MG> --- Mark Galbreath <ma...@qat.com> wrote:
>> The no-argument constructor is the default and does
>> not have to be declared.
>> You have a 2-arg constructor. As for JSTL (or any
>> EL) acting like straight
>> scripting, I've never had an argument with using
>> scripting where
>> appropriate. Pragmatism should be the rule of the
>> day. Finally, I don't
>> know why declaring DynaActionForm beans as Maps
>> didn't work for me, but
>> neither is it a big issue. I realize the constraints
>> of declaring a variable
>> as a concrete/abstract class vs. as an interface.
>>
>> Besides, I like what you've created. :-)
>>
>> -----Original Message-----
>> From: Kris Schneider [mailto:kris@dotech.com]
>> Sent: Wednesday, July 16, 2003 8:55 AM
>> To: Struts Users Mailing List
>> Subject: RE: [OT] Re: 4th Of July Struts
>> Challenge...
>>
>>
>> Quoting Mark Galbreath <ma...@qat.com>:
>>
>> > 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.
>>
>> Not sure what you're doing, but the example works as
>> coded. If it matters,
>> post some details and we'll see if something needs
>> fixing.
>>
>> > 2. You may be using JSTL, but it still looks like
>> scripting to
>> > me.....
>>
>> Fair enough. What's your recommended alternative to
>> JSTL when using JSP for
>> your view layer?
>>
>> > 3. Strictly speaking, JavaBeans do not contain a
>> constructor and
>> > implement Serializable.
>>
>> Strictly speaking, a JavaBean *does* contain a
>> construtctor (or even more
>> than one), just like any other Java class. It's just
>> that a "real" bean
>> needs to have a no-arg constructor. The actual code
>> that I uploaded to Rick
>> includes a no-arg construtctor for EmployeeBean but
>> omitted implementing
>> Serializable or Externalizable. The bean also fails
>> to act as an event
>> source and it doesn't check for things like null
>> values passed to either its
>> construtctor or its set methods.
>>
>> > 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:
>> > > ------------------
>> > >
>> > > <form-beans>
>> > > <form-bean name="employeesForm"
>> > >
>> type="org.apache.struts.action.DynaActionForm">
>> > > <form-property name="employeesMap"
>> type="java.util.Map"/>
>> > > </form-bean>
>> > > </form-beans>
>> > >
>> > > <action-mappings>
>> > > <action path="/employees/edit"
>> > >
>> type="com.dotech.EditEmployeesAction"
>> > > name="employeesForm"
>> > > scope="session"
>> > > validate="false">
>> > > <forward name="success"
>> path="/editEmployees.jsp"/>
>> > > </action>
>> > > <action path="/employees/save"
>> > >
>> type="org.apache.struts.actions.ForwardAction"
>> > > parameter="/viewEmployees.jsp"
>> > > name="employeesForm"
>> > > scope="session"
>> > > validate="false"/>
>> > > </action-mappings>
>> > >
>> > >
>> > > 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 --%> <bean:struts
>> > > id="mapping"
>> mapping="/employees/save"/> <c:set
>> > > var="attribute" value="${mapping.attribute}"/>
>> <c:set var="scope"
>> > > value="${mapping.scope}"/> <c:choose>
>> > > <c:when test="${scope eq 'request'}">
>> > > <c:set var="form"
>> value="${requestScope[attribute]}"/>
>> > > </c:when>
>> > > <c:otherwise>
>> > > <c:set var="form"
>> value="${sessionScope[attribute]}"/>
>> > > </c:otherwise>
>> > > </c:choose>
>> > >
>> > > <html>
>> > >
>> > > <head><title>Edit Employees</title></head>
>> > >
>> > > <body>
>> > > <html:form action="/employees/save">
>> > > <table>
>> > > <c:forEach var="entry"
>> items="${form.map.employeesMap}">
>> > > <tr>
>> > > <td><c:out
>> value="${entry.key}"/></td>
>> > > <td>
>> > > <input type="text"
>> > > name="<c:out
>> > >
>> value="employeesMap(${entry.key}).name"/>"
>> > > value="<c:out
>> value="${entry.value.name}"/>">
>> > > </td>
>> > > <td>
>> > > <input type="text"
>> > > name="<c:out
>> > >
>> value="employeesMap(${entry.key}).age"/>"
>> > > value="<c:out
>> value="${entry.value.age}"/>">
>> > > </td>
>> > > </tr>
>> > > </c:forEach>
>> > > <tr>
>> > > <td align="center"
>> colspan="3"><html:submit/></td>
>> > > </tr>
>> > > </table>
>> > > </html:form>
>> > > </body>
>> > >
>> > > </html>
>> > >
>> > >
>> > > 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 --%> <bean:struts
>> > > id="mapping"
>> mapping="/employees/save"/> <c:set
>> > > var="attribute" value="${mapping.attribute}"/>
>> <c:set var="scope"
>> > > value="${mapping.scope}"/> <c:choose>
>> > > <c:when test="${scope eq 'request'}">
>> > > <c:set var="form"
>> value="${requestScope[attribute]}"/>
>> > > </c:when>
>> > > <c:otherwise>
>> > > <c:set var="form"
>> value="${sessionScope[attribute]}"/>
>> > > </c:otherwise>
>> > > </c:choose>
>> > >
>> > > <html>
>> > >
>> > > <head><title>View Employees</title></head>
>> > >
>> > > <body>
>> > > <table>
>> > > <c:forEach var="entry"
>> items="${form.map.employeesMap}">
>> > > <tr>
>> > > <td><c:out
>> value="${entry.key}"/></td>
>> > > <td><c:out
>> value="${entry.value.name}"/></td>
>> > > <td><c:out
>> value="${entry.value.age}"/></td>
>> > > </tr>
>> > > </c:forEach>
>> > > </table>
>> > > </body>
>> > >
>> > > </html>
>> > >
>> > > Quoting Kris Schneider <kr...@dotech.com>:
>> > >
>> > > > 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 <r...@reumann.net>:
>> > > >
>> > > > > 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 <ma...@dotech.com>
>> > > > D.O.Tech <http://www.dotech.com/>
>> > >
>> >
>> >
>> > --
>> > Rick
>>
>> --
>> Kris Schneider <ma...@dotech.com>
>> D.O.Tech <http://www.dotech.com/>
>>
>>
MG> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> struts-user-help@jakarta.apache.org
>>
>>
>>
>>
MG> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> struts-user-help@jakarta.apache.org
>>
MG> __________________________________
MG> Do you Yahoo!?
MG> SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
MG> ---------------------------------------------------------------------
MG> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
MG> For additional commands, e-mail: struts-user-help@jakarta.apache.org
MG> ---------------------------------------------------------------------
MG> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
MG> For additional commands, e-mail: struts-user-help@jakarta.apache.org
Regards,
Dirk
+------- Quality leads ---------------------------------------+
| Dirk Markert dirk.markert@dr-markert.de |
| Dr. Markert Softwaretechnik AG |
| Joseph-von-Fraunhofer-Str. 20 |
| 44227 Dortmund |
+---------------------------------->>>>>>> to success! <<<<<<-+
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Andrew Hill <an...@gridnode.com>.
I do not believe this to be the case. Indeed Im 99% certain it is not the
case.
I suppose I should bang together a class to prove this, but it will be more
fun to argue about it for a while yet ;-)
-----Original Message-----
From: Mark Galbreath [mailto:mark_galbreath@qat.com]
Sent: Wednesday, 16 July 2003 22:30
To: 'Struts Users Mailing List'
Subject: RE: [OT] Re: 4th Of July Struts Challenge...
I have not found this in the spec, but I believe the no-argument constructor
is available at anytime for a concrete class. This would be a good one to
test....
-----Original Message-----
From: Michael Duffy [mailto:duffymo@yahoo.com]
Sent: Wednesday, July 16, 2003 10:27 AM
To: Struts Users Mailing List
Subject: RE: [OT] Re: 4th Of July Struts Challenge...
It's my understanding that you ONLY get the default if
there are no other constructors written. The minute
you write ANY constructor, you're on your own. If you
still want a default ctor, you've gotta supply it.
I'll be happy to learn something if this is incorrect.
- MOD
--- Mark Galbreath <ma...@qat.com> wrote:
> The no-argument constructor is the default and does
> not have to be declared.
> You have a 2-arg constructor. As for JSTL (or any
> EL) acting like straight
> scripting, I've never had an argument with using
> scripting where
> appropriate. Pragmatism should be the rule of the
> day. Finally, I don't
> know why declaring DynaActionForm beans as Maps
> didn't work for me, but
> neither is it a big issue. I realize the constraints
> of declaring a variable
> as a concrete/abstract class vs. as an interface.
>
> Besides, I like what you've created. :-)
>
> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Wednesday, July 16, 2003 8:55 AM
> To: Struts Users Mailing List
> Subject: RE: [OT] Re: 4th Of July Struts
> Challenge...
>
>
> Quoting Mark Galbreath <ma...@qat.com>:
>
> > 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.
>
> Not sure what you're doing, but the example works as
> coded. If it matters,
> post some details and we'll see if something needs
> fixing.
>
> > 2. You may be using JSTL, but it still looks like
> scripting to
> > me.....
>
> Fair enough. What's your recommended alternative to
> JSTL when using JSP for
> your view layer?
>
> > 3. Strictly speaking, JavaBeans do not contain a
> constructor and
> > implement Serializable.
>
> Strictly speaking, a JavaBean *does* contain a
> construtctor (or even more
> than one), just like any other Java class. It's just
> that a "real" bean
> needs to have a no-arg constructor. The actual code
> that I uploaded to Rick
> includes a no-arg construtctor for EmployeeBean but
> omitted implementing
> Serializable or Externalizable. The bean also fails
> to act as an event
> source and it doesn't check for things like null
> values passed to either its
> construtctor or its set methods.
>
> > 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:
> > > ------------------
> > >
> > > <form-beans>
> > > <form-bean name="employeesForm"
> > >
> type="org.apache.struts.action.DynaActionForm">
> > > <form-property name="employeesMap"
> type="java.util.Map"/>
> > > </form-bean>
> > > </form-beans>
> > >
> > > <action-mappings>
> > > <action path="/employees/edit"
> > >
> type="com.dotech.EditEmployeesAction"
> > > name="employeesForm"
> > > scope="session"
> > > validate="false">
> > > <forward name="success"
> path="/editEmployees.jsp"/>
> > > </action>
> > > <action path="/employees/save"
> > >
> type="org.apache.struts.actions.ForwardAction"
> > > parameter="/viewEmployees.jsp"
> > > name="employeesForm"
> > > scope="session"
> > > validate="false"/>
> > > </action-mappings>
> > >
> > >
> > > 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 --%> <bean:struts
> > > id="mapping"
> mapping="/employees/save"/> <c:set
> > > var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope"
> > > value="${mapping.scope}"/> <c:choose>
> > > <c:when test="${scope eq 'request'}">
> > > <c:set var="form"
> value="${requestScope[attribute]}"/>
> > > </c:when>
> > > <c:otherwise>
> > > <c:set var="form"
> value="${sessionScope[attribute]}"/>
> > > </c:otherwise>
> > > </c:choose>
> > >
> > > <html>
> > >
> > > <head><title>Edit Employees</title></head>
> > >
> > > <body>
> > > <html:form action="/employees/save">
> > > <table>
> > > <c:forEach var="entry"
> items="${form.map.employeesMap}">
> > > <tr>
> > > <td><c:out
> value="${entry.key}"/></td>
> > > <td>
> > > <input type="text"
> > > name="<c:out
> > >
> value="employeesMap(${entry.key}).name"/>"
> > > value="<c:out
> value="${entry.value.name}"/>">
> > > </td>
> > > <td>
> > > <input type="text"
> > > name="<c:out
> > >
> value="employeesMap(${entry.key}).age"/>"
> > > value="<c:out
> value="${entry.value.age}"/>">
> > > </td>
> > > </tr>
> > > </c:forEach>
> > > <tr>
> > > <td align="center"
> colspan="3"><html:submit/></td>
> > > </tr>
> > > </table>
> > > </html:form>
> > > </body>
> > >
> > > </html>
> > >
> > >
> > > 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 --%> <bean:struts
> > > id="mapping"
> mapping="/employees/save"/> <c:set
> > > var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope"
> > > value="${mapping.scope}"/> <c:choose>
> > > <c:when test="${scope eq 'request'}">
> > > <c:set var="form"
> value="${requestScope[attribute]}"/>
> > > </c:when>
> > > <c:otherwise>
> > > <c:set var="form"
> value="${sessionScope[attribute]}"/>
> > > </c:otherwise>
> > > </c:choose>
> > >
> > > <html>
> > >
> > > <head><title>View Employees</title></head>
> > >
> > > <body>
> > > <table>
> > > <c:forEach var="entry"
> items="${form.map.employeesMap}">
> > > <tr>
> > > <td><c:out
> value="${entry.key}"/></td>
> > > <td><c:out
> value="${entry.value.name}"/></td>
> > > <td><c:out
> value="${entry.value.age}"/></td>
> > > </tr>
> > > </c:forEach>
> > > </table>
> > > </body>
> > >
> > > </html>
> > >
> > > Quoting Kris Schneider <kr...@dotech.com>:
> > >
> > > > 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 <r...@reumann.net>:
> > > >
> > > > > 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();
Map.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 ne
w 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 <ma...@dotech.com>
> > > > D.O.Tech <http://www.dotech.com/>
> > >
> >
> >
> > --
> > Rick
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
>
---------------------------------------------------------------------
> 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
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
---------------------------------------------------------------------
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
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Mark Galbreath <ma...@qat.com>.
I have not found this in the spec, but I believe the no-argument constructor
is available at anytime for a concrete class. This would be a good one to
test....
-----Original Message-----
From: Michael Duffy [mailto:duffymo@yahoo.com]
Sent: Wednesday, July 16, 2003 10:27 AM
To: Struts Users Mailing List
Subject: RE: [OT] Re: 4th Of July Struts Challenge...
It's my understanding that you ONLY get the default if
there are no other constructors written. The minute
you write ANY constructor, you're on your own. If you
still want a default ctor, you've gotta supply it.
I'll be happy to learn something if this is incorrect.
- MOD
--- Mark Galbreath <ma...@qat.com> wrote:
> The no-argument constructor is the default and does
> not have to be declared.
> You have a 2-arg constructor. As for JSTL (or any
> EL) acting like straight
> scripting, I've never had an argument with using
> scripting where
> appropriate. Pragmatism should be the rule of the
> day. Finally, I don't
> know why declaring DynaActionForm beans as Maps
> didn't work for me, but
> neither is it a big issue. I realize the constraints
> of declaring a variable
> as a concrete/abstract class vs. as an interface.
>
> Besides, I like what you've created. :-)
>
> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Wednesday, July 16, 2003 8:55 AM
> To: Struts Users Mailing List
> Subject: RE: [OT] Re: 4th Of July Struts
> Challenge...
>
>
> Quoting Mark Galbreath <ma...@qat.com>:
>
> > 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.
>
> Not sure what you're doing, but the example works as
> coded. If it matters,
> post some details and we'll see if something needs
> fixing.
>
> > 2. You may be using JSTL, but it still looks like
> scripting to
> > me.....
>
> Fair enough. What's your recommended alternative to
> JSTL when using JSP for
> your view layer?
>
> > 3. Strictly speaking, JavaBeans do not contain a
> constructor and
> > implement Serializable.
>
> Strictly speaking, a JavaBean *does* contain a
> construtctor (or even more
> than one), just like any other Java class. It's just
> that a "real" bean
> needs to have a no-arg constructor. The actual code
> that I uploaded to Rick
> includes a no-arg construtctor for EmployeeBean but
> omitted implementing
> Serializable or Externalizable. The bean also fails
> to act as an event
> source and it doesn't check for things like null
> values passed to either its
> construtctor or its set methods.
>
> > 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:
> > > ------------------
> > >
> > > <form-beans>
> > > <form-bean name="employeesForm"
> > >
> type="org.apache.struts.action.DynaActionForm">
> > > <form-property name="employeesMap"
> type="java.util.Map"/>
> > > </form-bean>
> > > </form-beans>
> > >
> > > <action-mappings>
> > > <action path="/employees/edit"
> > >
> type="com.dotech.EditEmployeesAction"
> > > name="employeesForm"
> > > scope="session"
> > > validate="false">
> > > <forward name="success"
> path="/editEmployees.jsp"/>
> > > </action>
> > > <action path="/employees/save"
> > >
> type="org.apache.struts.actions.ForwardAction"
> > > parameter="/viewEmployees.jsp"
> > > name="employeesForm"
> > > scope="session"
> > > validate="false"/>
> > > </action-mappings>
> > >
> > >
> > > 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 --%> <bean:struts
> > > id="mapping"
> mapping="/employees/save"/> <c:set
> > > var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope"
> > > value="${mapping.scope}"/> <c:choose>
> > > <c:when test="${scope eq 'request'}">
> > > <c:set var="form"
> value="${requestScope[attribute]}"/>
> > > </c:when>
> > > <c:otherwise>
> > > <c:set var="form"
> value="${sessionScope[attribute]}"/>
> > > </c:otherwise>
> > > </c:choose>
> > >
> > > <html>
> > >
> > > <head><title>Edit Employees</title></head>
> > >
> > > <body>
> > > <html:form action="/employees/save">
> > > <table>
> > > <c:forEach var="entry"
> items="${form.map.employeesMap}">
> > > <tr>
> > > <td><c:out
> value="${entry.key}"/></td>
> > > <td>
> > > <input type="text"
> > > name="<c:out
> > >
> value="employeesMap(${entry.key}).name"/>"
> > > value="<c:out
> value="${entry.value.name}"/>">
> > > </td>
> > > <td>
> > > <input type="text"
> > > name="<c:out
> > >
> value="employeesMap(${entry.key}).age"/>"
> > > value="<c:out
> value="${entry.value.age}"/>">
> > > </td>
> > > </tr>
> > > </c:forEach>
> > > <tr>
> > > <td align="center"
> colspan="3"><html:submit/></td>
> > > </tr>
> > > </table>
> > > </html:form>
> > > </body>
> > >
> > > </html>
> > >
> > >
> > > 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 --%> <bean:struts
> > > id="mapping"
> mapping="/employees/save"/> <c:set
> > > var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope"
> > > value="${mapping.scope}"/> <c:choose>
> > > <c:when test="${scope eq 'request'}">
> > > <c:set var="form"
> value="${requestScope[attribute]}"/>
> > > </c:when>
> > > <c:otherwise>
> > > <c:set var="form"
> value="${sessionScope[attribute]}"/>
> > > </c:otherwise>
> > > </c:choose>
> > >
> > > <html>
> > >
> > > <head><title>View Employees</title></head>
> > >
> > > <body>
> > > <table>
> > > <c:forEach var="entry"
> items="${form.map.employeesMap}">
> > > <tr>
> > > <td><c:out
> value="${entry.key}"/></td>
> > > <td><c:out
> value="${entry.value.name}"/></td>
> > > <td><c:out
> value="${entry.value.age}"/></td>
> > > </tr>
> > > </c:forEach>
> > > </table>
> > > </body>
> > >
> > > </html>
> > >
> > > Quoting Kris Schneider <kr...@dotech.com>:
> > >
> > > > 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 <r...@reumann.net>:
> > > >
> > > > > 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 <ma...@dotech.com>
> > > > D.O.Tech <http://www.dotech.com/>
> > >
> >
> >
> > --
> > Rick
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
>
---------------------------------------------------------------------
> 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
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
---------------------------------------------------------------------
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
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Michael Duffy <du...@yahoo.com>.
It's my understanding that you ONLY get the default if
there are no other constructors written. The minute
you write ANY constructor, you're on your own. If you
still want a default ctor, you've gotta supply it.
I'll be happy to learn something if this is incorrect.
- MOD
--- Mark Galbreath <ma...@qat.com> wrote:
> The no-argument constructor is the default and does
> not have to be declared.
> You have a 2-arg constructor. As for JSTL (or any
> EL) acting like straight
> scripting, I've never had an argument with using
> scripting where
> appropriate. Pragmatism should be the rule of the
> day. Finally, I don't
> know why declaring DynaActionForm beans as Maps
> didn't work for me, but
> neither is it a big issue. I realize the constraints
> of declaring a variable
> as a concrete/abstract class vs. as an interface.
>
> Besides, I like what you've created. :-)
>
> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Wednesday, July 16, 2003 8:55 AM
> To: Struts Users Mailing List
> Subject: RE: [OT] Re: 4th Of July Struts
> Challenge...
>
>
> Quoting Mark Galbreath <ma...@qat.com>:
>
> > 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.
>
> Not sure what you're doing, but the example works as
> coded. If it matters,
> post some details and we'll see if something needs
> fixing.
>
> > 2. You may be using JSTL, but it still looks like
> scripting to
> > me.....
>
> Fair enough. What's your recommended alternative to
> JSTL when using JSP for
> your view layer?
>
> > 3. Strictly speaking, JavaBeans do not contain a
> constructor and
> > implement Serializable.
>
> Strictly speaking, a JavaBean *does* contain a
> construtctor (or even more
> than one), just like any other Java class. It's just
> that a "real" bean
> needs to have a no-arg constructor. The actual code
> that I uploaded to Rick
> includes a no-arg construtctor for EmployeeBean but
> omitted implementing
> Serializable or Externalizable. The bean also fails
> to act as an event
> source and it doesn't check for things like null
> values passed to either its
> construtctor or its set methods.
>
> > 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:
> > > ------------------
> > >
> > > <form-beans>
> > > <form-bean name="employeesForm"
> > >
> type="org.apache.struts.action.DynaActionForm">
> > > <form-property name="employeesMap"
> type="java.util.Map"/>
> > > </form-bean>
> > > </form-beans>
> > >
> > > <action-mappings>
> > > <action path="/employees/edit"
> > >
> type="com.dotech.EditEmployeesAction"
> > > name="employeesForm"
> > > scope="session"
> > > validate="false">
> > > <forward name="success"
> path="/editEmployees.jsp"/>
> > > </action>
> > > <action path="/employees/save"
> > >
> type="org.apache.struts.actions.ForwardAction"
> > > parameter="/viewEmployees.jsp"
> > > name="employeesForm"
> > > scope="session"
> > > validate="false"/>
> > > </action-mappings>
> > >
> > >
> > > 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 --%>
> > > <bean:struts id="mapping"
> mapping="/employees/save"/> <c:set
> > > var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope"
> > > value="${mapping.scope}"/> <c:choose>
> > > <c:when test="${scope eq 'request'}">
> > > <c:set var="form"
> value="${requestScope[attribute]}"/>
> > > </c:when>
> > > <c:otherwise>
> > > <c:set var="form"
> value="${sessionScope[attribute]}"/>
> > > </c:otherwise>
> > > </c:choose>
> > >
> > > <html>
> > >
> > > <head><title>Edit Employees</title></head>
> > >
> > > <body>
> > > <html:form action="/employees/save">
> > > <table>
> > > <c:forEach var="entry"
> items="${form.map.employeesMap}">
> > > <tr>
> > > <td><c:out
> value="${entry.key}"/></td>
> > > <td>
> > > <input type="text"
> > > name="<c:out
> > >
> value="employeesMap(${entry.key}).name"/>"
> > > value="<c:out
> value="${entry.value.name}"/>">
> > > </td>
> > > <td>
> > > <input type="text"
> > > name="<c:out
> > >
> value="employeesMap(${entry.key}).age"/>"
> > > value="<c:out
> value="${entry.value.age}"/>">
> > > </td>
> > > </tr>
> > > </c:forEach>
> > > <tr>
> > > <td align="center"
> colspan="3"><html:submit/></td>
> > > </tr>
> > > </table>
> > > </html:form>
> > > </body>
> > >
> > > </html>
> > >
> > >
> > > 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 --%>
> > > <bean:struts id="mapping"
> mapping="/employees/save"/> <c:set
> > > var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope"
> > > value="${mapping.scope}"/> <c:choose>
> > > <c:when test="${scope eq 'request'}">
> > > <c:set var="form"
> value="${requestScope[attribute]}"/>
> > > </c:when>
> > > <c:otherwise>
> > > <c:set var="form"
> value="${sessionScope[attribute]}"/>
> > > </c:otherwise>
> > > </c:choose>
> > >
> > > <html>
> > >
> > > <head><title>View Employees</title></head>
> > >
> > > <body>
> > > <table>
> > > <c:forEach var="entry"
> items="${form.map.employeesMap}">
> > > <tr>
> > > <td><c:out
> value="${entry.key}"/></td>
> > > <td><c:out
> value="${entry.value.name}"/></td>
> > > <td><c:out
> value="${entry.value.age}"/></td>
> > > </tr>
> > > </c:forEach>
> > > </table>
> > > </body>
> > >
> > > </html>
> > >
> > > Quoting Kris Schneider <kr...@dotech.com>:
> > >
> > > > 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 <r...@reumann.net>:
> > > >
> > > > > 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 <ma...@dotech.com>
> > > > D.O.Tech <http://www.dotech.com/>
> > >
> >
> >
> > --
> > Rick
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
>
---------------------------------------------------------------------
> 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
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Mark Galbreath <ma...@qat.com>.
The no-argument constructor is the default and does not have to be declared.
You have a 2-arg constructor. As for JSTL (or any EL) acting like straight
scripting, I've never had an argument with using scripting where
appropriate. Pragmatism should be the rule of the day. Finally, I don't
know why declaring DynaActionForm beans as Maps didn't work for me, but
neither is it a big issue. I realize the constraints of declaring a variable
as a concrete/abstract class vs. as an interface.
Besides, I like what you've created. :-)
-----Original Message-----
From: Kris Schneider [mailto:kris@dotech.com]
Sent: Wednesday, July 16, 2003 8:55 AM
To: Struts Users Mailing List
Subject: RE: [OT] Re: 4th Of July Struts Challenge...
Quoting Mark Galbreath <ma...@qat.com>:
> 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.
Not sure what you're doing, but the example works as coded. If it matters,
post some details and we'll see if something needs fixing.
> 2. You may be using JSTL, but it still looks like scripting to
> me.....
Fair enough. What's your recommended alternative to JSTL when using JSP for
your view layer?
> 3. Strictly speaking, JavaBeans do not contain a constructor and
> implement Serializable.
Strictly speaking, a JavaBean *does* contain a construtctor (or even more
than one), just like any other Java class. It's just that a "real" bean
needs to have a no-arg constructor. The actual code that I uploaded to Rick
includes a no-arg construtctor for EmployeeBean but omitted implementing
Serializable or Externalizable. The bean also fails to act as an event
source and it doesn't check for things like null values passed to either its
construtctor or its set methods.
> 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:
> > ------------------
> >
> > <form-beans>
> > <form-bean name="employeesForm"
> > type="org.apache.struts.action.DynaActionForm">
> > <form-property name="employeesMap" type="java.util.Map"/>
> > </form-bean>
> > </form-beans>
> >
> > <action-mappings>
> > <action path="/employees/edit"
> > type="com.dotech.EditEmployeesAction"
> > name="employeesForm"
> > scope="session"
> > validate="false">
> > <forward name="success" path="/editEmployees.jsp"/>
> > </action>
> > <action path="/employees/save"
> > type="org.apache.struts.actions.ForwardAction"
> > parameter="/viewEmployees.jsp"
> > name="employeesForm"
> > scope="session"
> > validate="false"/>
> > </action-mappings>
> >
> >
> > 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 --%>
> > <bean:struts id="mapping" mapping="/employees/save"/> <c:set
> > var="attribute" value="${mapping.attribute}"/> <c:set var="scope"
> > value="${mapping.scope}"/> <c:choose>
> > <c:when test="${scope eq 'request'}">
> > <c:set var="form" value="${requestScope[attribute]}"/>
> > </c:when>
> > <c:otherwise>
> > <c:set var="form" value="${sessionScope[attribute]}"/>
> > </c:otherwise>
> > </c:choose>
> >
> > <html>
> >
> > <head><title>Edit Employees</title></head>
> >
> > <body>
> > <html:form action="/employees/save">
> > <table>
> > <c:forEach var="entry" items="${form.map.employeesMap}">
> > <tr>
> > <td><c:out value="${entry.key}"/></td>
> > <td>
> > <input type="text"
> > name="<c:out
> > value="employeesMap(${entry.key}).name"/>"
> > value="<c:out value="${entry.value.name}"/>">
> > </td>
> > <td>
> > <input type="text"
> > name="<c:out
> > value="employeesMap(${entry.key}).age"/>"
> > value="<c:out value="${entry.value.age}"/>">
> > </td>
> > </tr>
> > </c:forEach>
> > <tr>
> > <td align="center" colspan="3"><html:submit/></td>
> > </tr>
> > </table>
> > </html:form>
> > </body>
> >
> > </html>
> >
> >
> > 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 --%>
> > <bean:struts id="mapping" mapping="/employees/save"/> <c:set
> > var="attribute" value="${mapping.attribute}"/> <c:set var="scope"
> > value="${mapping.scope}"/> <c:choose>
> > <c:when test="${scope eq 'request'}">
> > <c:set var="form" value="${requestScope[attribute]}"/>
> > </c:when>
> > <c:otherwise>
> > <c:set var="form" value="${sessionScope[attribute]}"/>
> > </c:otherwise>
> > </c:choose>
> >
> > <html>
> >
> > <head><title>View Employees</title></head>
> >
> > <body>
> > <table>
> > <c:forEach var="entry" items="${form.map.employeesMap}">
> > <tr>
> > <td><c:out value="${entry.key}"/></td>
> > <td><c:out value="${entry.value.name}"/></td>
> > <td><c:out value="${entry.value.age}"/></td>
> > </tr>
> > </c:forEach>
> > </table>
> > </body>
> >
> > </html>
> >
> > Quoting Kris Schneider <kr...@dotech.com>:
> >
> > > 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 <r...@reumann.net>:
> > >
> > > > 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 <ma...@dotech.com>
> > > D.O.Tech <http://www.dotech.com/>
> >
>
>
> --
> Rick
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
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
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Kris Schneider <kr...@dotech.com>.
Quoting Mark Galbreath <ma...@qat.com>:
> 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.
Not sure what you're doing, but the example works as coded. If it matters, post
some details and we'll see if something needs fixing.
> 2. You may be using JSTL, but it still looks like scripting to me.....
Fair enough. What's your recommended alternative to JSTL when using JSP for your
view layer?
> 3. Strictly speaking, JavaBeans do not contain a constructor and implement
> Serializable.
Strictly speaking, a JavaBean *does* contain a construtctor (or even more than
one), just like any other Java class. It's just that a "real" bean needs to have
a no-arg constructor. The actual code that I uploaded to Rick includes a no-arg
construtctor for EmployeeBean but omitted implementing Serializable or
Externalizable. The bean also fails to act as an event source and it doesn't
check for things like null values passed to either its construtctor or its set
methods.
> 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:
> > ------------------
> >
> > <form-beans>
> > <form-bean name="employeesForm"
> > type="org.apache.struts.action.DynaActionForm">
> > <form-property name="employeesMap" type="java.util.Map"/>
> > </form-bean>
> > </form-beans>
> >
> > <action-mappings>
> > <action path="/employees/edit"
> > type="com.dotech.EditEmployeesAction"
> > name="employeesForm"
> > scope="session"
> > validate="false">
> > <forward name="success" path="/editEmployees.jsp"/>
> > </action>
> > <action path="/employees/save"
> > type="org.apache.struts.actions.ForwardAction"
> > parameter="/viewEmployees.jsp"
> > name="employeesForm"
> > scope="session"
> > validate="false"/>
> > </action-mappings>
> >
> >
> > 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 --%>
> > <bean:struts id="mapping" mapping="/employees/save"/>
> > <c:set var="attribute" value="${mapping.attribute}"/>
> > <c:set var="scope" value="${mapping.scope}"/>
> > <c:choose>
> > <c:when test="${scope eq 'request'}">
> > <c:set var="form" value="${requestScope[attribute]}"/>
> > </c:when>
> > <c:otherwise>
> > <c:set var="form" value="${sessionScope[attribute]}"/>
> > </c:otherwise>
> > </c:choose>
> >
> > <html>
> >
> > <head><title>Edit Employees</title></head>
> >
> > <body>
> > <html:form action="/employees/save">
> > <table>
> > <c:forEach var="entry" items="${form.map.employeesMap}">
> > <tr>
> > <td><c:out value="${entry.key}"/></td>
> > <td>
> > <input type="text"
> > name="<c:out
> > value="employeesMap(${entry.key}).name"/>"
> > value="<c:out value="${entry.value.name}"/>">
> > </td>
> > <td>
> > <input type="text"
> > name="<c:out
> > value="employeesMap(${entry.key}).age"/>"
> > value="<c:out value="${entry.value.age}"/>">
> > </td>
> > </tr>
> > </c:forEach>
> > <tr>
> > <td align="center" colspan="3"><html:submit/></td>
> > </tr>
> > </table>
> > </html:form>
> > </body>
> >
> > </html>
> >
> >
> > 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 --%>
> > <bean:struts id="mapping" mapping="/employees/save"/>
> > <c:set var="attribute" value="${mapping.attribute}"/>
> > <c:set var="scope" value="${mapping.scope}"/>
> > <c:choose>
> > <c:when test="${scope eq 'request'}">
> > <c:set var="form" value="${requestScope[attribute]}"/>
> > </c:when>
> > <c:otherwise>
> > <c:set var="form" value="${sessionScope[attribute]}"/>
> > </c:otherwise>
> > </c:choose>
> >
> > <html>
> >
> > <head><title>View Employees</title></head>
> >
> > <body>
> > <table>
> > <c:forEach var="entry" items="${form.map.employeesMap}">
> > <tr>
> > <td><c:out value="${entry.key}"/></td>
> > <td><c:out value="${entry.value.name}"/></td>
> > <td><c:out value="${entry.value.age}"/></td>
> > </tr>
> > </c:forEach>
> > </table>
> > </body>
> >
> > </html>
> >
> > Quoting Kris Schneider <kr...@dotech.com>:
> >
> > > 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 <r...@reumann.net>:
> > >
> > > > 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 <ma...@dotech.com>
> > > D.O.Tech <http://www.dotech.com/>
> >
>
>
> --
> Rick
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Mark Galbreath <ma...@qat.com>.
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...
<snip>
Strictly speaking, JavaBeans do not contain a constructor and implement
Serializable. </snip>
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:
> ------------------
>
> <form-beans>
> <form-bean name="employeesForm"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="employeesMap" type="java.util.Map"/>
> </form-bean>
> </form-beans>
>
> <action-mappings>
> <action path="/employees/edit"
> type="com.dotech.EditEmployeesAction"
> name="employeesForm"
> scope="session"
> validate="false">
> <forward name="success" path="/editEmployees.jsp"/>
> </action>
> <action path="/employees/save"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/viewEmployees.jsp"
> name="employeesForm"
> scope="session"
> validate="false"/>
> </action-mappings>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>Edit Employees</title></head>
>
> <body>
> <html:form action="/employees/save">
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).name"/>"
> value="<c:out value="${entry.value.name}"/>">
> </td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).age"/>"
> value="<c:out value="${entry.value.age}"/>">
> </td>
> </tr>
> </c:forEach>
> <tr>
> <td align="center" colspan="3"><html:submit/></td>
> </tr>
> </table>
> </html:form>
> </body>
>
> </html>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>View Employees</title></head>
>
> <body>
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td><c:out value="${entry.value.name}"/></td>
> <td><c:out value="${entry.value.age}"/></td>
> </tr>
> </c:forEach>
> </table>
> </body>
>
> </html>
>
> Quoting Kris Schneider <kr...@dotech.com>:
>
> > 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 <r...@reumann.net>:
> >
> > > 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 <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
>
--
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
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Andrew Hill <an...@gridnode.com>.
<snip>
Strictly speaking, JavaBeans do not contain a constructor and implement
Serializable.
</snip>
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:
> ------------------
>
> <form-beans>
> <form-bean name="employeesForm"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="employeesMap" type="java.util.Map"/>
> </form-bean>
> </form-beans>
>
> <action-mappings>
> <action path="/employees/edit"
> type="com.dotech.EditEmployeesAction"
> name="employeesForm"
> scope="session"
> validate="false">
> <forward name="success" path="/editEmployees.jsp"/>
> </action>
> <action path="/employees/save"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/viewEmployees.jsp"
> name="employeesForm"
> scope="session"
> validate="false"/>
> </action-mappings>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>Edit Employees</title></head>
>
> <body>
> <html:form action="/employees/save">
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).name"/>"
> value="<c:out value="${entry.value.name}"/>">
> </td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).age"/>"
> value="<c:out value="${entry.value.age}"/>">
> </td>
> </tr>
> </c:forEach>
> <tr>
> <td align="center" colspan="3"><html:submit/></td>
> </tr>
> </table>
> </html:form>
> </body>
>
> </html>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>View Employees</title></head>
>
> <body>
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td><c:out value="${entry.value.name}"/></td>
> <td><c:out value="${entry.value.age}"/></td>
> </tr>
> </c:forEach>
> </table>
> </body>
>
> </html>
>
> Quoting Kris Schneider <kr...@dotech.com>:
>
> > 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 <r...@reumann.net>:
> >
> > > 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 <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
>
--
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
RE: [OT] Re: 4th Of July Struts Challenge...
Posted by Mark Galbreath <ma...@qat.com>.
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:
> ------------------
>
> <form-beans>
> <form-bean name="employeesForm"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="employeesMap" type="java.util.Map"/>
> </form-bean>
> </form-beans>
>
> <action-mappings>
> <action path="/employees/edit"
> type="com.dotech.EditEmployeesAction"
> name="employeesForm"
> scope="session"
> validate="false">
> <forward name="success" path="/editEmployees.jsp"/>
> </action>
> <action path="/employees/save"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/viewEmployees.jsp"
> name="employeesForm"
> scope="session"
> validate="false"/>
> </action-mappings>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>Edit Employees</title></head>
>
> <body>
> <html:form action="/employees/save">
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).name"/>"
> value="<c:out value="${entry.value.name}"/>">
> </td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).age"/>"
> value="<c:out value="${entry.value.age}"/>">
> </td>
> </tr>
> </c:forEach>
> <tr>
> <td align="center" colspan="3"><html:submit/></td>
> </tr>
> </table>
> </html:form>
> </body>
>
> </html>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>View Employees</title></head>
>
> <body>
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td><c:out value="${entry.value.name}"/></td>
> <td><c:out value="${entry.value.age}"/></td>
> </tr>
> </c:forEach>
> </table>
> </body>
>
> </html>
>
> Quoting Kris Schneider <kr...@dotech.com>:
>
> > 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 <r...@reumann.net>:
> >
> > > 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 <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
>
--
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
[OT] Re: 4th Of July Struts Challenge...
Posted by Rick Reumann <r...@reumann.net>.
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:
> ------------------
>
> <form-beans>
> <form-bean name="employeesForm"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="employeesMap" type="java.util.Map"/>
> </form-bean>
> </form-beans>
>
> <action-mappings>
> <action path="/employees/edit"
> type="com.dotech.EditEmployeesAction"
> name="employeesForm"
> scope="session"
> validate="false">
> <forward name="success" path="/editEmployees.jsp"/>
> </action>
> <action path="/employees/save"
> type="org.apache.struts.actions.ForwardAction"
> parameter="/viewEmployees.jsp"
> name="employeesForm"
> scope="session"
> validate="false"/>
> </action-mappings>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>Edit Employees</title></head>
>
> <body>
> <html:form action="/employees/save">
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).name"/>"
> value="<c:out value="${entry.value.name}"/>">
> </td>
> <td>
> <input type="text"
> name="<c:out
> value="employeesMap(${entry.key}).age"/>"
> value="<c:out value="${entry.value.age}"/>">
> </td>
> </tr>
> </c:forEach>
> <tr>
> <td align="center" colspan="3"><html:submit/></td>
> </tr>
> </table>
> </html:form>
> </body>
>
> </html>
>
>
> 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 --%>
> <bean:struts id="mapping" mapping="/employees/save"/>
> <c:set var="attribute" value="${mapping.attribute}"/>
> <c:set var="scope" value="${mapping.scope}"/>
> <c:choose>
> <c:when test="${scope eq 'request'}">
> <c:set var="form" value="${requestScope[attribute]}"/>
> </c:when>
> <c:otherwise>
> <c:set var="form" value="${sessionScope[attribute]}"/>
> </c:otherwise>
> </c:choose>
>
> <html>
>
> <head><title>View Employees</title></head>
>
> <body>
> <table>
> <c:forEach var="entry" items="${form.map.employeesMap}">
> <tr>
> <td><c:out value="${entry.key}"/></td>
> <td><c:out value="${entry.value.name}"/></td>
> <td><c:out value="${entry.value.age}"/></td>
> </tr>
> </c:forEach>
> </table>
> </body>
>
> </html>
>
> Quoting Kris Schneider <kr...@dotech.com>:
>
> > 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 <r...@reumann.net>:
> >
> > > 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 <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
>
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: 4th Of July Struts Challenge...
Posted by Kris Schneider <kr...@dotech.com>.
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:
------------------
<form-beans>
<form-bean name="employeesForm"
type="org.apache.struts.action.DynaActionForm">
<form-property name="employeesMap" type="java.util.Map"/>
</form-bean>
</form-beans>
<action-mappings>
<action path="/employees/edit"
type="com.dotech.EditEmployeesAction"
name="employeesForm"
scope="session"
validate="false">
<forward name="success" path="/editEmployees.jsp"/>
</action>
<action path="/employees/save"
type="org.apache.struts.actions.ForwardAction"
parameter="/viewEmployees.jsp"
name="employeesForm"
scope="session"
validate="false"/>
</action-mappings>
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 --%>
<bean:struts id="mapping" mapping="/employees/save"/>
<c:set var="attribute" value="${mapping.attribute}"/>
<c:set var="scope" value="${mapping.scope}"/>
<c:choose>
<c:when test="${scope eq 'request'}">
<c:set var="form" value="${requestScope[attribute]}"/>
</c:when>
<c:otherwise>
<c:set var="form" value="${sessionScope[attribute]}"/>
</c:otherwise>
</c:choose>
<html>
<head><title>Edit Employees</title></head>
<body>
<html:form action="/employees/save">
<table>
<c:forEach var="entry" items="${form.map.employeesMap}">
<tr>
<td><c:out value="${entry.key}"/></td>
<td>
<input type="text"
name="<c:out value="employeesMap(${entry.key}).name"/>"
value="<c:out value="${entry.value.name}"/>">
</td>
<td>
<input type="text"
name="<c:out value="employeesMap(${entry.key}).age"/>"
value="<c:out value="${entry.value.age}"/>">
</td>
</tr>
</c:forEach>
<tr>
<td align="center" colspan="3"><html:submit/></td>
</tr>
</table>
</html:form>
</body>
</html>
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 --%>
<bean:struts id="mapping" mapping="/employees/save"/>
<c:set var="attribute" value="${mapping.attribute}"/>
<c:set var="scope" value="${mapping.scope}"/>
<c:choose>
<c:when test="${scope eq 'request'}">
<c:set var="form" value="${requestScope[attribute]}"/>
</c:when>
<c:otherwise>
<c:set var="form" value="${sessionScope[attribute]}"/>
</c:otherwise>
</c:choose>
<html>
<head><title>View Employees</title></head>
<body>
<table>
<c:forEach var="entry" items="${form.map.employeesMap}">
<tr>
<td><c:out value="${entry.key}"/></td>
<td><c:out value="${entry.value.name}"/></td>
<td><c:out value="${entry.value.age}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
Quoting Kris Schneider <kr...@dotech.com>:
> 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 <r...@reumann.net>:
>
> > 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 <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: 4th Of July Struts Challenge...
Posted by Kris Schneider <kr...@dotech.com>.
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 <r...@reumann.net>:
> 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 <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: 4th Of July Struts Challenge...
Posted by Mark Galbreath <ma...@qat.com>.
Piece of cake:
Problem: How to have dynamically-generated String data from a database
populate fields in a JSP form, have that data set the keys and values of a
DynaActionForm bean of type HashMap, and propogate any changes to the
database and display changes in real time to the user.
Elements:
1. JSP form page that retrieves records from the db by userid and date;
2. struts_config.xml defining the DynaActionForm Map beans and action
forwards;
3. Action class to process the user events in the JSP form;
4. DAO to trasfer data to and from the db;
5. A shit load of luck.
Code:
1. JSP:
<%-- the DynaActionForm bean --%>
<logic:present name="adminForm" scope="session">
<%-- the userid bean to bring it into page scope as a matter of convenience
--%>
<bean:define name="userid"
property="value"
type="java.lang.String"
id="key"/>
<%-- the logic to display the correct true checkboxes;
a radio btn cannot be used because multiple records requires that
the value be the userid and the true|false aspect of the checkbox is
discriminated by the name; --%>
<logic:equal name="adminForm" property="<%= "approved(" + key + ")"
%>" value="checked" scope="session">
<input type="checkbox"
name="approve"
value="<bean:write name="userid"
property="value"/>"
checked/>
APPROVE Expense Report for <bean:write name="userid"
property="value"/>
<input type="checkbox"
name="disapprove"
value="<bean:write name="userid"
property="value"/>"/>
DISAPPROVE Expense Report for <bean:write name="userid"
property="value"/>
</logic:equal>
<logic:equal name="adminForm" property="<%= "approved(" + key + ")"
%>" value="NO" scope="session">
<input type="checkbox"
name="approve"
value="<bean:write name="userid"
property="value"/>"/>
APPROVE Expense Report for <bean:write name="userid"
property="value"/>
<input type="checkbox"
name="disapprove"
value="<bean:write name="userid"
property="value"/>"
checked/>
DISAPPROVE Expense Report for <bean:write name="userid"
property="value"/>
</logic:equal>
</logic:present>
2. relevant struts-config.xml:
<form-bean name="adminForm" type="org.apache.struts.action.DynaActionForm">
<!-- globals -->
<form-property name="approved" type="java.util.HashMap"/>
</form-bean>
<%-- the action forwards - note that it forwards to itself to refresh the
GUI with the updated values --%>
<!-- Admin functions -->
<action path="/admin" type="com.qat.expense.AdminAction"
name="adminForm"
scope="session"
input="/admin.jsp">
<forward name="success" path="/admin.jsp"/>
<forward name="excel" path="isAdminExcel.jsp"/>
<forward name="logout" path="/logout.do"/>
</action>
3. relevant parts of Action class
DynaActionForm adminForm = ( DynaActionForm ) form ;
ActionErrors errors = new ActionErrors();
String week_ending = ( String ) adminForm.get( "week_ending" );
// process approval changes
if( !(( Map ) adminForm.get( "approved" )).isEmpty() ) {
StringBuffer query = new StringBuffer( "SELECT emp_id, approved FROM
total WHERE week_ending='" )
.append( week_ending )
.append( "' ORDER BY emp_id" );
try {
DBresults empIds = DatabaseUtilities.getQueryResults(
query.toString(), true );
String[] data = new String[ empIds.getRowCount() ];
String[] fields = new String[ empIds.getColCnt() ];
fields = empIds.getColNames();
String[] emp_ids = new String[ empIds.getRowCount() ];
String[] dbValues = new String[ empIds.getRowCount() ];
if( empIds.getRowCount() > 0 ) {
for( int i = 0; i < data.length; i++ ) {
data = empIds.getRow( i );
adminForm.set( "approved", data[ 0 ], data[
1 ]);
emp_ids[ i ] = data[ 0 ];
dbValues[ i ] = data[ 1 ];
}
}
String[] aValues = null;
String[] dValues = null;
if( request.getParameterValues( "approve" ) != null ) {
aValues = request.getParameterValues( "approve" );
}
if( request.getParameterValues( "disapprove" ) != null ) {
dValues = request.getParameterValues( "disapprove"
);
}
if( aValues != null ) {
for( int i = 0; i < aValues.length; i++ ) {
adminForm.set( "approved", aValues[ i ],
"checked" );
for( int j = 0; j < emp_ids.length; j++ ) {
if( aValues[ i ].equals( emp_ids[ j
] )) {
StringBuffer update = new
StringBuffer( "UPDATE total SET approved='checked' WHERE emp_id='" )
.append( aValues[ i
] )
.append( "' AND
week_ending='" )
.append( week_ending
)
.append( "'" );
int k =
DatabaseUtilities.modifyDB( update.toString() );
}
}
}
}
if( dValues != null ) {
for( int i = 0; i < dValues.length; i++ ) {
adminForm.set( "approved", dValues[ i ],
"NO" );
for( int j = 0; j < emp_ids.length; j++ ) {
if( dValues[ i ].equals( emp_ids[ j
] )) {
StringBuffer update = new
StringBuffer( "UPDATE total SET approved='NO' WHERE emp_id='" )
.append( dValues[ i
] )
.append( "' AND
week_ending='" )
.append( week_ending
)
.append( "'" );
int k =
DatabaseUtilities.modifyDB( update.toString() );
}
}
}
}
} catch( SQLException e ) {
e.printStackTrace();
} catch( NamingException e ) {
e.printStackTrace();
}
}
return( retrieve( adminForm, week_ending, request, mapping ));
}
4. DAO and helper class
/**
* DAO Class to store completed results of JDBC. Differs from a
<code>ResultSet</code>
* in several ways (shameless stolen from Craig's code):
* <ul>
* <li><code>ResultSet</code> does not necessarily have all the
data; another call to
* the database in necessary for additional rows.</li>
* <li>This class stores results as <code>String</code> objects in
arrays.</li>
* <li>This class includes <code>DatabaseMetaData</code> and
<code>ResultSetMetaData</code>.</li>
* <li>This class has a toHTMLTable() method that turns the results
into a long
* <code>String</code> corresponding to an HTML table.</li>
* </ul>
*
* @author Mark Galbreath (mark_galbreath@qat.com)
* @version 1.0 March 2003
*/
public class DBresults {
private Connection conn = null;
private String dbName = null;
private String dbVersion = null;
private String[] colNames = null;
private String[] rowData = null;
private String[] data = null;
private int colCnt = 0;
private Vector queryResults = null;
/**
* Public constructor to initialize objects states.
*
* @param conn The <code>Connection</code> object used to connection
to the database.
* @param dbName The <code>String</code> name of the database.
* @param dbVersion The <code>String</code> version of the database.
* @param colCnt The <code>int</code> number of columns in the query
table.
* @param colNames The <code>String[]</code> array of column names.
*/
public DBresults( Connection conn,
String dbName,
String dbVersion,
int colCnt,
String[] colNames ) {
this.conn = conn;
this.dbName = dbName;
this.dbVersion = dbVersion;
this.colCnt = colCnt;
this.colNames = colNames;
rowData = new String[ colCnt ];
queryResults = new Vector();
}
/**
* Connection accessor.
*
* @return conn The <code>Connection</code> object.
*/
public Connection getConnection() {
return( conn );
}
/**
* Database name accessor.
*
* @return dbName The <code>String</code> name of the database.
*/
public String getDbName() {
return( dbName );
}
/**
* Database version accessor.
*
* @return dbVersion The <code>String</code> db version.
*/
public String getDbVersion() {
return( dbVersion );
}
/**
* Column count accessor.
*
* @return colCnt The <code>int</code> number of table columns.
*/
public int getColCnt() {
return( colCnt );
}
/**
* Column names accessor.
*
* @return colNames The <code>String[]</code> array of table column
names.
*/
public String[] getColNames() {
return( colNames );
}
/**
* Returned rows count accessor.
*
* @return queryResults.size() The <code>int</code> number of rows.
*/
public int getRowCount() {
return( queryResults.size() );
}
/**
* Row data accessor.
*
* @param index The <code>int</code> index of the data element.
* @return String[ index ] The <code>String[]</code> containing the
row data.
*/
public String[] getRow( int index ) {
try {
data = ( String[] ) queryResults.elementAt( index );
} catch( ArrayIndexOutOfBoundsException e ) {
System.out.println( "No row returned by database: "
+ e.getMessage() );
return( null );
}
return( data );
}
/**
* Add a row of data to the queryResults Vector.
*
* @param row The <code>String[]</code> row of data to add to the
Vector.
*/
public void addRow( String[] row ) {
queryResults.addElement( row );
}
}
package com.qat.expense;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* <code>DatabaseUtitilies</code> and its associated classes provide
convenience
* methods for application objects to query the database.
*
* @author Mark Galbreath (mark_galbreath@qat.com)
* @version 1.0 March 2003
*/
public class DatabaseUtilities {
/**
* Default empty constructor.
*/
public DatabaseUtilities() {
}
/**
* Connect to database, execute specified query, and accumulate
results into
* a DBresults object. If the db connection is left open, it can be
retrieved
* with DBresults.getConnection().
*
* @param query The <code>String</code> SQL query to execute.
* @param close The <code>boolean</code> flag indicating whether or
not
* to close the connection.
* @return DBresults The object encapsulating the query result.
* @exception ClassNotFoundException Thrown if the db driver class
cannot be found.
* @exception SQLException Thrown if the query fails for some
reason.
*/
public static DBresults getQueryResults( String query, boolean close
) throws NamingException, SQLException {
InitialContext ctx = new InitialContext();
DataSource ds = ( DataSource ) ctx.lookup(
"com.qat.db.expense" );
Connection conn = ds.getConnection();
return( getQueryResults( conn, query, close ));
}
/**
* Override method that retrieves query results using an open
connection.
*
* @param conn The <code>Connection</code> to the database.
* @param query The <code>String</code> SQL query to be executed.
* @param close The <code>boolean</code> flag indicating whether to
close the connection.
* @return dbResults The <code>DBresults</code> object encapsulating
the query result.
* @exception SQLException Thrown if the query fails.
*/
public static DBresults getQueryResults( Connection conn, String
query, boolean close ) {
try {
DatabaseMetaData dbMetaData = conn.getMetaData();
String dbName = dbMetaData.getDatabaseProductName();
String dbVersion =
dbMetaData.getDatabaseProductVersion();
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery( query );
ResultSetMetaData rsetMetaData = rset.getMetaData();
int colCnt = rsetMetaData.getColumnCount();
String[] colNames = new String[ colCnt ];
for( int i = 1; i < colCnt + 1; i++ ) {
colNames[ i - 1 ] =
rsetMetaData.getColumnName( i ).trim();
}
DBresults dbResults = new DBresults( conn, dbName,
dbVersion, colCnt, colNames );
while( rset.next() ) {
String[] row = new String[ colCnt ];
for( int i = 1; i < colCnt + 1; i++ ) {
String datum = rset.getString( i );
if( datum != null ) {
datum = datum.trim();
}
row[ i - 1 ] = datum;
}
dbResults.addRow( row );
}
if( close ) {
conn.close();
}
return( dbResults );
} catch( SQLException e ) {
System.out.println( "Problem querying database: " +
e.getMessage() );
}
return( null );
}
/**
* Modify database tables with SQL inserts.
*
* @param sql The <code>String</code> sql statement to be executed.
* @return rows The <code>int</code> number of rows added.
* @exception SQLException Thrown if query fails.
* @exception IOException Thrown if database connection fails.
*/
public static int modifyDB( String sql ) {
try {
InitialContext ctx = new InitialContext();
DataSource ds = ( DataSource ) ctx.lookup(
"com.qat.db.expense" );
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
return( stmt.executeUpdate( sql ) );
} catch( NamingException e ) {
System.out.println( "JNDI lookup error: " +
e.getMessage() );
} catch( SQLException e ) {
System.out.println( "Error connecting to database: "
+ e.getMessage() );
}
return( 0 );
}
}
-----Original Message-----
From: Rick Reumann [mailto:r@reumann.net]
Sent: Thursday, July 03, 2003 2:03 PM
To: Struts Users Mailing List
Subject: 4th Of July Struts Challenge...
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
---------------------------------------------------------------------
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
Re: 4th Of July Struts Challenge...
Posted by Sandeep Takhar <sa...@yahoo.com>.
The answer for the first part is here:
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg71256.html
specifically the part where it talks about nested tags
works. The logic:iterate I couldn't get to work and I
haven't set up the el stuff, but that would probably
work.
All you need in the form is the Object getMap(String
key) and setMap(key,object)
next thing to try is the dynaform, but I've never used
one before...
sandeep
--- Rick Reumann <r...@reumann.net> wrote:
> 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
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org