You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Amin Lalji <am...@intelysis.com> on 2004/04/07 21:28:28 UTC
DynaAction or Map Backed Form?
Hello All,
I have the following scenario:
I need to populate a form using a runtime generated set of form
properties...
Essentially I have two collections I pull from a database
Services (serviceID,serviceName)
Documents (documentID,documentName)
I want to populate a set of checkboxes for each service such that I achieve:
<input type="checkbox" name="serviceName[0].id"
value="documentID">documentName
Any ideas?
Thanks,
Amin
RE: DynaAction or Map Backed Form?
Posted by Amin Lalji <am...@intelysis.com>.
I've been able to "hack" it using logic:iterate:
<logic:iterate name="allRequiredDocuments" id="service">
<bean:write name="service" property="serviceName"/> :
<logic:iterate name="service" property="requiredDocuments" id="document">
<input type="checkbox" name="<bean:write name="service"
property="serviceId"/>" value="<bean:write name="document"
property="value"/>"><bean:write name="document" property="label"/>
</logic:iterate>
</logic:iterate>
Problem is, I lose my counter, and the ability to use validation . there has
got to be a better way!
Thank,
/A
-----Original Message-----
From: Ray Madigan [mailto:ray@madigans.org]
Sent: Wednesday, April 07, 2004 5:03 PM
To: Struts Users Mailing List
Subject: RE: DynaAction or Map Backed Form?
Im not sure how to do it with the iterate tag, I use the c:forEach tag in
the jstl taglib.
It goes something like this:
Assume service is a bean with accessors getDocuments ( ) and getId ( )
Assume document is a bean wit accessors getId ( ) and getName ( )
<c:forEach var='service' items='services'>
<c:forEach var='document' items='service.documents'>
<input type="checkbox" name='${service.id}"
value='${document.id}'><c:out value='${document.name}'/>
<c:forEach>
<c:foreach>
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 1:26 PM
To: 'Struts Users Mailing List'
Subject: RE: DynaAction or Map Backed Form?
Here is the Data structure:
I have two tables (Services, Documents)
I hit the database and pull two separate Collections.
I need to iterate over both collections... here is the relationship:
ServiceID
ServiceName
Documents
DocumentID
DocumentName
So a service object contains a collection of documents....
I need to be able to output something like:
<input type="checkbox" name="ServiceID[0].id"
value="DocumentID">DocumentName
---
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
In my action, I created a DynaActionForm.
I set a java.util.ArrayList property called requiredDocuments in
struts-config.xml
In my action I make the database calls, then I iterate the services
collection creating a RequiredDocumentsBean (contains serviceID,
serviceName, and documents Collection)
I populate the first two properties (serviceID, and serviceName) and then
iterate the documents collection setting a LabelValueBean
Here is the code:
<-- snip -->
while(sIterator.hasNext()){ // for each service...
RequiredDocumentsBean rd = new RequiredDocumentsBean();
ServiceBeanLocal service = (ServiceBeanLocal)sIterator.next();
rd.setServiceId(service.getId());
rd.setServiceName(service.getServiceName());
Iterator dIterator = documents.iterator();
while(dIterator.hasNext()){ // for each available document
DocumentBeanValue document =
DocumentBeanValue)dIterator.next();
rd.getRequiredDocuments().add(new
LabelValueBean(document.getDocumentName(),document.getId()));
}
requiredDocuments.add(rd);
}
myForm.set("allRequiredDocuments",requiredDocuments);
request.setAttribute("allRequiredDocuments",requiredDocuments);
<-- snip -->
Thanks
-----Original Message-----
From: Ray Madigan [mailto:ray@madigans.org]
Sent: Wednesday, April 07, 2004 3:09 PM
To: Struts Users Mailing List
Subject: RE: DynaAction or Map Backed Form?
It isn't clear what you have to work with. Is services a map of some sort,
or is it a collection.
Either way you should use the iterate tag in the logic tag set.
If you could explain the data structure better, it would be easier to help.
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 12:39 PM
To: 'Struts Users Mailing List'
Subject: RE: DynaAction or Map Backed Form?
Sorry... to add...
Each Service may have a unknown set of documents...
E.g. Services:
001 Catering
002 Party
Documents:
001 Contract
002 Deposit
Should yield:
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
Thanks,
/A
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 2:28 PM
To: 'Struts Users Mailing List'
Subject: DynaAction or Map Backed Form?
Hello All,
I have the following scenario:
I need to populate a form using a runtime generated set of form
properties...
Essentially I have two collections I pull from a database
Services (serviceID,serviceName)
Documents (documentID,documentName)
I want to populate a set of checkboxes for each service such that I achieve:
<input type="checkbox" name="serviceName[0].id"
value="documentID">documentName
Any ideas?
Thanks,
Amin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: DynaAction or Map Backed Form?
Posted by Ray Madigan <ra...@madigans.org>.
Im not sure how to do it with the iterate tag, I use the c:forEach tag in
the jstl taglib.
It goes something like this:
Assume service is a bean with accessors getDocuments ( ) and getId ( )
Assume document is a bean wit accessors getId ( ) and getName ( )
<c:forEach var='service' items='services'>
<c:forEach var='document' items='service.documents'>
<input type="checkbox" name='${service.id}"
value='${document.id}'><c:out value='${document.name}'/>
<c:forEach>
<c:foreach>
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 1:26 PM
To: 'Struts Users Mailing List'
Subject: RE: DynaAction or Map Backed Form?
Here is the Data structure:
I have two tables (Services, Documents)
I hit the database and pull two separate Collections.
I need to iterate over both collections... here is the relationship:
ServiceID
ServiceName
Documents
DocumentID
DocumentName
So a service object contains a collection of documents....
I need to be able to output something like:
<input type="checkbox" name="ServiceID[0].id"
value="DocumentID">DocumentName
---
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
In my action, I created a DynaActionForm.
I set a java.util.ArrayList property called requiredDocuments in
struts-config.xml
In my action I make the database calls, then I iterate the services
collection creating a RequiredDocumentsBean (contains serviceID,
serviceName, and documents Collection)
I populate the first two properties (serviceID, and serviceName) and then
iterate the documents collection setting a LabelValueBean
Here is the code:
<-- snip -->
while(sIterator.hasNext()){ // for each service...
RequiredDocumentsBean rd = new RequiredDocumentsBean();
ServiceBeanLocal service = (ServiceBeanLocal)sIterator.next();
rd.setServiceId(service.getId());
rd.setServiceName(service.getServiceName());
Iterator dIterator = documents.iterator();
while(dIterator.hasNext()){ // for each available document
DocumentBeanValue document =
DocumentBeanValue)dIterator.next();
rd.getRequiredDocuments().add(new
LabelValueBean(document.getDocumentName(),document.getId()));
}
requiredDocuments.add(rd);
}
myForm.set("allRequiredDocuments",requiredDocuments);
request.setAttribute("allRequiredDocuments",requiredDocuments);
<-- snip -->
Thanks
-----Original Message-----
From: Ray Madigan [mailto:ray@madigans.org]
Sent: Wednesday, April 07, 2004 3:09 PM
To: Struts Users Mailing List
Subject: RE: DynaAction or Map Backed Form?
It isn't clear what you have to work with. Is services a map of some sort,
or is it a collection.
Either way you should use the iterate tag in the logic tag set.
If you could explain the data structure better, it would be easier to help.
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 12:39 PM
To: 'Struts Users Mailing List'
Subject: RE: DynaAction or Map Backed Form?
Sorry... to add...
Each Service may have a unknown set of documents...
E.g. Services:
001 Catering
002 Party
Documents:
001 Contract
002 Deposit
Should yield:
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
Thanks,
/A
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 2:28 PM
To: 'Struts Users Mailing List'
Subject: DynaAction or Map Backed Form?
Hello All,
I have the following scenario:
I need to populate a form using a runtime generated set of form
properties...
Essentially I have two collections I pull from a database
Services (serviceID,serviceName)
Documents (documentID,documentName)
I want to populate a set of checkboxes for each service such that I achieve:
<input type="checkbox" name="serviceName[0].id"
value="documentID">documentName
Any ideas?
Thanks,
Amin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: DynaAction or Map Backed Form?
Posted by Amin Lalji <am...@intelysis.com>.
Here is the Data structure:
I have two tables (Services, Documents)
I hit the database and pull two separate Collections.
I need to iterate over both collections... here is the relationship:
ServiceID
ServiceName
Documents
DocumentID
DocumentName
So a service object contains a collection of documents....
I need to be able to output something like:
<input type="checkbox" name="ServiceID[0].id"
value="DocumentID">DocumentName
---
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
In my action, I created a DynaActionForm.
I set a java.util.ArrayList property called requiredDocuments in
struts-config.xml
In my action I make the database calls, then I iterate the services
collection creating a RequiredDocumentsBean (contains serviceID,
serviceName, and documents Collection)
I populate the first two properties (serviceID, and serviceName) and then
iterate the documents collection setting a LabelValueBean
Here is the code:
<-- snip -->
while(sIterator.hasNext()){ // for each service...
RequiredDocumentsBean rd = new RequiredDocumentsBean();
ServiceBeanLocal service = (ServiceBeanLocal)sIterator.next();
rd.setServiceId(service.getId());
rd.setServiceName(service.getServiceName());
Iterator dIterator = documents.iterator();
while(dIterator.hasNext()){ // for each available document
DocumentBeanValue document =
DocumentBeanValue)dIterator.next();
rd.getRequiredDocuments().add(new
LabelValueBean(document.getDocumentName(),document.getId()));
}
requiredDocuments.add(rd);
}
myForm.set("allRequiredDocuments",requiredDocuments);
request.setAttribute("allRequiredDocuments",requiredDocuments);
<-- snip -->
Thanks
-----Original Message-----
From: Ray Madigan [mailto:ray@madigans.org]
Sent: Wednesday, April 07, 2004 3:09 PM
To: Struts Users Mailing List
Subject: RE: DynaAction or Map Backed Form?
It isn't clear what you have to work with. Is services a map of some sort,
or is it a collection.
Either way you should use the iterate tag in the logic tag set.
If you could explain the data structure better, it would be easier to help.
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 12:39 PM
To: 'Struts Users Mailing List'
Subject: RE: DynaAction or Map Backed Form?
Sorry... to add...
Each Service may have a unknown set of documents...
E.g. Services:
001 Catering
002 Party
Documents:
001 Contract
002 Deposit
Should yield:
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
Thanks,
/A
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 2:28 PM
To: 'Struts Users Mailing List'
Subject: DynaAction or Map Backed Form?
Hello All,
I have the following scenario:
I need to populate a form using a runtime generated set of form
properties...
Essentially I have two collections I pull from a database
Services (serviceID,serviceName)
Documents (documentID,documentName)
I want to populate a set of checkboxes for each service such that I achieve:
<input type="checkbox" name="serviceName[0].id"
value="documentID">documentName
Any ideas?
Thanks,
Amin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: DynaAction or Map Backed Form?
Posted by Ray Madigan <ra...@madigans.org>.
It isn't clear what you have to work with. Is services a map of some sort,
or is it a collection.
Either way you should use the iterate tag in the logic tag set.
If you could explain the data structure better, it would be easier to help.
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 12:39 PM
To: 'Struts Users Mailing List'
Subject: RE: DynaAction or Map Backed Form?
Sorry... to add...
Each Service may have a unknown set of documents...
E.g. Services:
001 Catering
002 Party
Documents:
001 Contract
002 Deposit
Should yield:
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
Thanks,
/A
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 2:28 PM
To: 'Struts Users Mailing List'
Subject: DynaAction or Map Backed Form?
Hello All,
I have the following scenario:
I need to populate a form using a runtime generated set of form
properties...
Essentially I have two collections I pull from a database
Services (serviceID,serviceName)
Documents (documentID,documentName)
I want to populate a set of checkboxes for each service such that I achieve:
<input type="checkbox" name="serviceName[0].id"
value="documentID">documentName
Any ideas?
Thanks,
Amin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: DynaAction or Map Backed Form?
Posted by Amin Lalji <am...@intelysis.com>.
Sorry... to add...
Each Service may have a unknown set of documents...
E.g. Services:
001 Catering
002 Party
Documents:
001 Contract
002 Deposit
Should yield:
<input type="checkbox" name="Catering[0].id"
value="001">Contract
<input type="checkbox" name="Catering[1].id"
value="002">Deposit
<input type="checkbox" name="Party[0].id"
value="001">Contract
<input type="checkbox" name="Party[1].id"
value="002">Deposit
Thanks,
/A
-----Original Message-----
From: Amin Lalji [mailto:amin.lalji@intelysis.com]
Sent: Wednesday, April 07, 2004 2:28 PM
To: 'Struts Users Mailing List'
Subject: DynaAction or Map Backed Form?
Hello All,
I have the following scenario:
I need to populate a form using a runtime generated set of form
properties...
Essentially I have two collections I pull from a database
Services (serviceID,serviceName)
Documents (documentID,documentName)
I want to populate a set of checkboxes for each service such that I achieve:
<input type="checkbox" name="serviceName[0].id"
value="documentID">documentName
Any ideas?
Thanks,
Amin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org