Class GenericUIBean


public class GenericUIBean extends UIBean

Renders an custom UI widget using the specified templates. Additional objects can be passed in to the template using the param tags.

Freemarker:

Objects provided can be retrieve from within the template via $attributes._attrname_.

JSP:

Objects provided can be retrieve from within the template via <s:property value="%{attributes._attrname_}" />

In the bottom JSP and Velocity samples, two attributes are being passed in to the component. From within the component, they can be accessed as:

Freemarker:

$attributes.get('key1') and $attributes.get('key2') or $attributes.key1 and $attributes.key2

JSP:

 <s:property value="%{attributes.key1}" /> and <s:property value="%{'attributes.key2'}" /> or
 <s:property value="%{attributes.get('key1')}" /> and <s:property value="%{attributes.get('key2')}" />
 

Currently, your custom UI components can be written in Velocity, JSP, or Freemarker, and the correct rendering engine will be found based on file extension.

Remember: the value params will always be resolved against the ValueStack so if you mean to pass a string literal to your component, make sure to wrap it in single quotes i.e. value="'value1'" (note the opening "' and closing '" otherwise, the the value stack will search for an Object on the stack with a method of getValue1().

Examples

JSP

     <s:component template="/my/custom/component.vm"/>

       or

     <s:component template="/my/custom/component.vm">
       <s:param name="key1" value="value1"/>
       <s:param name="key2" value="value2"/>
     </s:component>
 

Velocity

     #s-component( "template=/my/custom/component.vm" )

       or

     #s-component( "template=/my/custom/component.vm" )
       #s-param( "name=key1" "value=value1" )
       #s-param( "name=key2" "value=value2" )
     #end
 

Freemarker

    <@s..component template="/my/custom/component.ftl" />

      or

    <@s..component template="/my/custom/component.ftl">
       <@s..param name="key1" value="%{'value1'}" />
       <@s..param name="key2" value="%{'value2'}" />
    </@s..component>
 

NOTE: If Jsp is used as the template, the jsp template itself must lie within the webapp itself and not the classpath. Unlike Freemarker or Velocity, JSP template could not be picked up from the classpath.

  • Constructor Details

    • GenericUIBean

      public GenericUIBean(ValueStack stack, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
  • Method Details

    • contains

      public boolean contains(Object obj1, Object obj2)
    • getDefaultTemplate

      protected String getDefaultTemplate()
      Description copied from class: UIBean
      A contract that requires each concrete UI Tag to specify which template should be used as a default. For example, the CheckboxTab might return "checkbox.vm" while the RadioTag might return "radio.vm". This value not begin with a '/' unless you intend to make the path absolute rather than relative to the current theme.
      Specified by:
      getDefaultTemplate in class UIBean
      Returns:
      The name of the template to be used as the default.