• Post Reply Bookmark Topic Watch Topic
  • New Topic

XHTML inside WEB-INF

 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

http://stackoverflow.com/questions/6104498/jee6-packaging-jsf-facelets-xhtml-and-managedbeans-as-jar


Simple code.


package com.example;

import java.net.URL;

import javax.faces.view.facelets.ResourceResolver;

public class FaceletsResourceResolver extends ResourceResolver {

private ResourceResolver parent;
private String basePath;

public FaceletsResourceResolver(ResourceResolver parent) {
this.parent = parent;
this.basePath = "/WEB-INF/resources"; // TODO: Make configureable?
}

@Override
public URL resolveUrl(String path) {


if (url == null) {
url = getClass().getResource(basePath + path); // Resolves from WEB-INF.
}

return url;
}

}


Register it in the web.xml as follows:

<context-param>
<param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
<param-value>com.example.FaceletsResourceResolver</param-value>
</context-param>
 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a question in here somewhere?
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4 down vote accepted


You need to create a custom ResourceResolver which resolves resources from classpath, put it in the common JAR file and then declare it in web-fragment.xml of the JAR (or in web.xml of the WARs).

Kickoff example:

package com.example;

import java.net.URL;

import javax.faces.view.facelets.ResourceResolver;

public class FaceletsResourceResolver extends ResourceResolver {

private ResourceResolver parent;
private String basePath;

public FaceletsResourceResolver(ResourceResolver parent) {
this.parent = parent;
this.basePath = "/META-INF/resources"; // TODO: Make configureable?
}

@Override
public URL resolveUrl(String path) {
URL url = parent.resolveUrl(path); // Resolves from WAR.

if (url == null) {
url = getClass().getResource(basePath + path); // Resolves from JAR.
}

return url;
}

}

with in web-fragment.xml or web.xml

<context-param>
<param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
<param-value>com.example.FaceletsResourceResolver</param-value>
</context-param>

 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the point of these posts?
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the above approach correct? is it possible to put xhtmls inside WEB-INF and access it?
 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the underlying problem that you're trying to solve?
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put included xhtml under WEB-INF all the time.

However, technically, people don't access "xhtml", they make JSF URL requests, which the FacesServlet then deconstructs in order to locate the xhtm. So if you really wanted to put primary page xhtml under WEB-INF, you'd configure or modify the Facelets resource resolver.

However, you can also keep the xhtmls in the traditional (public) part of the WAR and protect them from direct abuse. A ServletFilter that rejects a URL ending with ".xhtml" would do it.

Or, if you're using the J2EE standard container security system, just enter a rule in web.xml that denies access for all URLs that end with .xhtml. No coding required.
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if you really wanted to put primary page xhtml under WEB-INF, you'd configure or modify the Facelets resource resolver.

I just wanted to put it in WEB_INF and want to configure resource resolver to locate xhtmls inside WEB_INF. How to configure Resource Resolver to do it, any example?
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions???
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!