001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.util;
016:
017: import java.io.IOException;
018: import java.io.Writer;
019: import java.util.Collections;
020: import java.util.List;
021: import org.araneaframework.jsp.UiEvent;
022: import org.araneaframework.jsp.UiUpdateEvent;
023:
024: /**
025: * Standard util for producing calls to UiLib widgets in various
026: * container frameworks.
027: *
028: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
029: */
030: public abstract class JspWidgetCallUtil {
031: public static final String SIMPLE_SUBMIT_FUNCTION = "return _ap.event(this);";
032:
033: /**
034: * Write out form submit script for specified attribute of HTML element. Aranea custom HTML
035: * tag attributes (See {@link org.araneaframework.jsp.AraneaAttributes}) are expected to be
036: * present for submit logic to work.
037: *
038: * @param out
039: * @param attributeName HTML attribute name, ('onclick', 'onchange', ...)
040: */
041: public static void writeSubmitScriptForEvent(Writer out,
042: String attributeName) throws IOException {
043: JspUtil.writeOpenAttribute(out, attributeName);
044: out.write(JspWidgetCallUtil.getSubmitScriptForEvent());
045: JspUtil.writeCloseAttribute(out);
046: }
047:
048: /**
049: * Write out form submit script for specified attribute of HTML element, along with Aranea
050: * custom HTML tag attributes (See {@link org.araneaframework.jsp.AraneaAttributes}) that
051: * are determined by <code>event</code> parameter.
052: *
053: * @param out
054: * @param attributeName HTML attribute name, ('onclick', 'onchange', ...)
055: * @param event event that should be activated when HTML element
056: */
057: public static void writeSubmitScriptForEvent(Writer out,
058: String attributeName, UiEvent event) throws IOException {
059: JspUtil.writeEventAttributes(out, event);
060: JspWidgetCallUtil.writeSubmitScriptForEvent(out, attributeName);
061: }
062:
063: /**
064: * Returns simple submit script for HTML element. This should be used whenever HTML
065: * element has just one event handling attribute that causes form submit, but can also
066: * be used when submit event should always take the same attributes, regardless of
067: * the DOM event that activates the submit function.
068: *
069: * @return {@link #SIMPLE_SUBMIT_FUNCTION} */
070: public static String getSubmitScriptForEvent() {
071: return SIMPLE_SUBMIT_FUNCTION;
072: }
073:
074: /** @since 1.0.2 */
075: public static String getSubmitScriptForEvent(UiUpdateEvent event) {
076: StringBuffer sb = new StringBuffer();
077: sb.append("_ap.event_6(");
078: sb.append("_ap.getSystemForm(),");
079: String eventId = event.getId() != null ? "'" + event.getId()
080: + "'" : "null";
081: String eventTarget = event.getTarget() != null ? "'"
082: + event.getTarget() + "'" : "null";
083: String eventParam = event.getParam() != null ? "'"
084: + event.getParam() + "'" : "null";
085: String eventPrecondition = event.getEventPrecondition() != null ? "'"
086: + event.getEventPrecondition() + "'"
087: : "null";
088: List updateRegionNames = event.getUpdateRegionNames() != null ? event
089: .getUpdateRegionNames()
090: : Collections.EMPTY_LIST;
091:
092: sb.append(eventId).append(",");
093: sb.append(eventTarget).append(",");
094: sb.append(eventParam).append(",");
095: sb.append(eventPrecondition).append(",");
096: sb.append("\"").append(
097: JspUpdateRegionUtil
098: .formatUpdateRegionsJS(updateRegionNames))
099: .append("\"");
100: sb.append(");");
101: return sb.toString();
102: }
103: }
|