Hi all,

I'm a bit concerned about onSelectionChanged event effectively binding
my model. Suppose my model is a LoadableDetachableModel that is loaded
from the repository every time. Normally (upon form submission)
nothing will be bound after successfully passing validation; then
additional logic will run inside a transactional service and a
rollback thrown if something goes wrong (take into account that I'm
using session-in-view). But if a property of my model object is bound
outside this controlled scenario, the change will be persisted upon
session correct finalization, even if the object is invalid. I
observed that during onSelectionChanged execution the changed property
is effectively bound, so how should I deal with this?
Here is an example with a simple User that has a sex property allowing
the usual two values, note how setSex is called during execution of
onSelectionChanged:


The ouput for onSelectionChanged
--------------------------------------------------

loadSexModel
getSex
setSex  <------- here
getSex
selectionChanged
getSex

The user domain entity.
----------------------------------

public class User implements Serializable {
    [...]
    private String sex;

    [...]
    public String getSex() {
        System.out.println("getSex");
        return sex;
    }

    public void setSex(String sex) {
        System.out.println("setSex");
        this.sex = sex;
    }
}

The sex choice.
----------------------

DropDownChoice sex = new DropDownChoice("sex", getSexModel()) {
  protected void onSelectionChanged(Object newSelection) {
    System.out.println("selectionChanged");
  }
  protected boolean wantOnSelectionChangedNotifications() {
    return true;
  }
};

The sex model.
---------------------

private IModel getSexModel() {
  return new LoadableDetachableModel() {
    protected Object load() {
        System.out.println("loadSexModel");
        return Arrays.asList("Masculine", "Feminine");
      }
    };
}


Cheers,
Carlos

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to