I have a web application based on Apache Wicket. I have a problem with the usage of the method onBeforRender() of a web page. I need to use this method to intercept the creation of a page, and redirect the user to another page. If I use setResponsePage inside the onBeforeRender, the page is aniway rendered.
How Can I implement my desired behavior?
I think this should work:
throw new RestartResponseAtInterceptPageException(SomePage.class);
As it is an exception it should prevent any other code(=rendering) from being executed.
I'm not sure why you are redirecting. My guess is that it's an authorization topic. Then you might want to check out the IAuthorizationStrategy. It's described in the official Wicket docu. They have a very good documentation over there with lots of best practises and examples.
Which org.apache.wicket.settings.RequestCycleSettings.RenderStrategy do you use ? I believe your problem can happen only with org.apache.wicket.settings.RequestCycleSettings.RenderStrategy#ONE_PASS_RENDER.
Try to use #onInitialize() or #onConfigure() instead.
Related
http://pastebin.com/5Nvn1uSB this is my xhtml
http://pastebin.com/fqwiRQER this is home there is the code for menuitems that dont work...
http://pastebin.com/Phun7EKS this is registration with connection to db... but doesn't work at all not even running it
Well, I see lots of issues here. First, your description of what's happening is non-existent. It's pretty hard to help you when all you provide is code without a good description of your environment, what you expect to happen and what's actually happening.
Also, it would be helpful to know what steps you have already taken to debug your code.
That said, based on a quick read of your code, your p:commandButton is using an actionListener instead of an action which I believe is the correct attribute.
Lastly, you're using raw text fields from your web page to directly build an SQL statement. This opens you up to all kinds of code injection exploits that you probably want to avoid. You'd be better off using something like JPA as an abstraction layer that allows you to persist objects.
I'm using BalusC's FileServlet example:
http://balusc.blogspot.com/2007/07/fileservlet.html
I'm able to get it to work, however, I would like to call a bean function before the download takes place. Is there a way to make that work? I tried with a4j:support and I also tried with h:commandLink and neither worked. Any help is appreciated!
You could do the file download job in bean's action method instead. For some concrete examples, see this answer: How to provide a file download from a JSF backing bean?
You only need to make sure that the request isn't made by Ajax, because the JavaScript language, who is responsible for handling the Ajax request, does not have any facilities to force a Save As dialogue for security reasons. So, use a plain <h:commandLink> or <h:commandButton> for this.
I have written test Filter (javax.servlet.Filter) and started to debug. And I was surprised that one refresh of html page calls twice method doFilter().
Could anybody describe me why it happens ?
Thanks.
Perhaps your filter was called also for static elements (images, etc.). Check your filter path declaration in web.xml.
One way to check what's really happening is to use either Fiddler or Firebug. Or both.
Another strategy to use is printing value of request.getRequestURL().toString() before doFilter(), so you can see what requests are being served. It's difficult to pinpoint why are you seeing 2 requests because the cause might be hidden somewhere in your environment or configuration.
Fire up Fiddler and watch the requests being made.
I've read that wicket can't throw Checked exception. how to deal with this? What is a good way to implement exception handling in Wicket spring based application?
Mac
What do you mean, "Wicket can't throw". [citation needed] :)
Perhaps you read somewhere that wicket will not pass an exception to the servlet container in the default configuration?
I usually wrap specific components' methods with a try and change the page appropriately in catch, i.e. telling the user that something went wrong.
Update:
And also, you have the error(), warn() etc. in every Component which works with Feedback stuff. See here.
I am trying to clear everything on my HTML form when I visit it from a hyperlink entry.
Any ideas? My development language is java.
are you using session-scoped data? if so, close your browser and open it again.
I'm not sure the application is, but one way to accomplish this would be to use JavaScript. For example, if it is acceptable to clear the form every time that page is visited you could write a quick function that clears the form when the page is loaded (i.e., using the onload event).
If you only want to clear the form when the page is hit from that link you could add a param to the URL (e.g., clearForm=true) and use JavaScript to pick up the query string and clear the form when that parameter is present.
This is, of course, a purely client-side solution. For a server-side solution it would be helpful to know what framework you are using.