Hi, Try to override the equals() method from the Object on your Club class 2007/12/19, Penyihir Kecil <[EMAIL PROTECTED]>: > > Hi... > > i got another problem here, using select component inside a form. > well, when it's on "add" mode....it works to add new entry in the > database. > > but when i try to edit it ("edit" mode). > the select component didn't showed the selected value but back to normal > condition (ordered list value). > > could anyone help me to solve this problem ? > > here's my code : > > > ---------------------------------------------------------------------------------------------------------------------------------- > *PlayerForm.java* > > public class PlayerForm extends BaseFormPage{ > @Inject > private IPlayerDao playerDao; > @Inject > private IClubDao clubDao; > > @Persist > private Player player; > private Club club; > > @Component > private Form playerForm; > > private List<Club> clubList; > > private String idPlayer; > > public IClubDao getClubDao() { > return clubDao; > } > > public IPlayerDao getPlayerDao() { > return playerDao; > } > > public Player getPlayer() { > return player; > } > > public Club getClub() { > return club; > } > public void setClub(Club club) { > this.club = club; > } > > public List<Club> getClubList() { > clubList = getClubDao().queryForList("", ""); > return clubList; > } > > > public ClubSelectionModel getClubSelectionModel() { > return new ClubSelectionModel(getClubList()); > } > public ValueEncoder<Club> getClubValueEncoder(){ > return new ClubValueEncoder(getClubList()); > } > > void onPrepare(){ > if(player == null){ > player = new Player(); > } > if(club == null){ > club = new Club(); > } > } > > //it's used for back button action, so it's turn back the value into > null > void cleanupRender() { > player = null; > club = null; > } > > void onActionFromClear(){ > player = null; > playerForm.clearErrors(); > } > > //submit action, i have to make player back to null > Object onSuccessFromPlayerForm(){ > if(getPlayer().getIdPlayer()==null){ > getPlayer().setIdPlayer(getIdPrimaryKey().generateId()); > getPlayer().setIdClub(getClub().getIdClub()); > > getPlayerDao().insert(getPlayer()); > }else{ > getPlayer().setClub(club); > getPlayerDao().update(getPlayer()); > > } > > player = null; > return PlayerGrid.class; > } > > void onActivate(String idPlayer){ > this.idPlayer = idPlayer; > player = (Player) getPlayerDao().findByPrimaryKey(idPlayer); > } > > String onPassivate(){ > return idPlayer; > } > > } > > > ---------------------------------------------------------------------------------------------------------------------------------- > > *PlayerForm.tml* > > <form t:type="Form" t:id="playerForm"> > <t:errors/> > <table class="soria"> > <tr> > <td><t:label for="firstNameField"/></td> > <td> :</td> > <td><input t:type="TextField" t:id="firstNameField" > value=" > Player.firstName" > validate="required,minlength=3" size="20" > label="First > Name"/></td> > </tr> > <tr> > <td><t:label for="midNameField"/></td> > <td> :</td> > <td><input t:type="TextField" t:id="midNameField" value=" > Player.midName" > size="20" label="Middle Name"/></td> > </tr> > <tr> > <td><t:label for="lastNameField"/></td> > <td> :</td> > <td><input t:type="TextField" t:id="lastNameField" value=" > Player.lastName" > validate="required" size="20" label="Last > Name"/></td> > </tr> > <tr> > <td><t:label for="clubSelect"/></td> > <td> </td> > <td><t:select t:id="clubSelect" model="clubSelectionModel" > value="club" encoder="clubValueEncoder" label="Club"/></td> > </tr> > <tr> > <td><t:label for="defaultPriceField"/></td> > <td> </td> > <td><input t:type="TextField" t:id="defaultPriceField" > value="Player.defaultPrice" > validate="required" size="20" label="Default > Price"/></td> > </tr> > <tr><td colspan="3"></td></tr> > <tr> > <td colspan="3"> > <input type="submit" label="Save" dojoType=" > dijit.form.Button" iconClass="dijitEditorIcon dijitEditorIconSave"/> > </td> > </tr> > </table> > </form> > > > ---------------------------------------------------------------------------------------------------------------------------------- > *ClubSelectionModel.java* > > public class ClubSelectionModel implements SelectModel { > private List<Club> clubList; > > public ClubSelectionModel(List<Club> clubList){ > this.clubList = clubList; > } > public List<OptionGroupModel> getOptionGroups() { > return getSelectModel().getOptionGroups(); > } > > public List<OptionModel> getOptions() { > return getSelectModel().getOptions(); > } > > public void visit(SelectModelVisitor visitor) { > getSelectModel().visit(visitor); > > } > > public SelectModel getSelectModel() { > List<OptionModel> optionModelList = new ArrayList<OptionModel>(); > > for(Club club: clubList) { > optionModelList.add(new OptionModelImpl(club.getClubName(), > false, club, new String[0])); > } > return new SelectModelImpl(null, optionModelList); > } > } > > > ---------------------------------------------------------------------------------------------------------------------------------- > *ClubValueEncoder.java* > > public class ClubValueEncoder implements ValueEncoder<Club> { > private List<Club> clubList; > > public ClubValueEncoder(List<Club> clubList) { > this.clubList = clubList; > } > > public String toClient(Club club) { > > return club.getClubName(); > } > > public Club toValue(String value) { > for(Club club : clubList){ > if(club.getClubName().equals(value)){ > return club; > } > } > return null; > } > } >
-- Atenciosamente, Marcelo Lotif