0

Having 2 or more instance of the same class(or extending from the same parent) in a view model

asked 2013-01-11 15:12:07 +0800

ottavio gravatar image ottavio
6

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

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-01-14 08:44:58 +0800

ottavio gravatar image ottavio
6

updated 2013-01-14 08:45:19 +0800

I have specified getters for all of my instance variables into the ViewModel

public BtorSearchCriteria getBtorSearchCriteria() {
		return btorSearchCriteria;
          }
           public RmmpEmailSearchCriteria getSearchCriteria() {
		return searchCriteria;
	
	}

link publish delete flag offensive edit
0

answered 2013-01-13 17:48:41 +0800

rdgrimes gravatar image rdgrimes
735 7

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2013-01-11 15:12:07 +0800

Seen: 53 times

Last updated: Jan 14 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More