alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (GenericUIBean.java)

This example Struts source code file (GenericUIBean.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

genericuibean, genericuibean, http, httpservletrequest, httpservletresponse, object, object, render, request, response, servlet, string, string, strutstag, template, template, uibean

The Struts GenericUIBean.java source code

/*
 * $Id: GenericUIBean.java 651946 2008-04-27 13:41:38Z apetrelli $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.struts2.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.util.ContainUtil;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * <!-- START SNIPPET: javadoc -->
 *
 * Renders an custom UI widget using the specified templates. Additional objects can be passed in to the template
 * using the param tags.<p/>
 *
 * <b>Freemarker:

* Objects provided can be retrieve from within the template via $parameters._paramname_.<p/> * * <b>Jsp:

* Objects provided can be retrieve from within the template via <s:property value="%{parameters._paramname_}" /><p/> * * * In the bottom JSP and Velocity samples, two parameters are being passed in to the component. From within the * component, they can be accessed as:- <p/> * * <b>Freemarker:

* $parameters.get('key1') and $parameters.get('key2') or $parameters.key1 and $parameters.key2<p/> * * <b>Jsp:

* <s:property value="%{parameters.key1}" /> and <s:property value="%{'parameters.key2'}" /> or * <s:property value="%{parameters.get('key1')}" /> and <s:property value="%{parameters.get('key2')}" /><p/> * * 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.<p/> * * <b>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 quotes i.e. value="'value1'" otherwise, the the value * stack will search for an Object on the stack with a method of getValue1(). (now that i've written this, i'm not * entirely sure this is the case. i should verify this manana)<p/> * * <!-- END SNIPPET: javadoc --> * * <p/> Examples * * <pre> * <!-- START SNIPPET: example --> * 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> * * <!-- END SNIPPET: example --> * </pre> * * <p/> * * <b>NOTE: * <!-- START SNIPPET: 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. * * <!-- END SNIPPET: note --> * */ @StrutsTag(name="component", tldTagClass="org.apache.struts2.views.jsp.ui.ComponentTag", description="Render a custom ui widget") public class GenericUIBean extends UIBean { private final static String TEMPLATE = "empty"; public GenericUIBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } public boolean contains(Object obj1, Object obj2) { return ContainUtil.contains(obj1, obj2); } protected String getDefaultTemplate() { return TEMPLATE; } }

Other Struts examples (source code examples)

Here is a short list of links related to this Struts GenericUIBean.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.