0

Zk Datebox validator and constraint problem

asked 2015-09-28 14:30:34 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

updated 2015-09-30 11:31:56 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

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.

http://zkfiddle.org/sample/30j79n8/2/

delete flag offensive retag edit

Comments

can you create a fiddle?

chillworld ( 2015-09-28 18:34:33 +0800 )edit

Hello chillworld sample is created please take a look to my updated question.

javiut ( 2015-09-29 12:23:05 +0800 )edit

I'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 )edit

A form validator can you give a sample.

javiut ( 2015-10-01 20:39:00 +0800 )edit

Is a sample in mvvm good?

chillworld ( 2015-10-02 00:19:17 +0800 )edit
Be the first one to answer this question!
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
1 follower

RSS

Stats

Asked: 2015-09-28 14:30:34 +0800

Seen: 31 times

Last updated: Sep 30 '15

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