I think your problem is that you have confused option and value and they
should be:
public Object getOption(int index) {
return (Truck)TruckList.get(index);
}
and:
public Object translateValue(String value) {
Integer id = Integer.parseInt(value);
Iterator TruckListIt = TruckList.Iterator
while (TruckListIt.hasNext()) {
Truck truck = (Truck)TruckListIt.next();
if (truck.getId().equals(id)) {
return truck;
break;
}
}
}
This should be more or less on the right lines. If you want to redisplay the
page make sure that your "truck" bean that I assume is a hibernate mapping
class implements public boolean equals(Object o) and uses your id for the
comparison.
Hope this helps,
Paul
From: Allan Rank <[EMAIL PROTECTED]>
Reply-To: "Tapestry users" <tapestry-user@jakarta.apache.org>
To: tapestry-user@jakarta.apache.org
Subject: hibernate objects and PropertySelection
Date: Wed, 12 Oct 2005 15:18:38 +0300
Hello!
One newbie question :)
I'm having problems using PropertySelection to generate
<select> from hibernate objects.
For example:
I have 1 database table from which I want to generate <select>, let's
call it Truck:
id ----- trucknr
1 111AAA
2 112BBB 5 113CCC
Then I have a Truck class, hibernate object for that table and I have
implemented
PropertySelectionModel:
public class TruckSelectionModel implements IPropertySelectionModel {
private List TruckList;
public TruckSelectionModel(List TruckList) {
this.TruckList = TruckList;
}
public int getOptionCount() {
return TruckList.size();
}
public Object getOption(int index) {
return ((Truck)TruckList.get(index)).getId();
}
public String getLabel(int index) {
return ((Truck)TruckList.get(index)).getTruckNr();
}
public String getValue(int index) {
return ((Truck)TruckList.get(index)).getId().toString();
}
public Object translateValue(String value) {
return getOption(Integer.parseInt(value));
}
}
Generation of <select> is ok:
<select name="Truck">
<option value="2">112BBB</option>
<option value="1">111AAA</option>
<option value="5">113CCC</option>
</select>
Tapestry asks for trucks count (getOptionCount() = 3), then starts to
ask for values/id's by index (getOption(0), getOption(1), getOption(2)
etc...).
BUT when i select, for example 113CCC-option(with database id/option value
5) and submit my form, Tapestry asks my PropertySelectionModel to getOption
with index 5!
There is no TruckList member with index 5. DB id's and list indexes are
messed up.
So my question is: how is it possible to use hibernate objects to generate
<select> with PropertySelectionModel?
Thanks!
--
ALLAN RANK
mob: + 372 56 239925 msn: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
skype: trutata [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]