You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sam Zilverberg <sa...@gmail.com> on 2011/01/26 17:32:30 UTC

FormComponentPanel and invalid child FormComponents question

I have a FormComponentPanel that represents a Time object - not
java.sql.Time but my own Time object.
This Time object has 2 fields - hours and minutes.
The panel has textfields for the hours and minutes that are defined as class
type Integer.

I have a behavior on the panel that whenever it has error feedback messages
it is added a css class that show a red border around it.
This works when I explicitly call panel.error("some error"). I do this when
the hour field is empty and the minutes field has a value.
But when I put an illegal Integer into the one of the textfields the
feedback error message is registered with the textfield so the
invalid-css-behavior doesn't trigger.

Is there a simple way to tell a form component to register all of it's
messages with some other form component -  in this case the panel?
Are there any other suggestion to get this desired behavior?

Thanks
-Sam

Re: FormComponentPanel and invalid child FormComponents question

Posted by Sam Zilverberg <sa...@gmail.com>.
Thanks again.
Just tried it out and it works perfect.

ContainerFeedbackMessageFilter for my form-comp-panel's feedback panel
allowed it to show it's children messages.

Using a visitor in my invalid-css-class-behavior allowed me to enable the
behavior when one of the children has an error.

This is how the isEnabled method in the invalid-css-class-behavior looks
like now:

@Override
    public boolean isEnabled(Component component)
    {
        if (component instanceof MarkupContainer)
        {
            if (component.hasErrorMessage()) return true;
            Object obj = ((MarkupContainer) component).visitChildren(new
IVisitor<Component>()
            {

                public Object component(Component component)
                {
                    if (component.hasErrorMessage())
                        return true;
                    else
                        return Component.IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            return super.isEnabled(component) && (obj != null) &&
(Boolean.TRUE.equals(obj));
        }
        else
            return super.isEnabled(component) &&
component.hasErrorMessage();
    }

kind of a mess but it works great :)

Re: FormComponentPanel and invalid child FormComponents question

Posted by Pedro Santos <pe...@gmail.com>.
Hi Sam, you can change the feedback panel to show not only messages
registered for the panel, but also for the inner components. The Wicket
feedback panel uses the IFeedbackMessageFilter to filter what messages to
display. You can provide one that test if the reporter is an panel children.
See ContainerFeedbackMessageFilter

On Wed, Jan 26, 2011 at 3:03 PM, Sam Zilverberg <sa...@gmail.com>wrote:

> That is an excellent idea.
> However I don't want to just set the panel to be invalid when one of it's
> children is invalid.
> I'd like to also "steal" its' feedback message.
> I want this to happen because I have a feedback panel next to the form
> component that shows feedback messages registered to it.
>
> Is there a simple way to achieve this?
>
> On Wed, Jan 26, 2011 at 6:39 PM, Igor Vaynberg <igor.vaynberg@gmail.com
> >wrote:
>
> > your form component panel should check if any of its children have
> > error messages as well. use a visitor.
> >
> > -igor
> >
> >
>



-- 
Pedro Henrique Oliveira dos Santos

Re: FormComponentPanel and invalid child FormComponents question

Posted by Igor Vaynberg <ig...@gmail.com>.
give the panel containerfeedbackmessagefilter which will filter on the
specified component and any of its children.

-igor

On Wed, Jan 26, 2011 at 9:03 AM, Sam Zilverberg <sa...@gmail.com> wrote:
> That is an excellent idea.
> However I don't want to just set the panel to be invalid when one of it's
> children is invalid.
> I'd like to also "steal" its' feedback message.
> I want this to happen because I have a feedback panel next to the form
> component that shows feedback messages registered to it.
>
> Is there a simple way to achieve this?
>
> On Wed, Jan 26, 2011 at 6:39 PM, Igor Vaynberg <ig...@gmail.com>wrote:
>
>> your form component panel should check if any of its children have
>> error messages as well. use a visitor.
>>
>> -igor
>>
>>
>

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


Re: FormComponentPanel and invalid child FormComponents question

Posted by Sam Zilverberg <sa...@gmail.com>.
That is an excellent idea.
However I don't want to just set the panel to be invalid when one of it's
children is invalid.
I'd like to also "steal" its' feedback message.
I want this to happen because I have a feedback panel next to the form
component that shows feedback messages registered to it.

Is there a simple way to achieve this?

On Wed, Jan 26, 2011 at 6:39 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> your form component panel should check if any of its children have
> error messages as well. use a visitor.
>
> -igor
>
>

Re: FormComponentPanel and invalid child FormComponents question

Posted by Igor Vaynberg <ig...@gmail.com>.
your form component panel should check if any of its children have
error messages as well. use a visitor.

-igor


On Wed, Jan 26, 2011 at 8:32 AM, Sam Zilverberg <sa...@gmail.com> wrote:
> I have a FormComponentPanel that represents a Time object - not
> java.sql.Time but my own Time object.
> This Time object has 2 fields - hours and minutes.
> The panel has textfields for the hours and minutes that are defined as class
> type Integer.
>
> I have a behavior on the panel that whenever it has error feedback messages
> it is added a css class that show a red border around it.
> This works when I explicitly call panel.error("some error"). I do this when
> the hour field is empty and the minutes field has a value.
> But when I put an illegal Integer into the one of the textfields the
> feedback error message is registered with the textfield so the
> invalid-css-behavior doesn't trigger.
>
> Is there a simple way to tell a form component to register all of it's
> messages with some other form component -  in this case the panel?
> Are there any other suggestion to get this desired behavior?
>
> Thanks
> -Sam
>

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