Prefixing Resources URL

UI Components for JSF
Post Reply
wingnut
Posts: 3
Joined: 16 Oct 2009, 14:56

16 Oct 2009, 15:05

Hiyas,

We're using PrimeFaces in our business app and so far everything is fine. However, as this application goes live we are proxying requests from a different server down to the application server itself. Due to this, all of our link URLs need to be prefixed with a "base url" that is passed to us in the header from the proxy server. This works fine for all URLs that we have control over, however, the resources URLs are not modifiable as they are written by PrimeFaces.

I was looking at the source and in ResourcesUtils there is the following lines of code that create the URLs that PrimeFaces write:

Code: Select all

		String contextPath = facesContext.getExternalContext().getRequestContextPath();		
		return contextPath + RESOURCE_PATTERN + VERSION_INFO + resource;
The contextPath is the one that we basically prepend with a URL, but as we cannot control this part of the code (or modify the contextPath in the ExternalContext), the URLs written are wrong.

Would it be possible for the <resources> tag to take a prefix option (ideally populated via EL) so that we can prefix all the Resource URLs with the necessary base url? Something like:

Code: Select all

<p:resources prefix="#{bean.baseUrl}" />
Which would essentially change the code to:

Code: Select all

		return prefix + contextPath + RESOURCE_PATTERN + VERSION_INFO + resource;
Or is there any workaround that can be done to achieve what we're after? I've tried overriding the ResponseWriter to intercept primefaces URLs but didn't manage to get that to work.

Regards,
Emil

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

19 Oct 2009, 11:58

Hi Emil,

Yes I think we can do that, so the prefix would be the address of the other server right? Are you going to deploy the same app to the other server just to get the resources?

Code: Select all

<p:resources host="prefix_here" />
Should do the trick. What do you think?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

19 Oct 2009, 11:59

Or a context param like;

Code: Select all

primefaces.RESOURCE_HOST

wingnut
Posts: 3
Joined: 16 Oct 2009, 14:56

19 Oct 2009, 13:43

Correct, basically all requests are passed through Server A, then a base URL is appended to the header from that server, which our server - Server B - then reads and appends to all URLs rendered by JSF (so that every request - regardless of what it is - goes through Server A). I know it's not pretty but sometimes "corporate" means "madness" :shock:

Any solution that you've proposed is fine, I'll let you decide, I'm just happy if we can prepend it somehow!

Cheers,
Emil

wingnut
Posts: 3
Joined: 16 Oct 2009, 14:56

19 Oct 2009, 13:48

And on second thought I think the host="" option is probably the best, if it can be fetched with EL, as depending if you cache the primefaces constants or not, we might not know the base URL until a request arrives on the server.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

19 Oct 2009, 13:51

All right, cool, I'll try to add it this week soon so you can take it for a test drive. First way would mean setting it to all p:resources, if you have it in your facelets page it would be ok since you don't have to set this setting on each page. On the other hand context param can set it globally. I need to think :)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests