Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3


JCR Plugin


Max Skripnikov (sibutu project)


Open Source




Struts 2.0 +



Plugin for the struts2 to provide transparent JCR(JSR-170) integration. Plugin consists of two parts - annotation based interceptor for preloading JCR nodes, and wrapper classes for transparent wrapping of JCR Nodes so they implement both javax,jcr.Node and java.util.Map. This approach allows node's properties to be set directly by Struts2, also validation can easily be done and JCR node's properties can be referenced in JSP pages in a standard way.


    * Easy access to jcr node's properties on jsp pages
    * Preloading nodes using annotation


 * Download the Plugin and put in into your WEB-INF/lib folder.
 * Configure the interceptors stack to include JCR interceptor

Code Block
<interceptor name="jcrActionsInterceptor" class="org.sibutu.plugin.struts2.jcr.interceptor.JcrActionsInterceptor" />
 <interceptor-stack name="myStack">
 <interceptor-ref name="jcrAction" />
 <interceptor-ref name="staticParams" />
 <interceptor-ref name="params">
 <param name="excludeParams">dojo\..*</param>
 <param name="ordered">true</param>


* Add lines to spring config describing JcrTemplateWrapper


Code Block
<bean id="wrapperFactory" class="org.sibutu.plugin.struts2.jcr.wrapper.SimpleNodeWrapperFactory"/>
<bean id="jcrTemplate" class="org.sibutu.plugin.struts2.jcr.wrapper.JcrTemplateWrapper">
  <property name="sessionFactory" ref="jcrSessionFactory"/>
  <property name="wrapperFactory" ref="wrapperFactory"/>
  <property name="allowCreate" value="true"/>


   The following example demonstrates plugin usage advantages. There is struts action AddressAction which is used to edit address. Address is a JCR node, having property addressId which is unique for each address node and serves as identifier.

Struts action.

Code Block
public class AddressAction extends ActionSupport {
    Long addressId;
    Node address;
    JcrTemplate jcrTemplate;
    public String save() throws RepositoryException{;
      return SUCCESS;
    public Long getAddressId() {
      return addressId;
    public void setAddressId(Long addressId) {
      this.addressId = addressId;
    @JcrNode(node="/address", id="addressId")
    public Node getAddress() {
      return address;
    public void setAddress(Node address) {
      this.address = address;

JSP page

Code Block
  <s:form action="address!save" name="addressForm" id="addressForm">
      <s:textfield name="" size="50" label="Country" required="true"/>
      <s:textfield name="" size="50" label="City" required="true"/>
      <s:textfield name="address.state" size="50" label="State" required="true"/>
      <s:textfield name="address.address" size="50" label="Address" required="true"/>

 Because the node is wrapped, jsp code interacts with the node in a way like it is java.util.Map.  Then the page is rendered, the node is automatically loaded from repository using path from the annotation and the addressId provided as a parameter. After a user fills in  and submits the form the node loaded again and it's properties are set by struts. The only thing we need to do is to save the node.