You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Wooldridge, Keith A" <Ke...@ManTech.com> on 2012/01/26 21:36:19 UTC

Wicket Feedback panels and Hibernate Validation

I'm trying to create a custom hibernate validator , based on bradhouse's solution in this StackOverflow thread<http://stackoverflow.com/questions/1972933/cross-field-validation-with-hibernate-validator-jsr-303>.  I'm passing in the field name that I would like the error message to be associated with to addNode.  Unfortunately, my ComponentFeedbackMessageFilter that is associated with the field in wicket does not know that the message was directed to it.  I know wicket is getting the validation error from Hibernate, because it shows up in my unfiltered feedback panel.

Could it be that I'm adding the feedback messages from a Behavior instead of from a FeedbackPanel directly?  The core of the Behavior, where the messages get attached , is this:

@Override
public void afterRender(Component component) {
      FormComponent<?> fc = (FormComponent<?>)component;
      Response r = component.getResponse();

      FeedbackMessages messages = fc.getSession().getFeedbackMessages();

      if (messages.hasMessageFor(component)) {
            r.write("<ul class=\"FeedbackStyle\">");
            IFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(component);
            for (FeedbackMessage message : messages.messages(filter)) {
                  r.write("<li class=\"feedbackPanel");
                  r.write(message.getLevelAsString().toUpperCase());
                  r.write("\">");
                  r.write(Strings.escapeMarkup(message.getMessage().toString()));
                  r.write("</li>");
            }
            r.write("</ul>");
      }
      r.write("</span>");
}

Thanks,

Keith Wooldridge



RE: Wicket Feedback panels and Hibernate Validation

Posted by "Wooldridge, Keith A" <Ke...@ManTech.com>.
No luck with this.  I tried checking message.getReporter() and it's always the form instead of the field.

Keith Wooldridge


-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org] 
Sent: Friday, January 27, 2012 3:24 AM
To: users@wicket.apache.org
Subject: Re: Wicket Feedback panels and Hibernate Validation

Hi,

On Thu, Jan 26, 2012 at 10:36 PM, Wooldridge, Keith A
<Ke...@mantech.com> wrote:
> I'm trying to create a custom hibernate validator , based on bradhouse's solution in this StackOverflow thread<http://stackoverflow.com/questions/1972933/cross-field-validation-with-hibernate-validator-jsr-303>.  I'm passing in the field name that I would like the error message to be associated with to addNode.  Unfortunately, my ComponentFeedbackMessageFilter that is associated with the field in wicket does not know that the message was directed to it.  I know wicket is getting the validation error from Hibernate, because it shows up in my unfiltered feedback panel.
>
> Could it be that I'm adding the feedback messages from a Behavior instead of from a FeedbackPanel directly?  The core of the Behavior, where the messages get attached , is this:
>
> @Override
> public void afterRender(Component component) {
>      FormComponent<?> fc = (FormComponent<?>)component;
>      Response r = component.getResponse();
>
>      FeedbackMessages messages = fc.getSession().getFeedbackMessages();
>
>      if (messages.hasMessageFor(component)) {
>            r.write("<ul class=\"FeedbackStyle\">");
>            IFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(component);
>            for (FeedbackMessage message : messages.messages(filter)) {

Try instead with:
 for (FeedbackMessage message : messages.messagesForComponent)

and then for each message:
message.markRendered();

>                  r.write("<li class=\"feedbackPanel");
>                  r.write(message.getLevelAsString().toUpperCase());
>                  r.write("\">");
>                  r.write(Strings.escapeMarkup(message.getMessage().toString()));
>                  r.write("</li>");
>            }
>            r.write("</ul>");
>      }
>      r.write("</span>");
> }
>
> Thanks,
>
> Keith Wooldridge
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Wicket Feedback panels and Hibernate Validation

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Thu, Jan 26, 2012 at 10:36 PM, Wooldridge, Keith A
<Ke...@mantech.com> wrote:
> I'm trying to create a custom hibernate validator , based on bradhouse's solution in this StackOverflow thread<http://stackoverflow.com/questions/1972933/cross-field-validation-with-hibernate-validator-jsr-303>.  I'm passing in the field name that I would like the error message to be associated with to addNode.  Unfortunately, my ComponentFeedbackMessageFilter that is associated with the field in wicket does not know that the message was directed to it.  I know wicket is getting the validation error from Hibernate, because it shows up in my unfiltered feedback panel.
>
> Could it be that I'm adding the feedback messages from a Behavior instead of from a FeedbackPanel directly?  The core of the Behavior, where the messages get attached , is this:
>
> @Override
> public void afterRender(Component component) {
>      FormComponent<?> fc = (FormComponent<?>)component;
>      Response r = component.getResponse();
>
>      FeedbackMessages messages = fc.getSession().getFeedbackMessages();
>
>      if (messages.hasMessageFor(component)) {
>            r.write("<ul class=\"FeedbackStyle\">");
>            IFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(component);
>            for (FeedbackMessage message : messages.messages(filter)) {

Try instead with:
 for (FeedbackMessage message : messages.messagesForComponent)

and then for each message:
message.markRendered();

>                  r.write("<li class=\"feedbackPanel");
>                  r.write(message.getLevelAsString().toUpperCase());
>                  r.write("\">");
>                  r.write(Strings.escapeMarkup(message.getMessage().toString()));
>                  r.write("</li>");
>            }
>            r.write("</ul>");
>      }
>      r.write("</span>");
> }
>
> Thanks,
>
> Keith Wooldridge
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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