WebFacetsHOW-TOsAuthentication
YourKit Java Profiler |
UsingFacetsAccessing Facets from Pure Java Components in the Web TierAccessing and executing facets from regular Java components of the web tier (servlets, action beans, or everything that's implemented in Java and has access to the http request) is as simple as accessing facets from POJOs. Actually, only the way you retrieve the JFacets bean is different. Here under is a code snippet that shows how to access the JFacets bean, and use it to retrieve/execute facets : // somewhere, in a servlet... HttpServletRequest request = ... ; String profileId = ... ; MyClass target = ... ; // get the Web-enabled jFacets bean // -------------------------------- WebFacets wf = WebFacets.get(request); // retrieve and use a facet // ------------------------- MyFacet f = (MyFacet)wf.getFacet("doSomething", profileId, target); f.xxx(); // execute a facet // --------------- MyResult res = (MyResult)wf.execFacet("doSomething", profileId, target); res.yyy(); As you can see, only the way you obtain the JFacets bean in the web tier is different. Here, you need a request to do so. Accessing Facets from JSPsWebFacets includes a simple taglib that can make your life easier than using scriptlets : <!-- retrieves a facet for passed params and makes it available as a page variable with the name "myFacet" --> <wf:useFacet name="doSomething" profileId="${profileId}" targetObject="${myObject}" var="myFacet"/> <!-- use the facet to do stuff --> <h1>${myFacet.title}</h1> <ul> <c:forEach items=${myFacet.someList} var="item"> ... or <!-- executes a facet for passed params and makes the result available as a page variable with the name "myResult" --> <wf:execFacet name="doSomething" profileId="${profileId}" targetObject="${myObject}" var="myResult"/> <!-- use the facet to do stuff --> <h1>${myResult.title}</h1> <ul> <c:forEach items=${myResult.someList} var="item"> ... |