-5

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?

Phil
  • 157,677
  • 23
  • 242
  • 245
  • Does it mean you want to get the value of themePreview from the session to decide which CSS file is to use? – Martin Strejc Dec 23 '13 at 18:18
  • @MartinStrejc No. I'm wanting the `themePreview` to be a flag that only applies whilst navigating around the iframed version of the site. I'm thinking a `PageParameter` would apply best. It cannot be stored in the session as then it would apply outside the iframe which is not what I want – Phil Dec 23 '13 at 22:09
  • OK, so I use in my applications a general ancestor of all pages (e.g. MyBasePage) and when I need a general functionality it is implemented here very easy, including anything after PageParameters. Also I use it the same way as you described. – Martin Strejc Dec 23 '13 at 22:15

1 Answers1

1

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.

Martin Cassidy
  • 686
  • 1
  • 9
  • 28