You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ran Aker <ra...@gmail.com> on 2005/09/12 15:48:01 UTC

Setting values for PropertySelection

Hi
How can i set my own values for the options in the select element.
I am using the PropertySelection component and i am getting the enum values 
for my options for example:
<select>
<option value="0">first option</option>
<option value="1">second option</option>
<option value="2">third option</option>
</select>

but what i really want is 

<select>
<option value="89">first option</option>
<option value="12">second option</option>
<option value="20">third option</option>
</select>

Thanks
Ran

Re: Setting values for PropertySelection

Posted by Tomáš Drenčák <to...@gmail.com>.
It's an implementation of selection model. But I think that this
behaviour could be overridden just by creating own component.

I have written own selection model which uses collection and it's
indexes. Just create this SelectionModel and insert it into
PropertySelection. You'll have selected object in property you have
pass to value binding after form submits.

public class SelectionModel implements IPropertySelectionModel {
	private List list;
    private boolean addNullRow;
    
    public SelectionModel(Collection list) {
        this(list, true);
    }
    
    @SuppressWarnings("unchecked")
	public SelectionModel(Collection list, boolean addNullRow) {
        this.list = new ArrayList(list);
        this.addNullRow = addNullRow;
    }
    
    public int getOptionCount() {
        if (addNullRow) {
            return list.size() +1;
        }
        return list.size();
    }

    public Object getOption(int index) {
        if (addNullRow && index == 0) {
            return null;
        } else if (addNullRow){
            index--;            
        }
        return list.get(index);
    }

    public String getLabel(int index) {
        if (addNullRow && index == 0) {
            return "...";
        }
        if (addNullRow) {
            index--;
        }
        Object o = list.get(index);
        if (o instanceof Displayable) {
            Displayable p = (Displayable) o;
            return p.getDisplayString();
        }
        return o.toString();
    }

    public String getValue(int index) {
        if (addNullRow && index == 0) {
            return null;
        }
        if (addNullRow) {
            index--;
        }
        return Integer.toString(index);
    }

    public Object translateValue(String value) {
        if (addNullRow && "".equals(value)) {
            return null;
        }
        int index = Integer.parseInt(value);
        if (index < 0)
            return null;
        return list.get(index);
    }

}

2005/9/12, Ran Aker <ra...@gmail.com>:
> Hi
> How can i set my own values for the options in the select element.
> I am using the PropertySelection component and i am getting the enum values
> for my options for example:
> <select>
> <option value="0">first option</option>
> <option value="1">second option</option>
> <option value="2">third option</option>
> </select>
> 
> but what i really want is
> 
> <select>
> <option value="89">first option</option>
> <option value="12">second option</option>
> <option value="20">third option</option>
> </select>
> 
> Thanks
> Ran
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org