wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wicket_new_user <murthy.m...@gmail.com>
Subject Issue while adding Custom Validator to ListMultipleChoice component
Date Fri, 28 Dec 2012 08:41:27 GMT
Hi,
is it possible to add Custom Validator (implenting IValidator<T>) for
ListMultipleChoice component?

when i'm trying to add validator to the the componnent using the below code, 

final ListMultipleChoice<Attribute> selectedFields = new
ListMultipleChoice<Attribute>("selected",
                new ListModel<Attribute>(new ArrayList<Attribute>()),
availableAttributesModel,
                FIELD_RENDERER);

selectedFields.setOutputMarkupId(true);
s*electedFields.add(new SelectedAttributesValidator());*

i'm seeing the below compilation error for the above statement
*The method add(IValidator<? super Collection<Attribute>>) in the type
FormComponent<Collection&lt;Attribute>> is not applicable for the arguments
(SelectedAttributesValidator)*


Following is the Validator Class
=========================
public class SelectedAttributesValidator implements
IValidator<ListMultipleChoice&lt;Attribute>>
{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * 
     */
    public void validate(IValidatable<ListMultipleChoice&lt;Attribute>>
validatable)
    {
        final ListMultipleChoice<Attribute> selectedFields =
validatable.getValue();

        if (CollectionUtils.isEmpty(selectedFields.getChoices()))
        {
            validatable.error(new
ValidationError().addMessageKey("attributesMustBeSelected"));
        }

    }

}

the reason i'm going for Custom Validator is as i'm unable to get the value
from the "getConvertedInput()" as it is showing always empty, when the form
is loaded with default values. Not able to understand what could be the
problem.


can one please let me know, if there is any issue in the above code?

Thanks




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Mime
View raw message