001: /*
002: * Adapted from Struts BaseHandlerTag
003: * ====================================================================
004: *
005: * The Apache Software License, Version 1.1
006: *
007: * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
008: * reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions
012: * are met:
013: *
014: * 1. Redistributions of source code must retain the above copyright
015: * notice, this list of conditions and the following disclaimer.
016: *
017: * 2. Redistributions in binary form must reproduce the above copyright
018: * notice, this list of conditions and the following disclaimer in
019: * the documentation and/or other materials provided with the
020: * distribution.
021: *
022: * 3. The end-user documentation included with the redistribution, if
023: * any, must include the following acknowlegement:
024: * "This product includes software developed by the
025: * Apache Software Foundation (http://www.apache.org/)."
026: * Alternately, this acknowlegement may appear in the software itself,
027: * if and wherever such third-party acknowlegements normally appear.
028: *
029: * 4. The names "The Jakarta Project", "Struts", and "Apache Software
030: * Foundation" must not be used to endorse or promote products derived
031: * from this software without prior written permission. For written
032: * permission, please contact apache@apache.org.
033: *
034: * 5. Products derived from this software may not be called "Apache"
035: * nor may "Apache" appear in their names without prior written
036: * permission of the Apache Group.
037: *
038: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
039: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
040: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
041: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
042: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
043: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
044: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
045: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
046: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
047: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
048: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
049: * SUCH DAMAGE.
050: * ====================================================================
051: *
052: * This software consists of voluntary contributions made by many
053: * individuals on behalf of the Apache Software Foundation. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: *
057: */
058:
059: package com.nabhinc.portlet.mvcportlet.taglib;
060:
061: import javax.portlet.PortletException;
062: import javax.portlet.PortletRequest;
063: import javax.portlet.PortletSession;
064: import javax.portlet.RenderRequest;
065: import javax.servlet.jsp.JspException;
066: import javax.servlet.jsp.PageContext;
067: import javax.servlet.jsp.tagext.TagSupport;
068:
069: import org.apache.commons.logging.Log;
070: import org.apache.commons.logging.LogFactory;
071:
072: import com.nabhinc.portlet.mvcportlet.core.Constants;
073: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
074: import com.nabhinc.portlet.mvcportlet.core.Form;
075: import com.nabhinc.portlet.mvcportlet.core.FormField;
076:
077: /**
078: * Base class for tags that render form elements capable of including JavaScript
079: * event handlers and/or CSS Style attributes. This class does not implement
080: * the doStartTag() or doEndTag() methods. Subclasses should provide
081: * appropriate implementations of these.
082: *
083: * @author Don Clasen
084: * @author James Turner
085: * @version $Revision: 1.7 $ $Date: 2006/09/14 22:16:59 $
086: */
087:
088: public abstract class BaseTag extends TagSupport {
089:
090: /**
091: * Commons Logging instance.
092: */
093: private static Log btLogger = LogFactory.getLog(BaseTag.class);
094:
095: // ----------------------------------------------------- Instance Variables
096:
097: //protected int btScope = Constants.SCOPE_UNSPECIFIED;
098:
099: protected String btName = null;
100:
101: // Navigation Management
102:
103: /** Access key character. */
104: protected String btAccesskey = null;
105:
106: /** Tab index value. */
107: protected String tabindex = null;
108:
109: // Indexing ability for Iterate
110:
111: /**
112: * Whether to created indexed names for fields
113: */
114: protected boolean indexed = false;
115:
116: // Mouse Events
117:
118: /** Mouse click event. */
119: private String onclick = null;
120:
121: /** Mouse double click event. */
122: private String ondblclick = null;
123:
124: /** Mouse over component event. */
125: private String onmouseover = null;
126:
127: /** Mouse exit component event. */
128: private String onmouseout = null;
129:
130: /** Mouse moved over component event. */
131: private String onmousemove = null;
132:
133: /** Mouse pressed on component event. */
134: private String onmousedown = null;
135:
136: /** Mouse released on component event. */
137: private String onmouseup = null;
138:
139: // Keyboard Events
140:
141: /** Key down in component event. */
142: private String onkeydown = null;
143:
144: /** Key released in component event. */
145: private String onkeyup = null;
146:
147: /** Key down and up together in component event. */
148: private String onkeypress = null;
149:
150: // Text Events
151:
152: /** Text selected in component event. */
153: private String onselect = null;
154:
155: /** Content changed after component lost focus event. */
156: private String onchange = null;
157:
158: // Focus Events and States
159:
160: /** Component lost focus event. */
161: private String onblur = null;
162:
163: /** Component has received focus event. */
164: private String onfocus = null;
165:
166: /** Component is disabled. */
167: private boolean disabled = false;
168:
169: /** Component is readonly. */
170: private boolean readonly = false;
171:
172: // CSS Style Support
173:
174: /** Style attribute associated with component. */
175: private String style = null;
176:
177: /** Named Style class associated with component. */
178: private String styleClass = null;
179:
180: /** Identifier associated with component. */
181: private String id = null;
182:
183: // Other Common Attributes
184:
185: /** The alternate text of this element. */
186: private String alt = null;
187:
188: /** The name of the message resources bundle for message lookups. */
189: private String bundle = null;
190:
191: /** The advisory title of this element. */
192: private String title = null;
193:
194: public String getName() {
195: return btName;
196: }
197:
198: public void setName(String name) {
199: btName = name;
200: }
201:
202: /*
203: public String getScope() {
204: switch (btScope) {
205: case Constants.SCOPE_APPLICATION_SESSION:
206: return Constants.APPLICATION_SESSION_SCOPE;
207: case Constants.SCOPE_PORTLET_SESSION:
208: return Constants.PORTLET_SESSION_SCOPE;
209: case Constants.SCOPE_PORTLET_CONTEXT:
210: return Constants.PORTLET_CONTEXT_SCOPE;
211: default:
212: return Constants.REQUEST_SCOPE;
213: }
214: }
215:
216: public void setScope(String scope) {
217: if (scope.equals(Constants.APPLICATION_SESSION_SCOPE)) {
218: btScope = Constants.SCOPE_APPLICATION_SESSION;
219: } else if (scope.equals(Constants.PORTLET_SESSION_SCOPE)) {
220: btScope = Constants.SCOPE_PORTLET_SESSION;
221: } else if (scope.equals(Constants.REQUEST_SCOPE)) {
222: btScope = Constants.SCOPE_REQUEST;
223: } else if (scope.equals(Constants.PORTLET_CONTEXT_SCOPE)) {
224: btScope = Constants.SCOPE_PORTLET_CONTEXT;
225: } else {
226: throw new IllegalArgumentException(
227: "Scope must be one of: request, portlet_session, application_session, portlet_context.");
228:
229: }
230: }
231: */
232: // ------------------------------------------------------------- Properties
233: // Navigation Management
234: /** Sets the accessKey character. */
235: public void setAccesskey(String accessKey) {
236: btAccesskey = accessKey;
237: }
238:
239: /** Returns the accessKey character. */
240: public String getAccesskey() {
241: return (btAccesskey);
242: }
243:
244: /** Sets the tabIndex value. */
245: public void setTabindex(String tabIndex) {
246: this .tabindex = tabIndex;
247: }
248:
249: /** Returns the tabIndex value. */
250: public String getTabindex() {
251: return (this .tabindex);
252: }
253:
254: // Indexing ability for Iterate [since Struts 1.1]
255:
256: /**
257: * Sets the indexed value.
258: */
259: public void setIndexed(boolean indexed) {
260: this .indexed = indexed;
261: }
262:
263: /**
264: * Returns the indexed value.
265: */
266: public boolean getIndexed() {
267: return (this .indexed);
268: }
269:
270: // Mouse Events
271:
272: /** Sets the onClick event handler. */
273: public void setOnclick(String onClick) {
274: this .onclick = onClick;
275: }
276:
277: /** Returns the onClick event handler. */
278: public String getOnclick() {
279: return onclick;
280: }
281:
282: /** Sets the onDblClick event handler. */
283: public void setOndblclick(String onDblClick) {
284: this .ondblclick = onDblClick;
285: }
286:
287: /** Returns the onDblClick event handler. */
288: public String getOndblclick() {
289: return ondblclick;
290: }
291:
292: /** Sets the onMouseDown event handler. */
293: public void setOnmousedown(String onMouseDown) {
294: this .onmousedown = onMouseDown;
295: }
296:
297: /** Returns the onMouseDown event handler. */
298: public String getOnmousedown() {
299: return onmousedown;
300: }
301:
302: /** Sets the onMouseUp event handler. */
303: public void setOnmouseup(String onMouseUp) {
304: this .onmouseup = onMouseUp;
305: }
306:
307: /** Returns the onMouseUp event handler. */
308: public String getOnmouseup() {
309: return onmouseup;
310: }
311:
312: /** Sets the onMouseMove event handler. */
313: public void setOnmousemove(String onMouseMove) {
314: this .onmousemove = onMouseMove;
315: }
316:
317: /** Returns the onMouseMove event handler. */
318: public String getOnmousemove() {
319: return onmousemove;
320: }
321:
322: /** Sets the onMouseOver event handler. */
323: public void setOnmouseover(String onMouseOver) {
324: this .onmouseover = onMouseOver;
325: }
326:
327: /** Returns the onMouseOver event handler. */
328: public String getOnmouseover() {
329: return onmouseover;
330: }
331:
332: /** Sets the onMouseOut event handler. */
333: public void setOnmouseout(String onMouseOut) {
334: this .onmouseout = onMouseOut;
335: }
336:
337: /** Returns the onMouseOut event handler. */
338: public String getOnmouseout() {
339: return onmouseout;
340: }
341:
342: // Keyboard Events
343:
344: /** Sets the onKeyDown event handler. */
345: public void setOnkeydown(String onKeyDown) {
346: this .onkeydown = onKeyDown;
347: }
348:
349: /** Returns the onKeyDown event handler. */
350: public String getOnkeydown() {
351: return onkeydown;
352: }
353:
354: /** Sets the onKeyUp event handler. */
355: public void setOnkeyup(String onKeyUp) {
356: this .onkeyup = onKeyUp;
357: }
358:
359: /** Returns the onKeyUp event handler. */
360: public String getOnkeyup() {
361: return onkeyup;
362: }
363:
364: /** Sets the onKeyPress event handler. */
365: public void setOnkeypress(String onKeyPress) {
366: this .onkeypress = onKeyPress;
367: }
368:
369: /** Returns the onKeyPress event handler. */
370: public String getOnkeypress() {
371: return onkeypress;
372: }
373:
374: // Text Events
375:
376: /** Sets the onChange event handler. */
377: public void setOnchange(String onChange) {
378: this .onchange = onChange;
379: }
380:
381: /** Returns the onChange event handler. */
382: public String getOnchange() {
383: return onchange;
384: }
385:
386: /** Sets the onSelect event handler. */
387: public void setOnselect(String onSelect) {
388: this .onselect = onSelect;
389: }
390:
391: /** Returns the onSelect event handler. */
392: public String getOnselect() {
393: return onselect;
394: }
395:
396: // Focus Events and States
397:
398: /** Sets the onBlur event handler. */
399: public void setOnblur(String onBlur) {
400: this .onblur = onBlur;
401: }
402:
403: /** Returns the onBlur event handler. */
404: public String getOnblur() {
405: return onblur;
406: }
407:
408: /** Sets the onFocus event handler. */
409: public void setOnfocus(String onFocus) {
410: this .onfocus = onFocus;
411: }
412:
413: /** Returns the onFocus event handler. */
414: public String getOnfocus() {
415: return onfocus;
416: }
417:
418: /** Sets the disabled event handler. */
419: public void setDisabled(boolean disabled) {
420: this .disabled = disabled;
421: }
422:
423: /** Returns the disabled event handler. */
424: public boolean getDisabled() {
425: return disabled;
426: }
427:
428: /** Sets the readonly event handler. */
429: public void setReadonly(boolean readonly) {
430: this .readonly = readonly;
431: }
432:
433: /** Returns the readonly event handler. */
434: public boolean getReadonly() {
435: return readonly;
436: }
437:
438: // CSS Style Support
439:
440: /** Sets the inline style attribute. */
441: public void setStyle(String style) {
442: this .style = style;
443: }
444:
445: /** Returns the inline style attribute. */
446: public String getStyle() {
447: return style;
448: }
449:
450: /** Sets the style class attribute. */
451: public void setStyleClass(String styleClass) {
452: this .styleClass = styleClass;
453: }
454:
455: /** Returns the style class attribute. */
456: public String getStyleClass() {
457: return styleClass;
458: }
459:
460: /** Sets the tag id attribute. */
461: public void setId(String tagId) {
462: id = tagId;
463: }
464:
465: /** Returns the tag id attribute. */
466: public String getId() {
467: return id;
468: }
469:
470: // Other Common Elements
471:
472: /** Returns the alternate text attribute. */
473: public String getAlt() {
474: return alt;
475: }
476:
477: /** Sets the alternate text attribute. */
478: public void setAlt(String alt) {
479: this .alt = alt;
480: }
481:
482: /** Returns the name of the message resources bundle to use. */
483: public String getBundle() {
484: return bundle;
485: }
486:
487: /** Sets the name of the message resources bundle to use. */
488: public void setBundle(String bundle) {
489: this .bundle = bundle;
490: }
491:
492: /** Returns the advisory title attribute. */
493: public String getTitle() {
494: return title;
495: }
496:
497: /** Sets the advisory title attribute. */
498: public void setTitle(String title) {
499: this .title = title;
500: }
501:
502: // --------------------------------------------------------- Public Methods
503:
504: /**
505: * Release any acquired resources.
506: */
507: public void release() {
508:
509: super .release();
510: btAccesskey = null;
511: alt = null;
512: bundle = null;
513: indexed = false;
514: onclick = null;
515: ondblclick = null;
516: onmouseover = null;
517: onmouseout = null;
518: onmousemove = null;
519: onmousedown = null;
520: onmouseup = null;
521: onkeydown = null;
522: onkeyup = null;
523: onkeypress = null;
524: onselect = null;
525: onchange = null;
526: onblur = null;
527: onfocus = null;
528: disabled = false;
529: readonly = false;
530: style = null;
531: styleClass = null;
532: id = null;
533: tabindex = null;
534: title = null;
535:
536: }
537:
538: // ------------------------------------------------------ Protected Methods
539:
540: /**
541: * Prepares the style attributes for inclusion in the component's HTML tag.
542: * @return The prepared String for inclusion in the HTML tag.
543: * @exception JspException if invalid attributes are specified
544: */
545: protected String prepareStyles() throws JspException {
546: String value = null;
547: StringBuffer styles = new StringBuffer();
548: if (style != null) {
549: styles.append(" style=\"");
550: styles.append(getStyle());
551: styles.append("\"");
552: }
553: if (styleClass != null) {
554: styles.append(" class=\"");
555: styles.append(getStyleClass());
556: styles.append("\"");
557: }
558: if (id != null) {
559: styles.append(" id=\"");
560: styles.append(getId());
561: styles.append("\"");
562: }
563:
564: if (title != null) {
565: value = getMessage(title);
566: styles.append(" title=\"");
567: styles.append(value);
568: styles.append("\"");
569: }
570: if (alt != null) {
571: value = getMessage(alt);
572: styles.append(" alt=\"");
573: styles.append(value);
574: styles.append("\"");
575: }
576: return styles.toString();
577: }
578:
579: /**
580: * Prepares the event handlers for inclusion in the component's HTML tag.
581: * @return The prepared String for inclusion in the HTML tag.
582: */
583: protected String prepareEventHandlers() {
584: StringBuffer handlers = new StringBuffer();
585: prepareMouseEvents(handlers);
586: prepareKeyEvents(handlers);
587: prepareTextEvents(handlers);
588: prepareFocusEvents(handlers);
589: return handlers.toString();
590: }
591:
592: /**
593: * Prepares the mouse event handlers, appending them to the the given
594: * StringBuffer.
595: * @param handlers The StringBuffer that output will be appended to.
596: */
597: protected void prepareMouseEvents(StringBuffer handlers) {
598: if (onclick != null) {
599: handlers.append(" onclick=\"");
600: handlers.append(getOnclick());
601: handlers.append("\"");
602: }
603:
604: if (ondblclick != null) {
605: handlers.append(" ondblclick=\"");
606: handlers.append(getOndblclick());
607: handlers.append("\"");
608: }
609:
610: if (onmouseover != null) {
611: handlers.append(" onmouseover=\"");
612: handlers.append(getOnmouseover());
613: handlers.append("\"");
614: }
615:
616: if (onmouseout != null) {
617: handlers.append(" onmouseout=\"");
618: handlers.append(getOnmouseout());
619: handlers.append("\"");
620: }
621:
622: if (onmousemove != null) {
623: handlers.append(" onmousemove=\"");
624: handlers.append(getOnmousemove());
625: handlers.append("\"");
626: }
627:
628: if (onmousedown != null) {
629: handlers.append(" onmousedown=\"");
630: handlers.append(getOnmousedown());
631: handlers.append("\"");
632: }
633:
634: if (onmouseup != null) {
635: handlers.append(" onmouseup=\"");
636: handlers.append(getOnmouseup());
637: handlers.append("\"");
638: }
639: }
640:
641: /**
642: * Prepares the keyboard event handlers, appending them to the the given
643: * StringBuffer.
644: * @param handlers The StringBuffer that output will be appended to.
645: */
646: protected void prepareKeyEvents(StringBuffer handlers) {
647:
648: if (onkeydown != null) {
649: handlers.append(" onkeydown=\"");
650: handlers.append(getOnkeydown());
651: handlers.append("\"");
652: }
653:
654: if (onkeyup != null) {
655: handlers.append(" onkeyup=\"");
656: handlers.append(getOnkeyup());
657: handlers.append("\"");
658: }
659:
660: if (onkeypress != null) {
661: handlers.append(" onkeypress=\"");
662: handlers.append(getOnkeypress());
663: handlers.append("\"");
664: }
665: }
666:
667: /**
668: * Prepares the text event handlers, appending them to the the given
669: * StringBuffer.
670: * @param handlers The StringBuffer that output will be appended to.
671: */
672: protected void prepareTextEvents(StringBuffer handlers) {
673:
674: if (onselect != null) {
675: handlers.append(" onselect=\"");
676: handlers.append(getOnselect());
677: handlers.append("\"");
678: }
679:
680: if (onchange != null) {
681: handlers.append(" onchange=\"");
682: handlers.append(getOnchange());
683: handlers.append("\"");
684: }
685: }
686:
687: /**
688: * Prepares the focus event handlers, appending them to the the given
689: * StringBuffer.
690: * @param handlers The StringBuffer that output will be appended to.
691: */
692: protected void prepareFocusEvents(StringBuffer handlers) {
693:
694: if (onblur != null) {
695: handlers.append(" onblur=\"");
696: handlers.append(getOnblur());
697: handlers.append("\"");
698: }
699:
700: if (onfocus != null) {
701: handlers.append(" onfocus=\"");
702: handlers.append(getOnfocus());
703: handlers.append("\"");
704: }
705:
706: if (disabled) {
707: handlers.append(" disabled=\"disabled\"");
708: }
709:
710: if (readonly) {
711: handlers.append(" readonly=\"readonly\"");
712: }
713:
714: }
715:
716: /**
717: * Allows HTML tags to find out if they're nested within an %lt;html:html> tag that
718: * has xhtml set to true.
719: * @return true if the tag is nested within an html tag with xhtml set to true, false
720: * otherwise.
721: * @since Struts 1.1
722: */
723: protected boolean isXhtml() {
724: String xhtml = (String) this .pageContext.getAttribute(
725: Constants.IS_XHTML_ATTRIB, PageContext.PAGE_SCOPE);
726:
727: if ("true".equalsIgnoreCase(xhtml)) {
728: return true;
729: } else {
730: return false;
731: }
732: }
733:
734: /**
735: * Returns the closing brace for an input element depending on xhtml status. The tag
736: * must be nested within an %lt;html:html> tag that has xhtml set to true.
737: * @return String - > if xhtml is false, /> if xhtml is true
738: * @since Struts 1.1
739: */
740: protected String getElementClose() {
741: if (this .isXhtml()) {
742: return " />";
743: } else {
744: return ">";
745: }
746: }
747:
748: private String getMessage(String key) throws JspException {
749: try {
750: RenderRequest request = (RenderRequest) pageContext
751: .getRequest().getAttribute("javax.portlet.request");
752:
753: ControllerPortletConfig portlet = (ControllerPortletConfig) request
754: .getAttribute(Constants.PORTLET_CONFIG_ATTRIB);
755: return portlet.getLocalizedMessage(key, request);
756: } catch (Exception ex) {
757: throw new JspException(ex);
758: }
759:
760: }
761:
762: protected String getParamValue(RenderRequest request)
763: throws JspException {
764: Form form = (Form) pageContext
765: .getAttribute(Constants.FORM_ATTRIB);
766: if (form == null)
767: throw new JspException(
768: "Failed to find a form enclosing the MVCPortlet tag.");
769:
770: int scope = Constants.SCOPE_REQUEST;
771: //if (btScope != Constants.SCOPE_UNSPECIFIED) {
772: // scope = btScope;
773: //} else
774: if (form.getScopeAsInt() != Constants.SCOPE_UNSPECIFIED) {
775: scope = form.getScopeAsInt();
776: }
777: String[] attribValues = null;
778: String paramValue = null;
779: switch (scope) {
780: case Constants.SCOPE_REQUEST:
781: paramValue = request.getParameter(btName);
782: if (paramValue == null)
783: paramValue = (String) request.getAttribute(btName);
784: break;
785: case Constants.SCOPE_PORTLET_SESSION:
786: attribValues = (String[]) request.getPortletSession()
787: .getAttribute(btName, PortletSession.PORTLET_SCOPE);
788: if (attribValues != null)
789: paramValue = attribValues[0];
790: break;
791: case Constants.SCOPE_APPLICATION_SESSION:
792: attribValues = (String[]) request.getPortletSession()
793: .getAttribute(btName,
794: PortletSession.APPLICATION_SCOPE);
795: if (attribValues != null)
796: paramValue = attribValues[0];
797: break;
798: default:
799: attribValues = (String[]) request.getPortletSession()
800: .getPortletContext().getAttribute(btName);
801: if (attribValues != null)
802: paramValue = attribValues[0];
803: break;
804: }
805: if (paramValue == null) {
806: if (request.getParameter(Constants.POST_USER_ACTION_PARAM
807: + form.getName()) == null) {
808: return getDefaultFieldValue(request);
809: } else {
810: return null;
811: }
812: } else {
813: return paramValue;
814: }
815: }
816:
817: protected String[] getParamValues(RenderRequest request)
818: throws JspException {
819: Form form = (Form) pageContext
820: .getAttribute(Constants.FORM_ATTRIB);
821: if (form == null)
822: throw new JspException(
823: "Failed to find a form enclosing the MVCPortlet tag.");
824:
825: int scope = Constants.SCOPE_REQUEST;
826: //if (btScope != Constants.SCOPE_UNSPECIFIED) {
827: // scope = btScope;
828: //} else
829: if (form.getScopeAsInt() != Constants.SCOPE_UNSPECIFIED) {
830: scope = form.getScopeAsInt();
831: }
832: String[] attribValues = null;
833: String[] paramValues = null;
834: switch (scope) {
835: case Constants.SCOPE_REQUEST:
836: paramValues = request.getParameterValues(btName);
837: if (paramValues == null)
838: paramValues = getParamValuesFromAttribute(request);
839: break;
840: case Constants.SCOPE_PORTLET_SESSION:
841: attribValues = (String[]) request.getPortletSession()
842: .getAttribute(btName, PortletSession.PORTLET_SCOPE);
843: if (attribValues != null)
844: paramValues = attribValues;
845: case Constants.SCOPE_APPLICATION_SESSION:
846: attribValues = (String[]) request.getPortletSession()
847: .getAttribute(btName,
848: PortletSession.APPLICATION_SCOPE);
849: if (attribValues != null)
850: paramValues = attribValues;
851: default:
852: attribValues = (String[]) request.getPortletSession()
853: .getPortletContext().getAttribute(btName);
854: if (attribValues != null)
855: paramValues = attribValues;
856: }
857:
858: if (paramValues == null) {
859: if (request.getParameter(Constants.POST_USER_ACTION_PARAM
860: + form.getName()) == null) {
861: return getDefaultFieldValues(request);
862: } else {
863: return null;
864: }
865: } else {
866: return paramValues;
867: }
868: }
869:
870: /**
871: * Logs a debug message.
872: * @param msg Message to be logged
873: */
874: public void debug(String msg) {
875: btLogger.debug(msg);
876: }
877:
878: /**
879: * Logs informational message.
880: * @param msg Message to be logged
881: */
882: public void info(String msg) {
883: btLogger.info(msg);
884: }
885:
886: /**
887: * Logs an error message.
888: * @param msg Message to be logged
889: */
890: public void error(String msg) {
891: btLogger.error(msg);
892: }
893:
894: /**
895: * Logs an error message.
896: * @param msg Message to be logged
897: */
898: public void error(String msg, Throwable t) {
899: btLogger.error(msg, t);
900: }
901:
902: /**
903: * Logs a warning message.
904: * @param msg Message to be logged
905: */
906: public void warn(String msg) {
907: btLogger.warn(msg);
908: }
909:
910: /**
911: * Logs a warning message.
912: * @param msg Message to be logged.
913: * @param t A throwable object.
914: */
915: public void warn(String msg, Throwable t) {
916: btLogger.warn(msg, t);
917: }
918:
919: /**
920: * Logs a fatal message.
921: * @param msg
922: */
923: public void fatal(String msg) {
924: btLogger.fatal(msg);
925: }
926:
927: /**
928: * Logs a fatal message and stack trace of the error.
929: * @param msg
930: * @param t
931: */
932: public void fatal(String msg, Throwable t) {
933: btLogger.fatal(msg, t);
934: }
935:
936: protected String getDefaultFieldValue(PortletRequest request)
937: throws JspException {
938: Form form = (Form) pageContext
939: .getAttribute(Constants.FORM_ATTRIB);
940: if (form == null)
941: throw new JspException(
942: "Failed to find a form enclosing the MVCPortlet tag.");
943: FormField field = form.getField(getName());
944: /*
945: if (field == null) throw new JspException("Failed to find a field named " + getName() +
946: " within MVCPortlet tag.");
947: */
948: if (field == null)
949: return null;
950: try {
951: String[] defaultValues = field.getDefaultValues(request);
952: if (defaultValues == null)
953: return null;
954: return defaultValues[0];
955: } catch (PortletException e) {
956: throw new JspException(
957: "Failed to get field default value.", e);
958: }
959:
960: }
961:
962: protected String[] getDefaultFieldValues(PortletRequest request)
963: throws JspException {
964: Form form = (Form) pageContext
965: .getAttribute(Constants.FORM_ATTRIB);
966: if (form == null)
967: throw new JspException(
968: "Failed to find a form enclosing the MVCPortlet tag.");
969: FormField field = form.getField(getName());
970: /*
971: if (field == null) throw new JspException("Failed to find a field named " + getName() +
972: " within MVCPortlet tag.");
973: */
974: if (field == null)
975: return null;
976: try {
977: return field.getDefaultValues(request);
978: } catch (PortletException e) {
979: throw new JspException(
980: "Failed to get field default value.", e);
981: }
982:
983: }
984:
985: private String[] getParamValuesFromAttribute(RenderRequest request) {
986: Object paramVal = request.getAttribute(btName);
987: if (paramVal == null)
988: return null;
989: if (paramVal instanceof String)
990: return new String[] { (String) paramVal };
991: return (String[]) paramVal;
992: }
993:
994: }
|