WebFacetsHOW-TOsAuthentication
YourKit Java Profiler |
InstallationInstallation and configuration of WebFacets is very simple (if you know a little bit of J2EE Web applications). Here under are the main requirements :
These steps are fully described below. Include required libraries to your webappFirst you have to include the JFacets libraries, by copying the jars to
There are other jars in the JFacets distribution touchgraph & jgoodies), which are used for the JFacetsIDE? and are not required by the webapp. Configure WebFacetsSpring context : injection of user-supplied components & general configurationConfiguration of user-supplied components for WebFacets is exactly the same than for JFacets. You simply have to define your profile repository implementation, the XML facets descriptor file name (if you use Java/XML facets) and the base packages (if you use groovy facets) in the Spring ApplicationContext. You may have a look at the JFacets configuration page for more infos about this. Here under is the code of a template context (provided in the JFacets distribution - <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- A Spring Context for WebFacets that already provides support for Java/XML and Groovy facets. Configurable stuff in there : * profileRepository : specify your implementation class (and config options if any) ; * xmlFacetDescriptorManager : specify the path the the XML file (CLASSPATH resource) ; * groovyFacetDescriptorManager : specify the base packages for Groovy facets discovery. --> <beans> <!-- --> <!-- ProfileRepository --> <!-- --> <!-- This *has* to be configured --> <!-- for your application. --> <!-- --> <bean id="profileRepository" singleton="true" class="net.sourceforge.jfacets.simpleprofiles.SimpleProfileRepository"> </bean> <!-- --> <!-- Facet Managers --> <!-- --> <!-- The config below allows to use --> <!-- both plain java and groovy --> <!-- facets in the same app. --> <!-- --> <!-- Look at each manager's config --> <!-- options. --> <!-- --> <!-- the XML facet descriptor manager --> <bean id="xmlFacetDescriptorManager" singleton="true" class="net.sourceforge.jfacets.impl.FacetDescriptorManager"> <constructor-arg index="0"><value>facets.xml</value></constructor-arg> </bean> <!-- the Groovy facet descriptor manager --> <bean id="groovyFacetDescriptorManager" singleton="true" class="net.sourceforge.jfacets.groovy.GroovyFacetDescriptorManager" init-method="initialize"> <constructor-arg index="0"> <list> <value>groovy-facets</value> </list> </constructor-arg> </bean> <!-- the main facet descriptor manager, used for wrapping the other ones transparently --> <bean id="facetDescriptorManager" singleton="true" class="net.sourceforge.jfacets.impl.MetaFacetDescriptorManager" init-method="initialize"> <property name="managers"> <list> <ref bean="groovyFacetDescriptorManager"/> <ref bean="xmlFacetDescriptorManager"/> </list> </property> </bean> <!-- --> <!-- Facet & Facet Context factories --> <!-- --> <!-- No additional config is --> <!-- required here. --> <!-- --> <!-- a fall back factory, so that we can crate non-groovy facets too --> <bean id="fallbackFacetFactory" singleton="true" class="net.sourceforge.jfacets.impl.DefaultFacetFactory"> </bean> <!-- the main facet factory : creates GroovyFacets --> <bean id="facetFactory" singleton="true" class="net.sourceforge.jfacets.groovy.GroovyFacetFactory"> <property name="fallbackFactory"><ref bean="fallbackFacetFactory"/></property> </bean> <!-- the web facet context factory --> <bean id="facetContextFactory" singleton="false" class="net.sourceforge.jfacets.web.WebFacetContextFactory"> </bean> <!-- --> <!-- Facet Repository --> <!-- --> <!-- No additional config is required --> <!-- here. --> <!-- --> <bean id="facetRepository" singleton="false" class="net.sourceforge.jfacets.impl.FacetRepositoryImpl"> <constructor-arg index="0"><ref bean="profileRepository"/></constructor-arg> <constructor-arg index="1"><ref bean="facetFactory"/></constructor-arg> <constructor-arg index="2"><ref bean="facetContextFactory"/></constructor-arg> <constructor-arg index="3"><ref bean="facetDescriptorManager"/></constructor-arg> </bean> <!-- --> <!-- top-level WebFacets bean --> <!-- --> <!-- No additional config is required --> <!-- here. --> <!-- --> <bean id="jFacets" singleton="false" class="net.sourceforge.jfacets.web.WebFacets"> <property name="facetRepository"><ref bean="facetRepository"/></property> </bean> </beans> WebFacetsFilter config in the Deployment Descriptor (web.xml)A few things have to be added to your web application's Deployment Descriptor in order to enable WebFacets. You have to declare and configure the WebFacetsFilterin your <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <!-- Configuration of the WebFacets Filter. --> <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <filter> <display-name>WebFacetsFilter</display-name> <filter-name>WebFacetsFilter</filter-name> <filter-class>net.sourceforge.jfacets.web.WebFacetsFilter</filter-class> <!-- Optional init parameter for the WebFacets Filter. --> <!-- <init-param> <param-name>appCtxName</param-name> <param-value>myAppCtx.xml</param-value> </init-param> --> </filter> <filter-mapping> <filter-name>WebFacetsFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>WebFacetsFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> The Spring Context can be loaded in several ways by the filter :
The first two options allows to use WebFacets without knowing anything about Spring or almost : you still have to configure the application context to inject your own components (at least the ProfileRepository !). The third one allows to use the WebFacets ApplicationContext along with other Spring stuff (e.g. SpringMVC, Acegi, etc.). |