First of all, the functional description:
I have a screen with the table which contains on each line a column with
description, a dropDownChoice (DDC) with a list of configurations and
another column with DDC with a list of years. When user changes a
configuration , the list of years updates depending on selected
configuration (using ajax). 

Below you can find the code. 

/**
 * @see RefreshingView#populateItem(Item)
 */
protected void populateItem(final Item item) {
  //get the configuration list
  List configurationList = ...//call a service to get the list
  DropDownChoice selConfig = new DropDownChoice("configuration",
     new PropertyModel(item.getModel(), "configuration"),
     configurationList, new ChoiceRenderer(
        "description", "id"));
  item.add(selConfig);

  IModel modelChoices = new Model() {
    public Object getObject(final Component component) {
      List rValue = Collections.EMPTY_LIST;
      ReportTemplateUI report = (ReportTemplateUI) item.getModelObject();
      Configuration config = report.getConfiguration();
      if (config == null) {
        return rValue;
      }
      rValue = getExtractionResultService().getAvailableYears(
          config.getId());
      return rValue;
    }
  };
  DropDownChoice selYear = new DropDownChoice("year",
      new PropertyModel(item.getModel(), "year"), modelChoices);
  item.add(selYear);
  //...
}  


The modelObject of the Item looks like this:

ReportTemplateUI implements Serializable{
  private Integer year;
  private Configuration configuration;  
  //other properties + getters & setters
}

As you can see, the DDC is constructed this way: it uses a PropertyModel for
setting the "year" property on the item model; the modelChoices (used to
populate the DDC component) based on the Item current configuration, calls a
service and returns a list of years associated with the selected
configuration.

Now the problem is that the PropertyModel does not set the year property on
the Item objectModel - the year property always have the NULL value. Somehow
I found that the problem is caused by calling item.getModelObject, but it
does not make sens for me (!?!)..   If instead of this I return a static
list, everything seems to work fine... (@see below)

  IModel modelChoices = new Model() {
    public Object getObject(final Component component) {
      List rValue = Collections.EMPTY_LIST;

      // THE PROBLEM IS HERE - CALLING Item.getModleObject() method. !!!
      ReportTemplateUI report = (ReportTemplateUI) item.getModelObject();

      Configuration config = report.getConfiguration();
      if (config == null) {
        return rValue;
      }
      rValue = getExtractionResultService().getAvailableYears(
          config.getId());
     
      //IF INSTEAD OF ABOVE CODE I RETURN A STATIC LIST - EVERYTHING WORKS
FINE

      return rValue;
    }
  };
  DropDownChoice selYear = new DropDownChoice("year",
      new PropertyModel(item.getModel(), "year"), modelChoices);

I found a workaround for this but it is a temporary solution until I find
the answer to this mysterious issue.
Is it a known issue, a bug, or this is not a correct approach to solve the
problem? Can you help me? 

Thank you!

PS: if you have any question regarding the code or anything else is not
clear, please don't hesitate to ask! Thank you again!
-- 
View this message in context: 
http://www.nabble.com/PropertyModel-misbehavior-tf3251590.html#a9038875
Sent from the Wicket - User mailing list archive at Nabble.com.


-------------------------------------------------------------------------
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