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

Struts example source code file (Div.java)

This example Struts source code file (Div.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

boolean, boolean, div, div, how, http, integer, load, request, response, servlet, string, string, strutstagattribute, strutstagattribute, template, template_close, topics

The Struts Div.java source code

/*
 * $Id: Div.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.dojo.components;

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

import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * <!-- START SNIPPET: javadoc -->
 * <p>
 * This tag generates an HTML div that loads its content using an XMLHttpRequest call, via
 * the dojo framework. When the "updateFreq" is set the built in timer will start automatically and 
 * reload the div content with the value of "updateFreq" as the refresh period(in milliseconds).
 * Topics can be used to stop(stopTimerListenTopics) and start(startTimerListenTopics) this timer.  
 * </p>
 * <p>
 * When used inside a "tabbedpanel" tag, each div becomes a tab. Some attributes are specific
 * to this use case, like:
 * <ul>
 *   <li>refreshOnShow: div content is realoded when tab is selected
 *   <li>closable: Tab will have close button
 *   <li>preload: load div content after page is loaded
 * </ul>
 * </p>
 * <!-- END SNIPPET: javadoc -->
 * 
 * <p>Examples

* <!-- START SNIPPET: example1 --> * <sx:div href="%{#url}">Initial Content</sx:div> * <!-- END SNIPPET: example1 --> * * <!-- START SNIPPET: example2 --> * <img id="indicator" src="${pageContext.request.contextPath}/images/indicator.gif" style="display:none"/> * <sx:div href="%{#url}" updateFreq="2000" indicator="indicator"> * Initial Content * </sx:div> * <!-- END SNIPPET: example2 --> * * <!-- START SNIPPET: example3 --> * <form id="form"> * <label for="textInput">Text to be submited when div reloads</label> * <input type=textbox id="textInput" name="data"> * </form> * <sx:div * href="%{#url}" * updateFreq="3000" * listenTopics="/refresh" * startTimerListenTopics="/startTimer" * stopTimerListenTopics="/stopTimer" * highlightColor="red" * formId="form"> * Initial Content * </sx:div> * <!-- END SNIPPET: example3 --> */ @StrutsTag(name="div", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.DivTag", description="Render HTML div providing content from remote call via AJAX") public class Div extends AbstractRemoteBean { public static final String TEMPLATE = "div"; public static final String TEMPLATE_CLOSE = "div-close"; public static final String COMPONENT_NAME = Div.class.getName(); protected String updateFreq; protected String autoStart; protected String delay; protected String startTimerListenTopics; protected String stopTimerListenTopics; protected String refreshOnShow; protected String closable; protected String preload; public Div(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } public String getDefaultOpenTemplate() { return TEMPLATE; } protected String getDefaultTemplate() { return TEMPLATE_CLOSE; } public void evaluateExtraParams() { super.evaluateExtraParams(); if (updateFreq != null) addParameter("updateFreq", findValue(updateFreq, Integer.class)); if (autoStart != null) addParameter("autoStart", findValue(autoStart, Boolean.class)); if (refreshOnShow != null) addParameter("refreshOnShow", findValue(refreshOnShow, Boolean.class)); if (delay != null) addParameter("delay", findValue(delay, Integer.class)); if (startTimerListenTopics != null) addParameter("startTimerListenTopics", findString(startTimerListenTopics)); if (stopTimerListenTopics != null) addParameter("stopTimerListenTopics", findString(stopTimerListenTopics)); if (separateScripts != null) addParameter("separateScripts", findValue(separateScripts, Boolean.class)); if (closable != null) addParameter("closable", findValue(closable, Boolean.class)); if (preload != null) addParameter("preload", findValue(preload, Boolean.class)); } @StrutsTagAttribute(description="Start timer automatically", type="Boolean", defaultValue="true") public void setAutoStart(String autoStart) { this.autoStart = autoStart; } @StrutsTagAttribute(description="How long to wait before fetching the content (in milliseconds)", type="Integer") public void setDelay(String delay) { this.delay = delay; } @StrutsTagAttribute(description="How often to reload the content (in milliseconds)", type="Integer") public void setUpdateFreq(String updateInterval) { this.updateFreq = updateInterval; } @StrutsTagAttribute(description="Topics that will start the timer (for autoupdate)") public void setStartTimerListenTopics(String startTimerListenTopic) { this.startTimerListenTopics = startTimerListenTopic; } @StrutsTagAttribute(description="Topics that will stop the timer (for autoupdate)") public void setStopTimerListenTopics(String stopTimerListenTopic) { this.stopTimerListenTopics = stopTimerListenTopic; } @StrutsTagAttribute(description="Content will be loaded when div becomes visible, used only inside the tabbedpanel tag", type="Boolean", defaultValue="false") public void setRefreshOnShow(String refreshOnShow) { this.refreshOnShow = refreshOnShow; } @StrutsTagAttribute(description="Show a close button when the div is inside a 'tabbedpanel'", defaultValue="false") public void setClosable(String closable) { this.closable = closable; } @StrutsTagAttribute(description="Load content when page is loaded", type="Boolean", defaultValue="true") public void setPreload(String preload) { this.preload = preload; } @StrutsTagAttribute(description = "Color used to perform a highlight effect on this element", defaultValue = "none") public void setHighlightColor(String highlightColor) { this.highlightColor = highlightColor; } }

Other Struts examples (source code examples)

Here is a short list of links related to this Struts Div.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.