001: package com.opensymphony.webwork.components;
002:
003: import com.opensymphony.xwork.util.OgnlValueStack;
004:
005: import javax.servlet.http.HttpServletRequest;
006: import javax.servlet.http.HttpServletResponse;
007:
008: /**
009: * <!-- START SNIPPET: javadoc -->
010: *
011: * A tag that creates a HTML <a href='' /> that when clicked calls a URL remote XMLHttpRequest call via the dojo
012: * framework. The result from the URL is executed as JavaScript. If a "listenTopics" is supplied, it will publish a
013: * 'click' message to that topic when the result is returned.
014: *
015: * <!-- END SNIPPET: javadoc -->
016: *
017: * <p/> <b>Examples</b>
018: *
019: * <pre>
020: * <!-- START SNIPPET: example1 -->
021: * <ww:a id="link1" theme="ajax" href="/DoIt.action" errorText="An error ocurred" showErrorTransportText="true">
022: * <img border="none" src="<%=request.getContextPath()%>/images/delete.gif"/>
023: * <ww:param name="id" value="1"/>
024: * </ww:a>
025: * <!-- END SNIPPET: example1 -->
026: * </pre>
027: *
028: * </p>
029: *
030: * <!-- START SNIPPET: exampledescription1 -->
031: *
032: * Results in
033: *
034: * <!-- END SNIPPET: exampledescription1 -->
035: *
036: * </p>
037: *
038: * <pre>
039: * <!-- START SNIPPET: example2 -->
040: * <a dojoType="BindAnchor" evalResult="true" id="link1" href="/DoIt.action?id=1" errorHtml="An error ocurred"
041: * showTransportError="true"></a>
042: * <!-- END SNIPPET: example2 -->
043: * </pre>
044: *
045: * </p>
046: *
047: * <!-- START SNIPPET: exampledescription2 -->
048: *
049: * Here is an example that uses the postInvokeJS. This example is in altSyntax=true:
050: *
051: * <!-- END SNIPPET: exampledescription2 -->
052: *
053: * </p>
054: *
055: * <pre>
056: * <!-- START SNIPPET: example3 -->
057: * <ww:a id="test" theme="ajax" href="/simpeResult.action" preInvokeJS="confirm(\'You sure\')">
058: * A
059: * </ww:a>
060: * <!-- END SNIPPET: example3 -->
061: * </pre>
062: *
063: * @author Ian Roughley
064: * @author Rene Gielen
065: * @version $Revision: 2468 $
066: * @ww.tag name="a" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.AnchorTag"
067: * description="Render a HTML href element that when clicked calls a URL via remote XMLHttpRequest"
068: * @since 2.2
069: */
070: public class Anchor extends RemoteCallUIBean {
071: final public static String OPEN_TEMPLATE = "a";
072: final public static String TEMPLATE = "a-close";
073: final public static String COMPONENT_NAME = Anchor.class.getName();
074:
075: protected String notifyTopics;
076: protected String preInvokeJS;
077:
078: public Anchor(OgnlValueStack stack, HttpServletRequest request,
079: HttpServletResponse response) {
080: super (stack, request, response);
081: }
082:
083: public String getDefaultOpenTemplate() {
084: return OPEN_TEMPLATE;
085: }
086:
087: protected String getDefaultTemplate() {
088: return TEMPLATE;
089: }
090:
091: public void evaluateExtraParams() {
092: super .evaluateExtraParams();
093:
094: if (notifyTopics != null) {
095: addParameter("notifyTopics", findString(notifyTopics));
096: }
097:
098: if (preInvokeJS != null) {
099: addParameter("preInvokeJS", findString(preInvokeJS));
100: }
101: }
102:
103: /**
104: * The id to assign the component
105: * @ww.tagattribute required="false" type="String"
106: */
107: public void setId(String id) {
108: super .setId(id);
109: }
110:
111: /**
112: * Topic names to post an event to after the remote call has been made
113: * @ww.tagattribute required="false"
114: */
115: public void setNotifyTopics(String notifyTopics) {
116: this .notifyTopics = notifyTopics;
117: }
118:
119: /**
120: * A javascript snippet that will be invoked prior to the execution of the target href. If provided must return true or false. True indicates to continue executing target, false says do not execute link target. Possible uses are for confirm dialogs.
121: * @ww.tagattribute required="false" type="String"
122: */
123: public void setPreInvokeJS(String preInvokeJS) {
124: this.preInvokeJS = preInvokeJS;
125: }
126: }
|