-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have 2 simple dateboxes namely
<datebox id="from"/>
<datebox id="to" constraint="${dualDateValidatorWithRange}"/>
They should work as from should always has a lower of less date than to and their difference should not be more than 48 months
I have a Constraint like this
private Integer monthRange;
private String nestedComponentName="from";
public void validate(final Component comp,final Object value) throws WrongValueException
{
log.info("Constraint method is called");
final Datebox currentDateBox = ((Datebox)comp);
if(monthRange!=null && monthRange>=0)
{
final Datebox from = (Datebox)comp.getFellow(nestedComponentName);//we locate the from datebox
currentDateBox.clearErrorMessage();//clear errors
from.clearErrorMessage();//clear errors
final Date dFrom = from.getValue();//the dates
final Date dTo = (Date)value;
if(dFrom != null && dTo != null)
{
final String message = buildedMessageFromDateboxDates;
if(dFrom.after(dTo))throw new WrongValueException(from,message);
final int currentMonthsBetween = DateUtilNewApi.getMonthsBetweenDates(dFrom,dTo);
if(currentMonthsBetween>monthRange.intValue())throw new WrongValueException(comp,rangeErrorMessage);
}
}
}
I have try to set on from date the date 30 of september of 2015 later i set on to datebox the date 28 of september of 2015 the constrains is fire correctly they say that the start date is upper the to date and the from datebox shows the wrong value exception is working like a charm my constraint is call and is working like expected.
The problem arises when after the constraint is fire and from datebox is selected i select no using the calendar just typing 2013 in place of 2015 and now the current date is 30 of september of 2013 and i click on a search button i use a code like this
private void search()
{
to.getValue();//here i expect the constraint is fire and compare the two new dates namely 30 of september of 2013 and 28 of september of 2015
}
But the problems arise
1). The constraint is not called because i cannot see the message "Constraint method is called" on the console." 2). The to datebox throws WrongValueException but why this? in my constraint from datebox should be fire as WrongValueException message but in the from datebox i dont understand this. 3). In the correct execution of the constraint the first time selecting a lower date in to datebox they show a correct message like this the Date 30 of september of 2015 is higher than 28 of september of 2015 this is correct but when the second time the constraint fires i guess, they shows the same message but why this i have changed the from datebox from 30-09-2015 to 30-09-2013? I dont understand here.
Seems that the to datebox constraint is cached or stale and both the constraint and the new value in datebox from is not binded to it.
This is driving me nuts why constraint is being fire why to datebox is select as a error message if i throws a WrongValueException from from datebox why i dont see the message "Constraint method is called" on the console."
The problem is solved just click on the datebox to and click on the button search the constraint is fire and both datebox has the current date and everything works like a charm. But the error shows incorrectly in the to datebox is very annoying.
I have created a fiddle here.
Asked: 2015-09-28 14:30:34 +0800
Seen: 31 times
Last updated: Sep 30 '15
wrong valueException come in front of modal popup [closed]
Use parameters in a conditional @command
Problems with multiple press and onCtrlKey
MVVM @save on the fly [closed]
Unable to activate destroyed desktop
org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException
How to put a image or Letter over image on a specific XY Coordinate
can you create a fiddle?
chillworld ( 2015-09-28 18:34:33 +0800 )editHello chillworld sample is created please take a look to my updated question.
javiut ( 2015-09-29 12:23:05 +0800 )editI'm playing with it but can't find the solution directly. If it is possible, can you use a form validator? I think this is better in this case. http://books.zkoss.org/wiki/ZKDeveloper'sReference/MVVM/Data_Binding/Validator
chillworld ( 2015-09-30 13:59:14 +0800 )editA form validator can you give a sample.
javiut ( 2015-10-01 20:39:00 +0800 )editIs a sample in mvvm good?
chillworld ( 2015-10-02 00:19:17 +0800 )edit