You will have to create yout own implementation of
IPropertySelectionModel, of which several are available via the WIKI.
Also see pages 141, 142 of Tapestry in Action.
This is what I created myself and is working fine. The only
bug/feature is that the value to which the PropertySelection
component is bound *has* to be a String.
The constructor of ValueLabelPropertySelectionModel accepts any List
of Objects that either implement the IValueLabel interface (which
should serve your needs) or are just plain Strings. In the latter
case the value and label in the poplist will be the same.
Good luck,
Martijn
public class ValueLabelPropertySelectionModel implements
IPropertySelectionModel {
/**
* The list of options held by this poplist<br/> Options can be: -
Strings or
* objects that implement IValueLabel
*
*/
List _options;
Map _optionsMap;
public ValueLabelPropertySelectionModel() {
}
public ValueLabelPropertySelectionModel(List l) {
set_options(l);
if( _options != null ) {
_optionsMap = new HashMap();
for( int i = 0; i < _options.size(); i++ ) {
Object option = _options.get(i);
if( option instanceof IValueLabel ) {
IValueLabel vl = (IValueLabel)_options.get(i);
// _optionsMap.put(vl.getValue(), vl.getLabel());
_optionsMap.put(vl.getValue(), vl);
} else {
_optionsMap.put(option.toString(), option.toString());
}
}
}
}
/**
* @see
org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
*/
public int getOptionCount() {
if( _options == null ) {
return 0;
} else {
return _options.size();
}
}
/**
* @see
org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
*/
public Object getOption(int i) {
if( _options == null ) {
return null;
} else {
Object option = _options.get(i);
if( option instanceof IValueLabel ) {
return ((IValueLabel)option).getValue();
// return option;
} else {
return option;
}
}
}
/**
* @see
org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
*/
public String getLabel(int i) {
if( _options == null ) {
return null;
} else {
Object option = _options.get(i);
if( option instanceof IValueLabel ) {
return ((IValueLabel)option).getLabel();
} else {
return option.toString();
}
}
}
/**
* @see
org.apache.tapestry.form.IPropertySelectionModel#getValue(int)
*/
public String getValue(int i) {
if( _options == null ) {
return null;
} else {
Object option = _options.get(i);
if( option instanceof IValueLabel ) {
return ((IValueLabel)option).getValue();
} else {
return option.toString();
}
}
}
/**
* @see
org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.l
ang.String)
*/
public Object translateValue(String value) {
if( _options == null ) {
return null;
} else {
Object o = _optionsMap.get(value);
if( o instanceof IValueLabel ) {
return ((IValueLabel)o).getValue();
} else {
return _optionsMap.get(value);
}
}
}
/**
* @return Returns the _options.
*/
public List get_options() {
return _options;
}
/**
* @param _options The _options to set.
*/
public void set_options(List _options) {
this._options = _options;
}
public interface IValueLabel {
public String getLabel();
public String getValue();
}
public class ValueLabel implements IValueLabel{
String label;
String value;
public ValueLabel(String l, String v){
setLabel(l);
setValue(v);
}
public void setLabel(String label) {
this.label = label;
}
public void setValue(String value) {
this.value = value;
}
public String getLabel() {
return label;
}
public String getValue() {
return value;
}
}
---- Original Message ----
From: [EMAIL PROTECTED]
To: [email protected]
Subject: RE: selection problem
Date: Thu, 22 Dec 2005 18:33:11 +0800
>Hi all,
> I have a issue about using PropertySelection component.
> So I wanna whether can PropertySelection seperate his list value
>and
>list key.Because I may need to display the value,while using the key
>of the
>selection.
> So is there any one who know how to do?
>
>Thanks,
>Ryan.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]