The generic type of your validator should be:

public class SelectedAttributesValidator implements IValidator<Collection<Attribute>>

Sven

On 12/28/2012 09:41 AM, wicket_new_user wrote:
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

Reply via email to