Question

Ok, what I'm trying to do is come up with a way to apply certain application settings (CSS to be exact) but only within an iframed version of the app.

If you've used Wordpress, I'm basically trying to implement a version of the theme live preview where it opens a version of the application in an iframe with theme changes made only to that instance of the site. I think it (Wordpress) does this by using JavaScript to change all the links to AJAX POST requests with the chosen theme as part the parameters.

I was thinking I might be able to do something similar by adding a page parameter (themePreview or something similar), detect that and apply the temporary (session) style properties. I already have a custom CssResourceReference that does this albeit without the page parameter detection though that seems simple enough.

My main problem is, I want the user to be able to navigate around the site within the iframe. To do so, I would need to maintain, persist or somehow inject the themePreview page parameter into all page requests when it is already set.

Does anybody know how to accomplish this or alternatively, have a better idea?

Was it helpful?

Solution

Links in wicket work by calling the urlFor method of the request cycle. This includes a URL renderer which all URLs are passed through when they are being generated.

If you:

  • Write a sub class for UrlRenderer to add your themePreview parameter to all urls if it was a parameter in the request
  • Write a sub class of RequestCycle and override the newUrlRenderer() to return your UrlRenderer.
  • Create your own implementation of IRequestCycleProvider to provide your custom RequestCycle
  • In your application class, in the init method, call setRequestCycleProvider passing your custom IRequestCycleProvider.

This way, if the themePreview parameter is present in a request, it will be automatically added to any URL that is generated and so will be present on any link within your iframe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top