001: /*
002: * $Id: Anchor.java 508280 2007-02-16 02:07:56Z musachy $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.struts2.views.annotations.StrutsTag;
027: import org.apache.struts2.views.annotations.StrutsTagAttribute;
028:
029: import com.opensymphony.xwork2.util.ValueStack;
030:
031: /**
032: * <!-- START SNIPPET: javadoc -->
033: *
034: * A tag that creates a HTML <a href='' /> that when clicked calls a URL remote XMLHttpRequest call via the dojo
035: * framework.<p/>
036: *
037: * <!-- START SNIPPET: ajaxJavadoc -->
038: * <B>THE FOLLOWING IS ONLY VALID WHEN AJAX IS CONFIGURED</B>
039: * <ul>
040: * <li>href</li>
041: * <li>errorText</li>
042: * <li>listenTopics</li>
043: * <li>notifyTopics</li>
044: * <li>executeScripts</li>
045: * <li>loadingText</li>
046: * <li>listenTopics</li>
047: * <li>handler</li>
048: * <li>formId</li>
049: * <li>formFilter</li>
050: * <li>targets</li>
051: * <li>showErrorTransportText</li>
052: * <li>targets</li>
053: * <li>indicator</li>
054: * </ul>
055: * 'resultDivId' Deprecated. Use targets.<p/>
056: * 'targets' is a list of element ids whose content will be updated with the
057: * text returned from request.<p/>
058: * 'errorText' is the text that will be displayed when there is an error making the request.<p/>
059: * 'onLoadJS' Deprecated. Use 'notifyTopics'.<p/>
060: * 'preInvokeJS' Deprecated. Use 'notifyTopics'.<p/>
061: * 'executeScripts' if set to true will execute javascript sections in the returned text.<p/>
062: * 'loadingText' is the text that will be displayed on the 'targets' elements while making the
063: * request.<p/>
064: * 'handler' is the name of the function that will take care of making the AJAX request. Dojo's widget
065: * and dom node are passed as parameters).<p/>
066: * 'formId' is the id of the html form whose fields will be seralized and passed as parameters
067: * in the request.<p/>
068: * 'formFilter' is the name of a function which will be used to filter the fields that will be
069: * seralized. This function takes as a parameter the element and returns true if the element
070: * should be included.<p/>
071: * 'listenTopics' comma separated list of topics names, that will trigger a request
072: * 'indicator' element to be shown while the request executing
073: * 'showErrorTransportText': whether errors should be displayed (on 'targets')</p>
074: * 'showLoadingText' show loading text on targets</p>
075: * 'notifyTopics' comma separated list of topics names, that will be published. Three parameters are passed:<p/>
076: * <ul>
077: * <li>data: html or json object when type='load' or type='error'</li>
078: * <li>type: 'before' before the request is made, 'load' when the request succeeds, or 'error' when it fails</li>
079: * <li>request: request javascript object, when type='load' or type='error'</li>
080: * </ul>
081: * <!-- END SNIPPET: javadoc -->
082: *
083: * <p/> <b>Examples</b>
084: *
085: * <pre>
086: * <!-- START SNIPPET: example1 -->
087: * <s:a id="link1" theme="ajax" href="/DoIt.action" errorText="An error ocurred" loadingText="Loading...">
088: * <img border="none" src="<%=request.getContextPath()%>/images/delete.gif"/>
089: * <s:param name="id" value="1"/>
090: * </s:a>
091: * <!-- END SNIPPET: example1 -->
092: * </pre>
093: *
094: * </p>
095: *
096: * <!-- START SNIPPET: exampledescription1 -->
097: *
098: * Results in
099: *
100: * <!-- END SNIPPET: exampledescription1 -->
101: *
102: * </p>
103: *
104: * <pre>
105: * <!-- START SNIPPET: example2 -->
106: * <a dojoType="BindAnchor" executeScripts="true" id="link1" href="/DoIt.action?id=1" errorText="An error ocurred"></a>
107: * <!-- END SNIPPET: example2 -->
108: * </pre>
109: *
110: * </p>
111: *
112: * <!-- START SNIPPET: exampledescription2 -->
113: *
114: * Here is an example that uses the beforeLoading. This example is in altSyntax=true:
115: *
116: * <!-- END SNIPPET: exampledescription2 -->
117: *
118: * </p>
119: *
120: * <pre>
121: * <!-- START SNIPPET: example3 -->
122: * <s:a id="test" theme="ajax" href="/simpeResult.action" beforeLoading="confirm('Are you sure?')">
123: * A
124: * </s:a>
125: * <!-- END SNIPPET: example3 -->
126: * </pre>
127: *
128: */
129: @StrutsTag(name="a",tldTagClass="org.apache.struts2.views.jsp.ui.AnchorTag",description="Render a HTML href element that when clicked can optionally call a URL via remote XMLHttpRequest and updates its targets")
130: public class Anchor extends AbstractRemoteCallUIBean {
131: public static final String OPEN_TEMPLATE = "a";
132: public static final String TEMPLATE = "a-close";
133: public static final String COMPONENT_NAME = Anchor.class.getName();
134:
135: protected String targets;
136:
137: public Anchor(ValueStack stack, HttpServletRequest request,
138: HttpServletResponse response) {
139: super (stack, request, response);
140: }
141:
142: public String getDefaultOpenTemplate() {
143: return OPEN_TEMPLATE;
144: }
145:
146: protected String getDefaultTemplate() {
147: return TEMPLATE;
148: }
149:
150: public void evaluateExtraParams() {
151: super .evaluateExtraParams();
152:
153: if (targets != null)
154: addParameter("targets", findString(targets));
155: }
156:
157: @StrutsTagAttribute(description="Comma delimited list of ids of the elements whose content will be updated")
158: public void setTargets(String targets) {
159: this .targets = targets;
160: }
161:
162: @StrutsTagAttribute(name="onLoadJS",description="Deprecated. Use 'notifyTopics'. Javascript code execute after reload")
163: public void setAfterLoading(String afterLoading) {
164: this .afterLoading = afterLoading;
165: }
166:
167: @StrutsTagAttribute(name="preInvokeJS",description="Deprecated. Use 'notifyTopics'. Javascript code execute before reload")
168: public void setBeforeLoading(String beforeLoading) {
169: this.beforeLoading = beforeLoading;
170: }
171: }
|