-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I've discovered that if there are two or more instances of the same class(or extending from the same parent) in a view model, if they don't override the equals() method, the binding sometime get in confusion.
For example i have 2 classes: EmailSearchCriteria and BtorSearchCriteria both extending from SearchCriteria.
public class RmmpEmailSearchCriteria extends SearchCriteria{ private Date dateFrom = null; public Date getDateFrom() { return dateFrom; } public void setDateFrom(Date dateFrom) { this.dateFrom = dateFrom; } } ;
public class BtorSearchCriteria extends SearchCriteria{ private Date travelStartDate = null; public Date getTravelStartDate() { return travelStartDate; } public void setTravelStartDate(Date travelStartDate) { this.travelStartDate = travelStartDate; } }
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class) public class RmmpSearchViewModel{ private RmmpEmailSearchCriteria searchCriteria; private BtorSearchCriteria btorSearchCriteria; }
In my viewmodel i have an instance of EmailSearchCriteria called searchCriteria and an instance of BtorSearchCriteria called btorSearchCriteria.In the zul file i have 2 different calendar widgets binded to 2 instance variable of the different classes:
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class) public class RmmpSearchViewModel{ private RmmpEmailSearchCriteria searchCriteria; private BtorSearchCriteria btorSearchCriteria; }
<datebox sclass="formInput" id="emailDateFrom" value="@load(vm.searchCriteria.dateFrom) @save(vm.searchCriteria.dateFrom)" />
<datebox sclass="formInput" id="btorDateFrom" value="@bind(vm.btorSearchCriteria.travelStartDate)" />
When i change the value of the datebox "emailDateFrom" the following message appear: Property 'dateFrom' not found on type org.fao.cio.rmmp.search.model.BtorSearchCriteria
When i change the value of the datebox "btorDateFrom" the following message appear: Property 'travelStartDate' not found on type org.fao.cio.rmmp.search.model.RmmpEmailSearchCriteria
I mean, i think it's not a bug, because it's a best practice to implement our own version of equals, but at least should be reported.
Ever happened to anyone?
Thank you
Ottavio Monzione
I have specified getters for all of my instance variables into the ViewModel
public BtorSearchCriteria getBtorSearchCriteria() { return btorSearchCriteria; } public RmmpEmailSearchCriteria getSearchCriteria() { return searchCriteria; }
I believe your problem is actually that your viewmodels don't have getter/setter methods for either searchCriteria or btorSearchCriteria. When you do @bind to vm.btorSearchCriteria.travelStartDate, the BindComposer actually looks for vm.getBtorSearchCriteria().getTravelStartDate(). So, when your error message says it can't find the "Property 'travelStartDate'", it's a bit deceptive because it's not actually looking for the property; it's looking for the property's associated getter/setter methods.
Asked: 2013-01-11 15:12:07 +0800
Seen: 53 times
Last updated: Jan 14 '13