I'm working with select component in Tapestry. I want to select one object in form, and I want it to show names in select options, but it shows id instead.
TML:
<t:beaneditform object="soba" exclude="idSobe" add="idHotel" >
<p:idHotel>
<t:label for="idHotel"/>:
<t:select t:blankLabel="Odaberi Hotel" t:id="idHotel"
encoder="encoder" model="hoteli" value="idHotel"
/>
</p:idHotel>
</t:beaneditform>
Java:
@Property
private Soba onesoba;
@Inject
private HotelDao hotelDao;
@Property
private Hotel idHotel;
@Property
@Persist
private List<Hotel> hoteli;
@Property
private List<Soba>sobe;
public ValueEncoder getEncoder() {
return new ValueEncoder<Hotel>() {
@Override
public String toClient(Hotel v) {
return String.valueOf(v.getIdHotel());
}
@Override
public Hotel toValue(String string) {
Hotel hot = hotelDao.getHotelById(Integer.parseInt(string));
return hot;
}
And when I run the app and want to select an obj I get this
But when clicking on "add hotel" I want name property not :com.mycompany...
If someone has any suggestion how to change that property in select component, I would be grateful.
You need to pass a SelectModel, specifying which property to be shown.
...
@Property
@Persist
private List<Hotel> hoteli;
@Inject
private SelectModelFactory smf;
public SelectModel getHoteliModel()
{
return smf.create(hoteli, "name") ;
}
...
And in your .tml you'll have:
<t:select t:blankLabel="Odaberi Hotel" t:id="idHotel"
encoder="encoder" model="hoteliModel" value="idHotel"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.