use IComponentBorder and then simply add it to each form component or
subclass formcomponents and add it in the constructor,
eg textfield.add(new fieldborder());

-igor

public class FieldBorder implements IComponentBorder
{
    public static final IComponentBorder INSTANCE = new FieldBorder();

    public void renderAfter(Component component)
    {
        final Response out = component.getResponse();

        List<FeedbackMessage> errors =
component.getSession().getFeedbackMessages().messages(
                new ErrorsFilter(component));

        if (errors.size() > 0)
        {
            out.write("<ul class=\"errors\">");
            for (FeedbackMessage error : errors)
            {
                out.write("<li>");
                out.write(error.getMessage().toString());
                out.write("</li>");
            }
            out.write("</ul>");
        }

    }

    public void renderBefore(Component component)
    {
        component.setOutputMarkupId(true);

        final Response out = component.getResponse();



        final boolean required = isRequired(component);

        out.write("<label for=\"");
        out.write(component.getMarkupId());
        out.write("\">");


        if (required)
        {
            out.write("<strong><em>*</em>");
        }

        String label = null;

        if (component instanceof LabeledWebMarkupContainer)
        {
            IModel labelModel =
((LabeledWebMarkupContainer)component).getLabel();
            if (labelModel != null)
            {
                label = labelModel.getObject().toString();
            }
        }

        if (label == null)
        {
                label = component.getString(component.getId());
        }

        if (!Strings.isEmpty(label))
        {
            out.write(label);
            if (separator)
            {
                out.write(getSeparator());
            }
        }

        if (required)
        {
            out.write("</strong>");
        }

        out.write("</label>");
    }

    protected String getSeparator()
    {
        return ":";
    }

    private boolean isRequired(Component component)
    {
        if (component instanceof FormComponent)
        {
            return ((FormComponent)component).isRequired();
        }
        return false;
    }

    private static class ErrorsFilter implements IFeedbackMessageFilter
    {
        private final Component target;

        public ErrorsFilter(Component target)
        {
            this.target = target;
        }

        public boolean accept(FeedbackMessage message)
        {
            if (message.isError() && message.getReporter() != null)
            {
                if (target == message.getReporter())
                {
                    return true;
                }
                if (target instanceof MarkupContainer)
                {
                    if
(((MarkupContainer)target).contains(message.getReporter(), true))
                    {
                        return true;
                    }
                }
            }
            return false;

        }
    }


}


On Tue, Jan 13, 2009 at 12:20 PM, walnutmon <[email protected]> wrote:
>
> All,
>
> I have a page with many form components, nearly all of them have some kind
> of validation associated with them.  I have a feedback panel at the top, I'd
> like to move feedback next to each component.  I have thought of some ways
> to do this without changing a ton of code, however none really work in the
> end because I would still need to add some kind of HTML in order to display
> messages.
>
> Also, nearly everything like this that I have developed in wicket is usually
> accompanied by the discovery that wicket already has the functionality I'm
> looking for out of the box.  Searching has given me surprisingly little with
> regard to this topic though.  Can someone point me in the right direction?
> --
> View this message in context: 
> http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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]

Reply via email to