Recent Changes - Search:

WebFacets

HOW-TOs

Authentication



SourceForge Logo









YourKit Java Profiler

UsingFacets

Accessing Facets from Pure Java Components in the Web Tier

Accessing 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 JSPs

WebFacets 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">
...

Edit - History - Print - Recent Changes - Search
Page last modified on April 14, 2007, at 07:51 PM