Re: Custom validator variablesMap() - Value of variable [[input]] could not be resolved

2008-11-06 Thread Igor Vaynberg
this is done by formcomponent's messagesource. i would imagine it
wouldnt be set if you use the validator outside of standard
formcomponent validation - but in that case you dont have "input"
anyways.

see FormComponent:250 - at least that is the line number in trunk

// add the input param if not already present
if (!fullParams.containsKey("input"))
{
  fullParams.put("input", getInput());
}

-igor

On Thu, Nov 6, 2008 at 6:39 AM, Gianni Doe <[EMAIL PROTECTED]> wrote:
> Hi
> I've written a custom validator and error message and I'm adding my own
> variables to the error message by overriding variablesMap().
> My error message looks like thie:
> 
>${input} must be between
> ${startDate} and ${endDate}
> 
>
> As I understand 3 default variables should be substituted by the validator
> for ${label} ${input} and ${name}; if I use ${label} and ${name} they get
> substituted fine but ${input} is not:
>
> WicketMessage: Exception 'java.lang.IllegalArgumentException: Value of
> variable [[input]] could not be resolved while interpolating [[${input} must
> be between ${startDate} and ${endDate}]]' occurred during validation
> com.resprompt.webapp.validation.LocalDateTimeValidator$LocalDateTimeRangeValidator
> on component 0:carHireSearchForm:dropoffDate
>
> I've had a look through the source for the Wicket built-in validators and I
> can't seem any instance of 'input' being added explicitly to the
> variablesMap, any ideas why this isn't being set for me?
>
>
> public abstract class LocalDateTimeValidator extends
> AbstractValidator {
>
>private static final long serialVersionUID = -5922211613447031430L;
>private static Logger log =
> LoggerFactory.getLogger(LocalDateTimeValidator.class);
>
>public static  LocalDateTimeValidator range(U
> startDate, U endDate) {
>return new LocalDateTimeRangeValidator(startDate, endDate);
>}
>
>public static class LocalDateTimeRangeValidator
> extends LocalDateTimeValidator {
>
>private static final long serialVersionUID = -6335920679560594249L;
>private T startDate;
>private T endDate;
>
>public LocalDateTimeRangeValidator(T startDate, T endDate) {
>this.startDate = startDate;
>this.endDate = endDate;
>}
>
>@Override
>protected void onValidate(IValidatable validatable) {
>BaseLocal date = validatable.getValue();
>if (!(date.isAfter(startDate) && date.isBefore(endDate))) {
>error(validatable);
>}
>}
>
>@Override
>protected String resourceKey() {
>return "LocalDateTimeRangeValidator";
>}
>
>@Override
>protected Map variablesMap(IValidatable
> validatable) {
>Map map = super.variablesMap(validatable);
>map.put("startDate", startDate);
>map.put("endDate", endDate);
>return map;
>}
>}
> }
>
> Thanks
> Gianni
>
>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Custom validator variablesMap() - Value of variable [[input]] could not be resolved

2008-11-06 Thread Gianni Doe

Hi
I've written a custom validator and error message and I'm adding my  
own variables to the error message by overriding variablesMap().

My error message looks like thie:

${input} must be between  
${startDate} and ${endDate}



As I understand 3 default variables should be substituted by the  
validator for ${label} ${input} and ${name}; if I use ${label} and $ 
{name} they get substituted fine but ${input} is not:


WicketMessage: Exception 'java.lang.IllegalArgumentException: Value of  
variable [[input]] could not be resolved while interpolating [[$ 
{input} must be between ${startDate} and ${endDate}]]' occurred during  
validation com.resprompt.webapp.validation.LocalDateTimeValidator 
$LocalDateTimeRangeValidator on component  
0:carHireSearchForm:dropoffDate


I've had a look through the source for the Wicket built-in validators  
and I can't seem any instance of 'input' being added explicitly to the  
variablesMap, any ideas why this isn't being set for me?



public abstract class LocalDateTimeValidator  
extends AbstractValidator {


private static final long serialVersionUID = -5922211613447031430L;
private static Logger log =  
LoggerFactory.getLogger(LocalDateTimeValidator.class);


public static  LocalDateTimeValidator  
range(U startDate, U endDate) {

return new LocalDateTimeRangeValidator(startDate, endDate);
}

public static class LocalDateTimeRangeValidatorBaseLocal> extends LocalDateTimeValidator {


private static final long serialVersionUID =  
-6335920679560594249L;

private T startDate;
private T endDate;

public LocalDateTimeRangeValidator(T startDate, T endDate) {
this.startDate = startDate;
this.endDate = endDate;
}

@Override
protected void onValidate(IValidatable validatable) {
BaseLocal date = validatable.getValue();
if (!(date.isAfter(startDate) && date.isBefore(endDate))) {
error(validatable);
}
}

@Override
protected String resourceKey() {
return "LocalDateTimeRangeValidator";
}

@Override
protected Map variablesMap(IValidatable  
validatable) {

Map map = super.variablesMap(validatable);
map.put("startDate", startDate);
map.put("endDate", endDate);
return map;
}
}
}

Thanks
Gianni




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]