Jeremy,

On 2011-01-14 03:57, Jeremy Thomerson wrote:
I had encountered this issue and for one of my training classes, I threw
together a solution.  Your post prodded me to go ahead and post my
solution
as a blog post.  After dusting off my long-forgotten blog, here it is:
http://www.jeremythomerson.com/blog/2011/01/catching-all-feedback
-messages-that-arent-rendered-by-other-feedback-panels/ (or
http://bit.ly/eHUEuN if that gets chopped up).

Your solution is quite nice but I have a request: you use ComponentFeedbackMessageFilter. What if I wanted your functionality in some component only - not whole page - using ContainerFeedbackMessageFilter.

Example:

instead of yours:

// create the form above
form.add(new FeedbackPanel("feedback", new 
ComponentFeedbackMessageFilter(form)));

final TextField name = new TextField("name", new PropertyModel(productModel, 
"name"));
name.setRequired(true);
form.add(new FeedbackPanel("nameFeedback", new 
ComponentFeedbackMessageFilter(name)));
form.add(name);

final TextField price = new TextField("price", new PropertyModel(productModel, 
"price"));
price.setRequired(true);
price.add(new MinimumValidator(0d));
form.add(new FeedbackPanel("priceFeedback", new 
ComponentFeedbackMessageFilter(price)));
form.add(price);


I would love:

// create the form above
form.add(new FeedbackPanel("feedback", new 
RenderOnlyWhatMyChildrenMissedFeedbackMessageFilter(form)));
                                             ^^^^^^^^^^^^^^^^ [1]

final TextField name = new TextField("name", new PropertyModel(productModel, 
"name"));
name.setRequired(true);
form.add(new FeedbackPanel("nameFeedback", new 
ComponentFeedbackMessageFilter(name)));
form.add(name);

final TextField price = new TextField("price", new PropertyModel(productModel, 
"price"));
price.setRequired(true);
price.add(new MinimumValidator(0d));


form.add(new FeedbackPanel("priceFeedback", new 
ComponentFeedbackMessageFilter(price)));
^^^^^^^^^^^^^^^^^^^^^^^^^6 remove this line.

form.add(price);

This way nameFeedback renders messages for name component

"feedback" renders messages for "price" and other components left without own feedback panel but NOT from "name" as those messages would be rendered twice.


All we need is a slight modification of AllExceptFeedbackFilter that would take a root component instead of assuming page instance.

You code from example then could look something like;

// create the form above
final TextField name = new TextField("name", new PropertyModel(productModel, 
"name"));
name.setRequired(true);
form.add(new FeedbackPanel("nameFeedback", new 
ComponentFeedbackMessageFilter(name)));
form.add(name);

final TextField price = new TextField("price", new PropertyModel(productModel, 
"price"));
price.setRequired(true);
price.add(new MinimumValidator(0d));
form.add(price);

form.add(new FeedbackPanel("feedback", new AllExceptFeedbackFilter(form)));

hope you like the idea.

--
Leszek Gawron                              http://lgawron.blogspot.com

Reply via email to