You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by wicket_new_user <mu...@gmail.com> on 2012/12/28 09:41:27 UTC

Issue while adding Custom Validator to ListMultipleChoice component

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


Re: Issue while adding Custom Validator to ListMultipleChoice component

Posted by wicket_new_user <mu...@gmail.com>.
Collection<String> value = validatable.getValue(); 

This is returning as empty, because of the values are not selected in
thelist box

We have used custom implementaion of Palette box using List choice
component, i.e, moving of elements from from available to selected

If the items are in selected (blue highlighted, those items are showing in
the validator, otherwise no.

Is there a way to make the items selected by default in the selected box?


Thanks
WN



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091p4655104.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


Re: Issue while adding Custom Validator to ListMultipleChoice component

Posted by Sven Meier <sv...@meiers.net>.
Hi,

 >This is getting empty when it is loaded with default values.

You mean you have values in your model but they don't show up on a 
re-submit?

Please take a look at ListMultipleChoicePage in wicket-examples. If I 
add a validator there, everything works as expected:

         listChoice.add(new IValidator<Collection<String>>()
         {
             @Override
             public void validate(IValidatable<Collection<String>> 
validatable)
             {
                 Collection<String> value = validatable.getValue();
                 // value is filled with the now selected choices
             }
         });

Check what's different to your usage.

Sven

On 12/28/2012 11:10 AM, wicket_new_user wrote:
> thanks Sven for your reply. the syntax issue worked.
>
> But i'm, getting another probelm is
>
> final Collection<Attribute> selectedFields = validatable.getValue();
>
> This is getting empty when it is loaded with default values. Not sure if i'm
> missing anything to add here.
>
>
>
> Able to get the values only when the values or added to the list (i.e, the
> component gets modified)
>
>
>
> Also, I have observed that, in onSubmit(), the "updateModel()" iof
> ListMultipleChoice() s getting called to set the actual property values, and
> so the values are being displayed in in on submit when storing them in
> domain objects :-(.
> But it is not the case in Validating it :-(
>
> Thanks
> WN
>
>
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091p4655093.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
>


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


Re: Issue while adding Custom Validator to ListMultipleChoice component

Posted by wicket_new_user <mu...@gmail.com>.
thanks Sven for your reply. the syntax issue worked.

But i'm, getting another probelm is 

final Collection<Attribute> selectedFields = validatable.getValue();

This is getting empty when it is loaded with default values. Not sure if i'm
missing anything to add here.



Able to get the values only when the values or added to the list (i.e, the
component gets modified)



Also, I have observed that, in onSubmit(), the "updateModel()" iof
ListMultipleChoice() s getting called to set the actual property values, and
so the values are being displayed in in on submit when storing them in
domain objects :-(. 
But it is not the case in Validating it :-(

Thanks
WN







--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091p4655093.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


Re: Issue while adding Custom Validator to ListMultipleChoice component

Posted by Sven Meier <sv...@meiers.net>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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