|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.j2ee.blueprints.ui.util.ResourcePhaseListener
public class ResourcePhaseListener
Leverage the Faces Lifecycle to load non-Java class resources out of jars in the web-app classloader. This class enables packing non-Java class resources associated with a component into the same jar as the classes of the component itself. For example, a component may require extra JavaScript and style sheet files. It is a burden to distribute these artifacts separately from the classes themselves.
Security Caution: The default operation of this class allows anyone to access the contents of the web app classloader using a simple HTTP get. Users are advised to restrict access to the "/resource" viewId such that such accesses are subject to standard Servlet security constraints.
Build-Time Usage
This listener is self-configured by placing the jar file in which
it is distributed into WEB-INF/lib
.
Referencing Resources Using this PhaseListener
Let's assume we have a JavaScript file in our component.jar under
the jar entry named /META-INF/autocomplete/script.js
.
To access this jar from a web page in a prefix mapped
FacesServlet
, the following <script> tag must be
used.
<script type="text/javascript"
src="faces/resource?r=/META-INF/autocomplete/script.js" />
To do so in an extension mapped FacesServlet
, do this:
<script type="text/javascript"
src="resource.faces?r=/META-INF/autocomplete/script.js" />
How it works
This class is very simple. Inspection of the above HTML code
reveals that we simply use a well known JSF view id of "resource"
combined with the query parameter named r
whose value is
the path to the resource in the web app classloader. An additional
query parameter of ct
is supported to pass the
content-type. If no ct
parameter is specified, this
class uses the extension to identify the content-type.
The following extension to content-type mappings are understood.
extension | content-type |
---|---|
js | text/javascript |
gif | image/gif |
jpeg | image/jpeg |
jpg | image/jpeg |
png | image/png |
ico | image/vnd.microsoft.icon |
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_CONTENT_TYPE
|
static java.lang.String |
RESOURCE_PREFIX
|
Constructor Summary | |
---|---|
ResourcePhaseListener()
Creates a new instance of ResourcePhaseListener |
Method Summary | |
---|---|
void |
afterPhase(javax.faces.event.PhaseEvent event)
|
void |
beforePhase(javax.faces.event.PhaseEvent phaseEvent)
|
javax.faces.event.PhaseId |
getPhaseId()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String RESOURCE_PREFIX
public static final java.lang.String DEFAULT_CONTENT_TYPE
Constructor Detail |
---|
public ResourcePhaseListener()
Method Detail |
---|
public javax.faces.event.PhaseId getPhaseId()
getPhaseId
in interface javax.faces.event.PhaseListener
public void beforePhase(javax.faces.event.PhaseEvent phaseEvent)
beforePhase
in interface javax.faces.event.PhaseListener
public void afterPhase(javax.faces.event.PhaseEvent event)
afterPhase
in interface javax.faces.event.PhaseListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |