You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Entropy <bl...@gmail.com> on 2019/11/26 15:53:21 UTC

Feedback messages not showing on first request

We have a page where we are being required to have multiple feedback panels,
and to show messages in various ones depending on the error.  Our solution
was to use message filters and to put the messages against certain
containers to say 'any message in container X goes to feedback panel X'.  

You can see the code below for example.  The request thing is just to set
the class of the feedbackpanel to a different value.  But we also control
the visibility of the panel by checking 'anyMessage()'.  So if there's no
errors, no feedback shows.  

This all works...except on the first request.  For some reason when I click
the button, I can see the error (it's added during the onSubmit(), not
during the normal validation step if that makes a difference) added to the
assetLookupOptionsWMC, but then when anyMessage() runs, it doesn't find the
error.  Click the button a second time, and it works perfectly.

Any idea why?

		assetLookupOptionsFP.setFilter(new IFeedbackMessageFilter(){
			private static final long serialVersionUID = 1L;

			@Override
			public boolean accept(FeedbackMessage msg) {
				Component reporter = msg.getReporter();
				HttpServletRequest request = ((HttpServletRequest)
getRequest().getContainerRequest());
				
				if (reporter.getId().equals("assetLookupOptionsWMC")){
					if(msg.isError())
						request.setAttribute("assetLookupOptionsFeedbackPanelHasError",
"TRUE");
					return true;
				} else if
(reporter.getParent().getId().equals("assetLookupOptionsWMC")){
					if(msg.isError())
						request.setAttribute("assetLookupOptionsFeedbackPanelHasError",
"TRUE");
					return true;
				} else {
					return false;
				}
			}
			
		});

--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html

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


Re: Feedback messages not showing on first request

Posted by Sven Meier <sv...@meiers.net>.
Hi,

your isVisible() might be called to often or early.

FeedbackMessagesModel caches the messages during request, so the call to 
#anyMessage() might result in a premature collection of messages.

Try override #onConfigure() instead, this is preferred over overriding 
#isVisible():

             @Override
             protected void onConfigure()
             {
                 super.onConfigure();
                 setVisible(anyMessage());
             }

Have fun
Sven


On 02.12.19 14:32, Entropy wrote:
> The isVisible():
>
> 		assetLookupOptionsFP = new FeedbackPanel("assetLookupOptionsFP"){
> 			private static final long serialVersionUID = 1L;
> 			
> 			@Override
> 			public boolean isVisible() {
> 				if (anyMessage()){
> 					return true;
> 				} else {
> 					return false;
> 				}
> 			}
> 		};
>
> --
> Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html
>
> ---------------------------------------------------------------------
> 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


Re: Feedback messages not showing on first request

Posted by Entropy <bl...@gmail.com>.
The isVisible():

		assetLookupOptionsFP = new FeedbackPanel("assetLookupOptionsFP"){
			private static final long serialVersionUID = 1L;
			
			@Override
			public boolean isVisible() {
				if (anyMessage()){
					return true;
				} else {
					return false;
				}
			}
		};

--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html

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


Re: Feedback messages not showing on first request

Posted by Sven Meier <sv...@meiers.net>.
Hi,

hard to tell from your code snippet.

Could you remove the irrelevant part (the request attribute) and show us 
the visibility control instead?

A quickstart would help too.

Have fun
Sven


On 26.11.19 16:53, Entropy wrote:
> We have a page where we are being required to have multiple feedback panels,
> and to show messages in various ones depending on the error.  Our solution
> was to use message filters and to put the messages against certain
> containers to say 'any message in container X goes to feedback panel X'.
>
> You can see the code below for example.  The request thing is just to set
> the class of the feedbackpanel to a different value.  But we also control
> the visibility of the panel by checking 'anyMessage()'.  So if there's no
> errors, no feedback shows.
>
> This all works...except on the first request.  For some reason when I click
> the button, I can see the error (it's added during the onSubmit(), not
> during the normal validation step if that makes a difference) added to the
> assetLookupOptionsWMC, but then when anyMessage() runs, it doesn't find the
> error.  Click the button a second time, and it works perfectly.
>
> Any idea why?
>
> 		assetLookupOptionsFP.setFilter(new IFeedbackMessageFilter(){
> 			private static final long serialVersionUID = 1L;
>
> 			@Override
> 			public boolean accept(FeedbackMessage msg) {
> 				Component reporter = msg.getReporter();
> 				HttpServletRequest request = ((HttpServletRequest)
> getRequest().getContainerRequest());
> 				
> 				if (reporter.getId().equals("assetLookupOptionsWMC")){
> 					if(msg.isError())
> 						request.setAttribute("assetLookupOptionsFeedbackPanelHasError",
> "TRUE");
> 					return true;
> 				} else if
> (reporter.getParent().getId().equals("assetLookupOptionsWMC")){
> 					if(msg.isError())
> 						request.setAttribute("assetLookupOptionsFeedbackPanelHasError",
> "TRUE");
> 					return true;
> 				} else {
> 					return false;
> 				}
> 			}
> 			
> 		});
>
> --
> Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html
>
> ---------------------------------------------------------------------
> 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