Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » components » [javadoc | source]
    1   /*
    2    * $Id: GenericUIBean.java 651946 2008-04-27 13:41:38Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.components;
   23   
   24   import javax.servlet.http.HttpServletRequest;
   25   import javax.servlet.http.HttpServletResponse;
   26   
   27   import org.apache.struts2.views.annotations.StrutsTag;
   28   import org.apache.struts2.util.ContainUtil;
   29   
   30   import com.opensymphony.xwork2.util.ValueStack;
   31   
   32   /**
   33    * <!-- START SNIPPET: javadoc -->
   34    *
   35    * Renders an custom UI widget using the specified templates. Additional objects can be passed in to the template
   36    * using the param tags.<p/>
   37    *
   38    * <b>Freemarker:</b><p/>
   39    * Objects provided can be retrieve from within the template via $parameters._paramname_.<p/>
   40    *
   41    * <b>Jsp:</b><p/>
   42    * Objects provided can be retrieve from within the template via &lt;s:property value="%{parameters._paramname_}" /&gt;<p/>
   43    *
   44    *
   45    * In the bottom JSP and Velocity samples, two parameters are being passed in to the component. From within the
   46    * component, they can be accessed as:- <p/>
   47    *
   48    * <b>Freemarker:</b><p/>
   49    * $parameters.get('key1') and $parameters.get('key2') or $parameters.key1 and $parameters.key2<p/>
   50    *
   51    * <b>Jsp:</b><p/>
   52    * &lt;s:property value="%{parameters.key1}" /&gt; and &lt;s:property value="%{'parameters.key2'}" /&gt; or
   53    * &lt;s:property value="%{parameters.get('key1')}" /&gt; and &lt;s:property value="%{parameters.get('key2')}" /&gt;<p/>
   54    *
   55    * Currently, your custom UI components can be written in Velocity, JSP, or Freemarker, and the correct rendering
   56    * engine will be found based on file extension.<p/>
   57    *
   58    * <b>Remember:</b> the value params will always be resolved against the ValueStack so if you mean to pass a
   59    * string literal to your component, make sure to wrap it in quotes i.e. value="'value1'" otherwise, the the value
   60    * stack will search for an Object on the stack with a method of getValue1(). (now that i've written this, i'm not
   61    * entirely sure this is the case. i should verify this manana)<p/>
   62    *
   63    * <!-- END SNIPPET: javadoc -->
   64    *
   65    * <p/> <b>Examples</b>
   66    *
   67    * <pre>
   68    * <!-- START SNIPPET: example -->
   69    * JSP
   70    *     &lt;s:component template="/my/custom/component.vm"/&gt;
   71    *
   72    *       or
   73    *
   74    *     &lt;s:component template="/my/custom/component.vm"&gt;
   75    *       &lt;s:param name="key1" value="value1"/&gt;
   76    *       &lt;s:param name="key2" value="value2"/&gt;
   77    *     &lt;/s:component&gt;
   78    *
   79    * Velocity
   80    *     #s-component( "template=/my/custom/component.vm" )
   81    *
   82    *       or
   83    *
   84    *     #s-component( "template=/my/custom/component.vm" )
   85    *       #s-param( "name=key1" "value=value1" )
   86    *       #s-param( "name=key2" "value=value2" )
   87    *     #end
   88    *
   89    * Freemarker
   90    *    &lt;@s..component template="/my/custom/component.ftl" />
   91    *
   92    *      or
   93    *
   94    *    &lt;@s..component template="/my/custom/component.ftl"&gt;
   95    *       &lt;@s..param name="key1" value="%{'value1'}" /&gt;
   96    *       &lt;@s..param name="key2" value="%{'value2'}" /&gt;
   97    *    &lt;/@s..component&gt;
   98    *
   99    * <!-- END SNIPPET: example -->
  100    * </pre>
  101    *
  102    * <p/>
  103    *
  104    * <b>NOTE:</b>
  105    * <!-- START SNIPPET: note -->
  106    *
  107    * If Jsp is used as the template, the jsp template itself must lie within the
  108    * webapp itself and not the classpath. Unlike Freemarker or Velocity, JSP template
  109    * could not be picked up from the classpath.
  110    *
  111    * <!-- END SNIPPET: note -->
  112    *
  113    */
  114   @StrutsTag(name="component", tldTagClass="org.apache.struts2.views.jsp.ui.ComponentTag", description="Render a custom ui widget")
  115   public class GenericUIBean extends UIBean {
  116       private final static String TEMPLATE = "empty";
  117   
  118       public GenericUIBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
  119           super(stack, request, response);
  120       }
  121   
  122       public boolean contains(Object obj1, Object obj2) {
  123           return ContainUtil.contains(obj1, obj2);
  124       }
  125   
  126       protected String getDefaultTemplate() {
  127           return TEMPLATE;
  128       }
  129   }

Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » components » [javadoc | source]