As you probably know by now the Tapestry checkbox component provides a boolean control. So the you will need to handle the illnessName and illnessID stuff in some sort of bean.
I would handle the multiple checkboxs in a foreach loop:
HTML:
<form jwcid="form">
<span jwcid="foreachIllness">
<input type="checkbox" jwcid="illnessCheckbox">
<span jwcid="illnessLabel"><br/>
</span>
<input type="submit">
</form>
PAGE:
<component id="form" type="Form">
<binding name="listener" expression="listeners.formSubmit"/>
</component>
<component id="foreachIllness" type="Foreach">
<binding name="source" expression="illnessList"/>
<binding name="value" expression="illness"/>
</component>
<component id="illnessLabel" type="Insert">
<binding name="value" expression="illness.name"/>
</component>
<component id="illnessCheckbox" type="Checkbox">
<binding name="selected" expression="illness.selected"/>
</component>
JAVA:
public clas Illness implements Serializable {
private int id;
private String name;
private boolean selected;
public int getId() { return id; }
public String getName() { return name; }
public boolean getSelected() { return selected; }
public void setSelected(boolean value) { selected = value; }
public String toString() {
return getClass().getName()
+ "[id=" + id
+ ",name=" + name
+ ",selected=" + selected
+ "]";
}
}
public class IllnessPage extends BasePage {
private List illnessList;
private Illness illness;
// Read by foreachIllness component
public List getIllnessList() {
return illnessList;
}
// Read by illnessCheckbox and illnessLabel components
public Illness getIllness() {
return illness;
}
// Set by foreachIllness component
public void setIllness(Illness value) {
illness = value;
}
// Cleans up page when returned to pool
protected void initialize() {
illnessList = null;
illness = null;
}
// All the illness selections will be set before this method
// is called
public void formSubmit(IRequestCycle cycle) {
for (int i = 0; i < illnessList.size(); i++) {
System.out.println("Illness: " + illnessList.get(i));
}
}
}
"http://jakarta.apache.org/proposals/tapestry/doc/ComponentReference/Checkbox.html"
regards Malcolm Edgar
From: "Meade, Joseph L" <[EMAIL PROTECTED]>
To: "Tapestry-Developer (E-mail)" <[EMAIL PROTECTED]>
Subject: [Tapestry-developer] A Form with many Checkboxes
Date: Wed, 19 Feb 2003 12:25:11 -0500
Tapestry Gurus,
I need some help with the paradigm shift.
I've got a form with an arbitrary number of related checkboxes. The value of each is an int corresponding to a String label. (illnessName and illnessID)
In the servlet paradigm, I would name them all the same thing and call something like this in the form listener:
String[] illnessIDs = request.getParameterValues("illness");
But, it seems in Tapestry that you need a specific boolean attribute for each checkbox? That's tough when you don't know how many you will have or what they will be called.
What am I missing? How can I receive a collection of values corresponding to the checked boxes? I know the Checkbox component accepts informal parameters, so I have set a value for each, but I can't see how to retrieve it once the form is submitted.
Thanks for your help.
Joe Meade
[EMAIL PROTECTED]
-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer
_________________________________________________________________
MSN Instant Messenger now available on Australian mobile phones.�Go to http://ninemsn.com.au/mobilecentral/hotmail_messenger.asp
-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer
