You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by walnutmon <ju...@gmail.com> on 2009/02/09 16:26:34 UTC
Re: Form Components With Built In Feedback
Igor,
I know this is old, but in a post this morning you reminded me-it got lost
in the shuffle at work lately. When I tried to implement this, I realized
that IComponentBorder doesn't really extend from anything that can be added
to a component. It extends IClusterable, which extends Serializeable, so I
didn't know how to link it to a component.
Simply adding it to a form component doesn't work, I also looked at using
behaviors but they have "renderBefore", not "beforeRender".
Thanks!
Justin
igor.vaynberg wrote:
>
> 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 <ju...@gmail.com>
> 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: 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
>
>
>
--
View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21915152.html
Sent from the Wicket - User 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: Form Components With Built In Feedback
Posted by walnutmon <ju...@gmail.com>.
Sorry for the double post, but after more investigation I also seem to have a
problem with the "out.write()", since it is writing directly to the HTML,
won't that always stack these errors if there is some ajax call to it
multiple times in a row? I want to only have one message displayed for a
component at a time, or at least only one set of them... Not a list of
errors since the last page load.
Thanks!
Justin
walnutmon wrote:
>
> Igor,
>
> I know this is old, but in a post this morning you reminded me-it got lost
> in the shuffle at work lately. When I tried to implement this, I realized
> that IComponentBorder doesn't really extend from anything that can be
> added to a component. It extends IClusterable, which extends
> Serializeable, so I didn't know how to link it to a component.
>
> Simply adding it to a form component doesn't work, I also looked at using
> behaviors but they have "renderBefore", not "beforeRender".
>
> Thanks!
> Justin
>
>
> igor.vaynberg wrote:
>>
>> 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 <ju...@gmail.com>
>> 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: 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
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21916822.html
Sent from the Wicket - User 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