Hi, first i want to apologize my bad english.
I having the next problem in faces 2.0. I created a multi module web solution and i need to put pages resources into the jars libs.
I had tried this configurations
the jar contents the next structure and lives in WEB-INF/lib path
META-INF/faces-config.xml
META-INF/resources/someResource.xhtml
I understand that faces 2.0 scans each jar in classpath and looks for META-INF/faces-config.xml and it puts avariables all contents under META-INF/resources path.
I had successful created a taglib under the jar and reference it without any problem but, when i just want to reference a simple xhtml under resources folder in jar it returns the following message.
<ui:include src="resources/test123.xhtml"> Invalid path : resources/test123.xhtml
someone have any idea???
thanks a lot
xhtml in jar lib.
Hi,
You can not reference a simple xhtml under resources folder in jar with ui:include. Use composite components.
You can not reference a simple xhtml under resources folder in jar with ui:include. Use composite components.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
Really? You know if with servlet 3.0 specification that defines web parts in jar files i could do this or it's another waste of time?
I need to have a web multi module faces that we can develop each module individually. how can do this with jsf primefaces
thanks!
I need to have a web multi module faces that we can develop each module individually. how can do this with jsf primefaces
thanks!
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
I think you need to write a custom facelets resource resolver to include xhtml from jars.
Oks!! just works!
I paste the code that I use for do this. If any are interested
The classes
public class CustomResourceResolver extends DefaultResourceResolver
{
@Override
public URL resolveUrl(String resource)
{
URL resourceUrl = super.resolveUrl(resource);
if (resourceUrl == null)
{
if (resource.startsWith("/"))
{
resource = resource.substring(1);
}
resourceUrl = Thread.currentThread().getContextClassLoader().getResource(resource);
}
return resourceUrl;
}
}
public class CustomExternalContext extends ExternalContextWrapper {
private ExternalContext wrapped;
public IPolarisExternalContext(ExternalContext wrapped) {
this.wrapped = wrapped;
}
public URL getResource(String path) throws MalformedURLException {
System.out.println("Looking for " + path);
URL url = Thread.currentThread().getContextClassLoader().getResource(path.substring(1));
if (url == null) {
url = getWrapped().getResource(path);
}
return url;
}
@Override
public ExternalContext getWrapped() {
return wrapped;
}
}
public class CustomExternalContextFactory extends ExternalContextFactory {
private ExternalContextFactory parent;
public IPolarisExternalContextFactory (ExternalContextFactory parent) {
super();
this.parent = parent;
}
@Override
public ExternalContext getExternalContext(Object context, Object request, Object response) throws FacesException {
return new IPolarisExternalContext(getWrapped().getExternalContext(context, request, response));
}
@Override
public ExternalContextFactory getWrapped() {
return parent;
}
}
On faces-config.xml
<factory>
<external-context-factory>CustomExternalContextFactory</external-context-factory>
</factory>
And if u want serve images, js and css just write another servlet that handles this type of request, here some code of that...
/**
* This servlet fetches a static resource from the classpath. Access to
* java class files is restricted.
*/
public class ClasspathServlet extends HttpServlet {
private Logger log = Logger.getLogger(getClass().getName());
/** default constructor */
public ClasspathServlet() {}
/** serve the file from the classpath */
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
/* if this servlet is not mapped to a path, use the request URI */
String path = String.format("%s%s",request.getServletPath(), request.getPathInfo());
if (path == null) {
path = request.getRequestURI().substring(
request.getContextPath().length());
}
/* failure conditions */
if (path.endsWith(".class")) {
response.sendError(403, path + " denied");
return;
}
/* find the resource */
log.fine("Looking for " + path + " on the classpath");
URL resource = Thread.currentThread().getContextClassLoader().
getResource(path.substring(1));
if (resource == null) {
response.sendError(404, path + " not found on classpath");
} else {
/* check modification date */
URLConnection connection = resource.openConnection();
long lastModified = connection.getLastModified();
long ifModifiedSince = request.getDateHeader("If-Modified-Since");
if (ifModifiedSince != -1 && lastModified <= ifModifiedSince) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
/* write to response */
response.setContentType(getServletContext().getMimeType(path));
OutputStream out = new BufferedOutputStream(
response.getOutputStream(), 512);
InputStream in = new BufferedInputStream(
resource.openStream(), 512);
try {
int len;
byte[] data = new byte[512];
while ((len = in.read(data)) != -1) {
out.write(data, 0, len);
}
} finally {
out.close();
in.close();
if (connection.getInputStream() != null) {
connection.getInputStream().close();
}
}
}
} /* doGet() */
}
I hope that helps. Thanks for the help!!!
I paste the code that I use for do this. If any are interested
The classes
public class CustomResourceResolver extends DefaultResourceResolver
{
@Override
public URL resolveUrl(String resource)
{
URL resourceUrl = super.resolveUrl(resource);
if (resourceUrl == null)
{
if (resource.startsWith("/"))
{
resource = resource.substring(1);
}
resourceUrl = Thread.currentThread().getContextClassLoader().getResource(resource);
}
return resourceUrl;
}
}
public class CustomExternalContext extends ExternalContextWrapper {
private ExternalContext wrapped;
public IPolarisExternalContext(ExternalContext wrapped) {
this.wrapped = wrapped;
}
public URL getResource(String path) throws MalformedURLException {
System.out.println("Looking for " + path);
URL url = Thread.currentThread().getContextClassLoader().getResource(path.substring(1));
if (url == null) {
url = getWrapped().getResource(path);
}
return url;
}
@Override
public ExternalContext getWrapped() {
return wrapped;
}
}
public class CustomExternalContextFactory extends ExternalContextFactory {
private ExternalContextFactory parent;
public IPolarisExternalContextFactory (ExternalContextFactory parent) {
super();
this.parent = parent;
}
@Override
public ExternalContext getExternalContext(Object context, Object request, Object response) throws FacesException {
return new IPolarisExternalContext(getWrapped().getExternalContext(context, request, response));
}
@Override
public ExternalContextFactory getWrapped() {
return parent;
}
}
On faces-config.xml
<factory>
<external-context-factory>CustomExternalContextFactory</external-context-factory>
</factory>
And if u want serve images, js and css just write another servlet that handles this type of request, here some code of that...
/**
* This servlet fetches a static resource from the classpath. Access to
* java class files is restricted.
*/
public class ClasspathServlet extends HttpServlet {
private Logger log = Logger.getLogger(getClass().getName());
/** default constructor */
public ClasspathServlet() {}
/** serve the file from the classpath */
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
/* if this servlet is not mapped to a path, use the request URI */
String path = String.format("%s%s",request.getServletPath(), request.getPathInfo());
if (path == null) {
path = request.getRequestURI().substring(
request.getContextPath().length());
}
/* failure conditions */
if (path.endsWith(".class")) {
response.sendError(403, path + " denied");
return;
}
/* find the resource */
log.fine("Looking for " + path + " on the classpath");
URL resource = Thread.currentThread().getContextClassLoader().
getResource(path.substring(1));
if (resource == null) {
response.sendError(404, path + " not found on classpath");
} else {
/* check modification date */
URLConnection connection = resource.openConnection();
long lastModified = connection.getLastModified();
long ifModifiedSince = request.getDateHeader("If-Modified-Since");
if (ifModifiedSince != -1 && lastModified <= ifModifiedSince) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
/* write to response */
response.setContentType(getServletContext().getMimeType(path));
OutputStream out = new BufferedOutputStream(
response.getOutputStream(), 512);
InputStream in = new BufferedInputStream(
resource.openStream(), 512);
try {
int len;
byte[] data = new byte[512];
while ((len = in.read(data)) != -1) {
out.write(data, 0, len);
}
} finally {
out.close();
in.close();
if (connection.getInputStream() != null) {
connection.getInputStream().close();
}
}
}
} /* doGet() */
}
I hope that helps. Thanks for the help!!!
-
- Information
-
Who is online
Users browsing this forum: No registered users and 32 guests