-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I've been experimenting with Selection and Option components, and am having
just one difficulty. When I execute my example code, I get the required HTML,
except that no labels are produced for each option.
To example how I am going about this:
0) The example is a very simple form showing some set of colours, with
multiple selection enabled.
1) there is a single HTML page, with form, select and option compoments. The
option component is wrapped in a foreach.
2) The foreach accesses it's source values (a list) from the Visit object.
3) The foreach sets it's 'current value' on the visit object as well.
4) The Option statement takes its values (selected, label) from the 'current
value' on the visit object.
5) The 'current value' is a very simple class, containing a boolean (for
'selected' and a String (for the label).
Anyone got any hints for me?
Cheers,
Neil Clayton
(see below for all related output and files)
The HTML produced by Tapestry (2.2, CVS) is as follows:
<body>
<h1>Example of Select and Option HTML element</h1>
<form method="post" name="Form0" action="/componentref">
<input type="hidden" name="service" value="direct">
<input type="hidden" name="context" value="Selection/form">
<input type="hidden" name="sp" value="S0">
Select a colour:
<select name="selection" multiple>
<option value="0">
<option value="1">
<option value="2">
<option value="3">
<option value="4">
<option value="5">
<option value="6">
</select>
<input type="hidden" name="Form0" value="1">
</form>
</body>
For reference, here are the relevant Tapestry bits:
- ----------------------------------------------------------------
The page specification is:
- ----------------------------------------------------------------
<specification class="examples.componentref.Selection" allow-body="yes"
allow-informal-parameters="yes" >
<bean name="validationDelegate"
class="net.sf.tapestry.valid.ValidationDelegate" lifecycle="request"/>
<component id="form" type="Form">
<binding name="delegate" property-path="beans.validationDelegate"/>
<binding name="listener" property-path="listeners.formSubmit"/>
</component>
<component id="colours" type="Foreach">
<binding name="source" property-path="visit.colours"/>
<binding name="value" property-path="visit.currentColour"/>
</component>
<component id="selection" type="Select">
<field-binding name="multiple" field-name="Boolean.TRUE"/>
</component>
<component id="colour" type="Option">
<binding name="selected" property-path="visit.currentColour.selected"/>
<binding name="label" property-path="visit.currentColour.label"/>
</component>
</specification>
The HTML is:
- ----------------------------------------------------------------
<body>
<h1>Example of Select and Option HTML element</h1>
<form jwcid="form">
Select a colour:
<input jwcid="selection">
<span jwcid="colours">
<option jwcid="colour"/>
</span>
</input>
</form>
</body>
And the Visit object (well, part of it):
- ----------------------------------------------------------------
public Collection getColours() {
if(colours == null) {
colours = new ArrayList();
colours.add(new Colour("Green"));
colours.add(new Colour("Blue"));
colours.add(new Colour("Red"));
colours.add(new Colour("White"));
colours.add(new Colour("Purple"));
colours.add(new Colour("Dark Black"));
colours.add(new Colour("Fiji Blue"));
}
return colours;
}
/**
* Returns the currentColour.
* @return Colour
*/
public Colour getCurrentColour() {
return currentColour;
}
/**
* Sets the currentColour.
* @param currentColour The currentColour to set
*/
public void setCurrentColour(Colour currentColour) {
this.currentColour = currentColour;
}
private List colours;
private Colour currentColour;
- ----------------------------------------------------------------
Finally, the Colour class:
- ----------------------------------------------------------------
public class Colour {
public Colour(String label) {
setLabel(label);
}
public Colour(String label, boolean selected) {
setLabel(label);
setSelected(selected);
}
/**
* Returns the isSelected.
* @return boolean
*/
public boolean getSelected() {
return selected;
}
/**
* Returns the label.
* @return String
*/
public String getLabel() {
return label;
}
/**
* Sets the isSelected.
* @param isSelected The isSelected to set
*/
public void setSelected(boolean isSelected) {
this.selected = isSelected;
}
/**
* Sets the label.
* @param label The label to set
*/
public void setLabel(String label) {
this.label = label;
}
private String label;
private boolean selected;
}
- --
Neil
(BTW: If you see weird text surrounding the message and you don't know what it
is, don't worry, it's just my public PGP signature).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9bPrVLXcfQF3yrNoRAvTlAJ4rwSl07Dzb1EiJNS19P6mj1vokBQCcCoxM
vyAw4REc9dXI3YXtav55O18=
=qtBo
-----END PGP SIGNATURE-----
-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest growing
real-time communications platform! Don't just IM. Build it in!
http://www.jabber.com/osdn/xim
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer