001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.renderkit.dom_html_basic;
035:
036: import com.icesoft.faces.context.DOMContext;
037: import com.icesoft.faces.context.effects.CurrentStyle;
038: import com.icesoft.faces.context.effects.JavascriptContext;
039: import com.icesoft.faces.util.Debug;
040: import org.w3c.dom.Element;
041:
042: import javax.faces.FactoryFinder;
043: import javax.faces.application.Application;
044: import javax.faces.application.ApplicationFactory;
045: import javax.faces.application.FacesMessage;
046: import javax.faces.application.FacesMessage.Severity;
047: import javax.faces.component.NamingContainer;
048: import javax.faces.component.UICommand;
049: import javax.faces.component.UIComponent;
050: import javax.faces.component.UIForm;
051: import javax.faces.component.UIInput;
052: import javax.faces.component.UIMessage;
053: import javax.faces.component.UIParameter;
054: import javax.faces.component.ValueHolder;
055: import javax.faces.component.html.HtmlMessage;
056: import javax.faces.component.html.HtmlMessages;
057: import javax.faces.context.FacesContext;
058: import javax.faces.convert.Converter;
059: import javax.faces.convert.ConverterException;
060: import javax.faces.render.Renderer;
061: import java.beans.Beans;
062: import java.io.IOException;
063: import java.util.HashMap;
064: import java.util.Iterator;
065: import java.util.Map;
066: import java.util.Set;
067:
068: public abstract class DomBasicRenderer extends Renderer {
069:
070: // iceSubmitPartial
071: public final String ICESUBMITPARTIAL = "iceSubmitPartial(form, this, event);";
072: // iceSubmit
073: public final String ICESUBMIT = "iceSubmit(form,this,event);";
074:
075: // component family constants for UIForm and WebUIForm
076: public static final String WEB_UIFORM = "com.sun.rave.web.ui.Form";
077: public static final String UIFORM = "javax.faces.form";
078: public static final String WEB_UIJSFFORM = "com.sun.webui.jsf.Form";
079:
080: public void decode(FacesContext facesContext,
081: UIComponent uiComponent) {
082: CurrentStyle.decode(facesContext, uiComponent);
083: validateParameters(facesContext, uiComponent, null);
084: // only need to decode input components
085: if (!(uiComponent instanceof UIInput)) {
086: return;
087: }
088: // only need to decode enabled, writable components
089: if (isStatic(uiComponent)) {
090: return;
091: }
092: // extract component value from the request map
093: String clientId = uiComponent.getClientId(facesContext);
094: Debug.assertTrue(clientId != null,
095: "Client id is not defined for decoding");
096: Map requestMap = facesContext.getExternalContext()
097: .getRequestParameterMap();
098: if (requestMap.containsKey(clientId)) {
099: String decodedValue = (String) requestMap.get(clientId);
100: setSubmittedValue(uiComponent, decodedValue);
101: }
102: }
103:
104: /**
105: * This method should be overridden by renderers for components who subclass
106: * UIInput
107: *
108: * @param uiComponent
109: * @param value
110: */
111: public void setSubmittedValue(UIComponent uiComponent, Object value) {
112: }
113:
114: /**
115: * Delegate rendering to the renderEnd(..) method after validating
116: * parameters and before maintaining the cursor position. The renderEnd
117: * method should be overridden by subclasses of this class so that the
118: * common infrastructure of parameter validation and cursor maintenance are
119: * provided here.
120: */
121: public void encodeEnd(FacesContext facesContext,
122: UIComponent uiComponent) throws IOException {
123: validateParameters(facesContext, uiComponent, null);
124: renderEnd(facesContext, uiComponent, getValue(facesContext,
125: uiComponent));
126: DOMContext domContext = DOMContext.attachDOMContext(
127: facesContext, uiComponent);
128:
129: domContext.stepOver();
130: JavascriptContext.fireEffect(uiComponent, facesContext);
131: }
132:
133: /**
134: * Get the submitted value from the UIComponent argument. If the UIComponent
135: * is not an instance of UIInput, or its <code>getSubmittedValue()</code>
136: * method returns null or a non-String value, then an attempt is made to
137: * obtain the value from the UIComponent's renderer. Conversion is performed
138: * on a value obtained from the renderer.
139: *
140: * @param facesContext
141: * @param uiComponent
142: * @return String the submitted value
143: */
144: String getValue(FacesContext facesContext, UIComponent uiComponent) {
145: // for input components, get the submitted value
146: if (uiComponent instanceof UIInput) {
147: Object submittedValue = ((UIInput) uiComponent)
148: .getSubmittedValue();
149: if (submittedValue != null
150: && submittedValue instanceof String) {
151: return (String) submittedValue;
152: }
153: }
154: return formatComponentValue(facesContext, uiComponent,
155: getValue(uiComponent));
156: }
157:
158: Object getValue(UIComponent uiComponent) {
159: return null;
160: }
161:
162: /**
163: * The common infrastructure of parameter validation and cursor management
164: * will be provided by the encodeEnd method and rendering is delegated to
165: * this method. Renderers should override this method instead of encodeEnd
166: * to provide rendering at the time of execution of the encodeEnd method.
167: *
168: * @param facesContext
169: * @param uiComponent
170: * @param currentValue
171: * @throws IOException
172: */
173: protected void renderEnd(FacesContext facesContext,
174: UIComponent uiComponent, String currentValue)
175: throws IOException {
176: }
177:
178: /**
179: * If the parameter UIComponent instance is a ValueHolder, return the
180: * currentValue parameter. If there is a converter registered with the
181: * component then use the converter to obtain a String value.
182: *
183: * @param facesContext
184: * @param uiComponent
185: * @param currentValue
186: * @return
187: * @throws ConverterException
188: */
189: String formatComponentValue(FacesContext facesContext,
190: UIComponent uiComponent, Object currentValue)
191: throws ConverterException {
192:
193: if (currentValue == null) {
194: return null;
195: }
196:
197: if (!(uiComponent instanceof ValueHolder)) {
198: return currentValue.toString();
199: }
200:
201: // look to see whether there is a converter registered with the component
202: Converter converter = ((ValueHolder) uiComponent)
203: .getConverter();
204:
205: // if there was no converter registered with the component then
206: // look for the default converter for the Class of the currentValue
207: if (converter == null) {
208: if (currentValue instanceof String) {
209: return (String) currentValue;
210: }
211: converter = getConverterForClass(currentValue.getClass());
212: }
213:
214: if (converter == null) {
215: return currentValue.toString();
216: } else {
217: // Don't convert currentValues that are already a String. Some 3rd party converters attempt
218: // to cast this to a specific instance.
219: if (currentValue instanceof String) {
220: return (String) currentValue;
221: }
222: return converter.getAsString(facesContext, uiComponent,
223: currentValue);
224: }
225: }
226:
227: /**
228: * Find the UIComponent whose id is given by the for attribute of the
229: * UIComponent parameter.
230: *
231: * @param facesContext
232: * @param uiComponent
233: * @return the UIComponent associated with the component id indicated by the
234: * value of the for attribute of the UIComponent parameter.
235: */
236: public static UIComponent findForComponent(
237: FacesContext facesContext, UIComponent uiComponent) {
238:
239: String forComponentId = null;
240: if (uiComponent instanceof UIMessage) {
241: forComponentId = ((UIMessage) uiComponent).getFor();
242: } else {
243: forComponentId = (String) uiComponent.getAttributes().get(
244: HTML.FOR_ATTR);
245: }
246:
247: if (forComponentId == null) {
248: return null;
249: }
250: if (forComponentId.length() == 0) {
251: return null;
252: }
253:
254: // Look for the 'for' component in the nearest parental naming container
255: // of the UIComponent (there's actually a bit more to this search - see
256: // the docs for the findComponent method
257: UIComponent forComponent = uiComponent
258: .findComponent(forComponentId);
259:
260: // Since the nearest naming container may be nested, search the
261: // next-to-nearest parental naming container in a recursive fashion,
262: // until we get to the view root
263: if (forComponent == null) {
264: UIComponent nextParent = uiComponent;
265: while (true) {
266: nextParent = nextParent.getParent();
267: // avoid extra searching by going up to the next NamingContainer
268: // (see the docs for findComponent for an information that will
269: // justify this approach)
270: while (nextParent != null
271: && !(nextParent instanceof NamingContainer)) {
272: nextParent = nextParent.getParent();
273: }
274: if (nextParent == null) {
275: break;
276: } else {
277: forComponent = nextParent
278: .findComponent(forComponentId);
279: }
280: if (forComponent != null) {
281: break;
282: }
283: }
284: }
285:
286: // There is one other situation to cover: if the 'for' component
287: // is not situated inside a NamingContainer then the algorithm above
288: // will not have found it. We need, in this case, to search for the
289: // component from the view root downwards
290: if (forComponent == null) {
291: forComponent = searchDownwardsForChildComponentWithId(
292: facesContext.getViewRoot(), forComponentId);
293: }
294: return forComponent;
295: }
296:
297: /**
298: * Retrieve the array of excluded attributes. This array should be
299: * constructed in the renderer class and then passed in to the
300: * PassThruAttributeRenderer.
301: *
302: * @return a String array of excluded attributes.
303: */
304: public static String[] getExcludesArray(Set excludes) {
305: String[] excludesArray = new String[excludes.size()];
306: excludes.toArray(excludesArray);
307: return excludesArray;
308: }
309:
310: private static UIComponent searchDownwardsForChildComponentWithId(
311: UIComponent parent, String searchChildId) {
312: UIComponent foundChild = null;
313: Iterator children = parent.getChildren().iterator();
314: UIComponent nextChild = null;
315: while (children.hasNext()) {
316: nextChild = (UIComponent) children.next();
317: if (nextChild instanceof NamingContainer) {
318: foundChild = nextChild.findComponent(searchChildId);
319: }
320: if (foundChild == null) {
321: searchDownwardsForChildComponentWithId(nextChild,
322: searchChildId);
323: }
324: if (foundChild != null) {
325: break;
326: }
327: }
328: return foundChild;
329: }
330:
331: /**
332: * Recursively render the parent UIComponent instance and its children.
333: *
334: * @param facesContext
335: * @param parent
336: * @throws IOException
337: */
338: public static void encodeParentAndChildren(
339: FacesContext facesContext, UIComponent parent)
340: throws IOException {
341: parent.encodeBegin(facesContext);
342: if (parent.getRendersChildren()) {
343: parent.encodeChildren(facesContext);
344: } else {
345: Iterator children = parent.getChildren().iterator();
346: while (children.hasNext()) {
347: UIComponent nextChild = (UIComponent) children.next();
348: if (nextChild.isRendered()) {
349: encodeParentAndChildren(facesContext, nextChild);
350: }
351: }
352: }
353: parent.encodeEnd(facesContext);
354: }
355:
356: protected static UIComponent getFacetByName(
357: UIComponent uiComponent, String name) {
358: UIComponent facet = uiComponent.getFacet(name);
359: if (facet == null) {
360: return null;
361: }
362: if (!facet.isRendered()) {
363: return null;
364: }
365: return facet;
366: }
367:
368: static boolean idNotNull(UIComponent uiComponent) {
369: return (uiComponent.getId() != null);
370: }
371:
372: /**
373: * Set the id of the root element of the DOMContext associated with the
374: * UIComponent parameter.
375: *
376: * @param facesContext
377: * @param rootElement
378: * @param uiComponent
379: */
380: public static void setRootElementId(FacesContext facesContext,
381: Element rootElement, UIComponent uiComponent) {
382: if (idNotNull(uiComponent)) {
383: rootElement.setAttribute("id", uiComponent
384: .getClientId(facesContext));
385: }
386: }
387:
388: /**
389: * <p/>
390: * Sets a non-null, non-empty-string, UIComponent property to the
391: * corresponding DOM Element
392: * <p/>
393: *
394: * @param uiComponent the source of the attribute value
395: * @param targetElement the DOM Element that will receive the
396: * attribute
397: * @param attrNameInComponent the property name in the UIComponent object
398: * @param attrNameInDom the attribute name in the DOM Element
399: */
400: public static void renderAttribute(UIComponent uiComponent,
401: Element targetElement, String attrNameInComponent,
402: String attrNameInDom) {
403: Object attrValue = uiComponent.getAttributes().get(
404: attrNameInComponent);
405: if (attrValue != null && !attrValue.equals("")) {
406: if (attrValue.toString().equalsIgnoreCase("true")
407: || attrValue.toString().equalsIgnoreCase("false")) {
408: boolean trueValue = new Boolean(attrValue.toString())
409: .booleanValue();
410: if (!trueValue) {
411: targetElement.removeAttribute(attrNameInDom
412: .toString());
413: return;
414: }
415: }
416: targetElement.setAttribute(attrNameInDom.toString(),
417: attrValue.toString());
418: }
419: }
420:
421: /**
422: * Due to the behaviour of the UIParameter class, the names in the
423: * name-value pairs of the Map returned by this method are guaranteed to be
424: * Strings
425: *
426: * @param uiComponent
427: * @return Map the parameterMap
428: */
429: static Map getParameterMap(UIComponent uiComponent) {
430: Map parameterMap = new HashMap();
431: Iterator children = uiComponent.getChildren().iterator();
432: while (children.hasNext()) {
433: UIComponent nextChild = (UIComponent) children.next();
434: if (nextChild instanceof UIParameter) {
435: UIParameter uiParam = (UIParameter) nextChild;
436: parameterMap.put(uiParam.getName(), uiParam.getValue());
437: }
438: }
439: return parameterMap;
440: }
441:
442: /**
443: * Validates that the facesContext is not null, the uiComponent is not null,
444: * and that uiComponent is assignment-compatible with the
445: * validComponentType. Pass a null parameter for validComponentType to avoid
446: * any type checking.
447: *
448: * @param facesContext
449: * @param uiComponent
450: * @param validComponentType
451: * @throws NullPointerException if either of the facesContext or the
452: * uiComponent parameters are null or
453: * if a parent form is not
454: * found when the given UIComponent
455: * is a UIInput or UICommand,
456: * IllegalArgumentException if the
457: * validComponentType is not null and the
458: * uiComponent is not assignable to the given
459: * type.
460: */
461: public void validateParameters(FacesContext facesContext,
462: UIComponent uiComponent, Class validComponentType) {
463:
464: if (facesContext == null) {
465: throw new NullPointerException(
466: "Invalid Parameter - FacesContext instance must not be null");
467: }
468: if (uiComponent == null) {
469: throw new NullPointerException(
470: "Invalid Parameter - UIComponent instance must not be null");
471: }
472: if (!Beans.isDesignTime() && validComponentType != null
473: && !(validComponentType.isInstance(uiComponent))) {
474: throw new IllegalArgumentException(
475: "Invalid Parameter - UIComponent class should be ["
476: + validComponentType
477: + "] but it is an instance of ["
478: + uiComponent.getClass() + "]");
479: }
480:
481: if ((uiComponent instanceof UIInput)
482: || (uiComponent instanceof UICommand)) {
483: if (findForm(uiComponent) == null) {
484: throw new NullPointerException(
485: "Missing Form - the UIComponent of type ["
486: + uiComponent.getClass()
487: + "] requires a containing form.");
488: }
489: }
490: }
491:
492: /**
493: * A component is static if it is disabled or readonly.
494: *
495: * @param uiComponent
496: * @return true if the component is disabled or readonly
497: */
498: public static boolean isStatic(UIComponent uiComponent) {
499: // the algorithm here is to return true as soon as we get affirmation that
500: // the component is static
501: boolean isStatic = false;
502: Object disabled = uiComponent.getAttributes().get("disabled");
503: Object readonly = uiComponent.getAttributes().get("readonly");
504: if (disabled != null) {
505: if (disabled instanceof Boolean) {
506: isStatic = ((Boolean) disabled).booleanValue();
507: } else if (disabled instanceof String) {
508: isStatic = ((String) disabled).equalsIgnoreCase("true");
509: }
510: }
511: if (isStatic) {
512: return isStatic;
513: }
514: if (readonly != null) {
515: if (readonly instanceof Boolean) {
516: return ((Boolean) readonly).booleanValue();
517: }
518: if (readonly instanceof String) {
519: return ((String) readonly).equalsIgnoreCase("true");
520: }
521: }
522: return isStatic;
523: }
524:
525: /**
526: * <p/>
527: * Given a UIComponent instance, recursively examine the heirarchy of parent
528: * UIComponents until the first NamingContainer is found. </p>
529: *
530: * @param uiComponent
531: * @return the nearest parent NamingContainer or null if none exist.
532: */
533: public static UIComponent findNamingContainer(
534: UIComponent uiComponent) {
535: UIComponent parent = uiComponent.getParent();
536: while (parent != null) {
537: if (parent instanceof NamingContainer) {
538: break;
539: }
540: parent = parent.getParent();
541: }
542: return parent;
543: }
544:
545: /**
546: * <p/>
547: * Given a UIComponent instance, recursively examine the heirarchy of parent
548: * NamingContainers until a Form is found. </p>
549: *
550: * @param uiComponent the UIComponent instance
551: * @return form as the UIComponent instance
552: */
553: public static UIComponent findForm(UIComponent uiComponent) {
554: UIComponent parent = uiComponent.getParent();
555: while (parent != null && !(parent instanceof UIForm)) {
556: parent = findNamingContainer(parent);
557: }
558: UIComponent form = null;
559: // check family
560: if (parent != null
561: && (parent.getFamily().equalsIgnoreCase(WEB_UIFORM)
562: || parent.getFamily().equalsIgnoreCase(UIFORM) || parent
563: .getFamily().equalsIgnoreCase(WEB_UIJSFFORM))) {
564: form = (UIComponent) parent;
565: }
566:
567: if (form == null && Beans.isDesignTime()) {
568: form = uiComponent.getParent();
569: }
570: return form;
571: }
572:
573: /**
574: * This method fabricates the clientId of a component. It should be used
575: * only when the clientId of the uiComponent is required in advance of the
576: * component existing. The uiComponentId may be provided by, for example, a
577: * label element with a 'for' attribute defined. The for attribute will be
578: * the id of the component that will eventually be created.
579: * <p/>
580: * Determine the id of the nearest parental naming container and prepend it
581: * to the id of the component's id.
582: *
583: * @param uiComponent
584: * @param facesContext
585: * @param uiComponentId
586: * @return
587: */
588: String fabricateClientId(UIComponent uiComponent,
589: FacesContext facesContext, String uiComponentId) {
590: UIComponent parentNamingContainer = findNamingContainer(uiComponent);
591: String parentNamingContainerClientId = null;
592: if (parentNamingContainer == null) {
593: return uiComponentId;
594: } else {
595: parentNamingContainerClientId = parentNamingContainer
596: .getClientId(facesContext);
597: }
598: return parentNamingContainerClientId
599: + NamingContainer.SEPARATOR_CHAR + uiComponentId;
600: }
601:
602: protected String[] getColumnStyleClasses(UIComponent uiComponent) {
603: return getStyleClasses(uiComponent, "columnClasses");
604: }
605:
606: /**
607: * This method, given a component, will return an array of the component's
608: * row classes.
609: *
610: * @param uiComponent
611: * @return a String array of row classes defined in a tag attribute or
612: * defined by default, depending on the component. Can be a
613: * zero-length array
614: */
615: public String[] getRowStyleClasses(UIComponent uiComponent) {
616: return getStyleClasses(uiComponent, "rowClasses");
617: }
618:
619: public String[] getStyleClasses(UIComponent uiComponent,
620: String styleClassAttributeName) {
621: String allStyleClasses = (String) uiComponent.getAttributes()
622: .get(styleClassAttributeName);
623: if (allStyleClasses == null) {
624: return (new String[0]);
625: }
626:
627: String separator = ",";
628: if (allStyleClasses.indexOf(separator) <= 0) {
629: separator = " ";
630: }
631: String[] styleClassesArray = allStyleClasses.trim().split(
632: separator);
633: int numberOfStyles = styleClassesArray.length;
634: for (int i = 0; i < numberOfStyles; i++) {
635: styleClassesArray[i] = styleClassesArray[i].trim();
636: }
637: return styleClassesArray;
638: }
639:
640: /**
641: * Get the style and style class associated with the severity of the
642: * FacesMessage
643: *
644: * @param uiComponent
645: * @param facesMessage
646: * @return
647: */
648: static String[] getStyleAndStyleClass(UIComponent uiComponent,
649: FacesMessage facesMessage) {
650: // obtain the severity style and severity style class
651: String severityStyle = null;
652: String severityStyleClass = null;
653: Severity messageSeverity = facesMessage.getSeverity();
654: if (messageSeverity == FacesMessage.SEVERITY_INFO) {
655: severityStyle = (String) uiComponent.getAttributes().get(
656: "infoStyle");
657: if (uiComponent instanceof HtmlMessage) {
658: severityStyleClass = ((HtmlMessage) uiComponent)
659: .getInfoClass();
660: } else if (uiComponent instanceof HtmlMessages) {
661: severityStyleClass = ((HtmlMessages) uiComponent)
662: .getInfoClass();
663: }
664: } else if (messageSeverity == FacesMessage.SEVERITY_WARN) {
665: severityStyle = (String) uiComponent.getAttributes().get(
666: "warnStyle");
667: if (uiComponent instanceof HtmlMessage) {
668: severityStyleClass = ((HtmlMessage) uiComponent)
669: .getWarnClass();
670: } else if (uiComponent instanceof HtmlMessages) {
671: severityStyleClass = ((HtmlMessages) uiComponent)
672: .getWarnClass();
673: }
674: } else if (messageSeverity == FacesMessage.SEVERITY_ERROR) {
675: severityStyle = (String) uiComponent.getAttributes().get(
676: "errorStyle");
677: if (uiComponent instanceof HtmlMessage) {
678: severityStyleClass = ((HtmlMessage) uiComponent)
679: .getErrorClass();
680: } else if (uiComponent instanceof HtmlMessages) {
681: severityStyleClass = ((HtmlMessages) uiComponent)
682: .getErrorClass();
683: }
684: } else if (messageSeverity == FacesMessage.SEVERITY_FATAL) {
685: severityStyle = (String) uiComponent.getAttributes().get(
686: "fatalStyle");
687: if (uiComponent instanceof HtmlMessage) {
688: severityStyleClass = ((HtmlMessage) uiComponent)
689: .getFatalClass();
690: } else if (uiComponent instanceof HtmlMessages) {
691: severityStyleClass = ((HtmlMessages) uiComponent)
692: .getFatalClass();
693: }
694: }
695:
696: String style = null;
697: if (severityStyle != null) {
698: style = severityStyle;
699: } else {
700: style = (String) uiComponent.getAttributes().get("style");
701: }
702: String styleClass = null;
703: if (severityStyleClass != null) {
704: styleClass = severityStyleClass;
705: } else {
706: if (uiComponent instanceof HtmlMessage) {
707: styleClass = ((HtmlMessage) uiComponent)
708: .getStyleClass();
709: } else if (uiComponent instanceof HtmlMessages) {
710: styleClass = ((HtmlMessages) uiComponent)
711: .getStyleClass();
712: }
713: }
714: return new String[] { style, styleClass };
715: }
716:
717: /**
718: * @param facesMessage
719: * @return
720: */
721: String[] getSummaryAndDetail(FacesMessage facesMessage) {
722: String summary = facesMessage.getSummary();
723: if (summary == null) {
724: summary = "";
725: }
726: String detail = facesMessage.getDetail();
727: if (detail == null) {
728: detail = "";
729: }
730: return new String[] { summary, detail };
731: }
732:
733: /**
734: * @param uiComponent
735: * @return
736: */
737: boolean getToolTipAttribute(UIComponent uiComponent) {
738: boolean tooltip = false;
739: Object tooltipAttribute = uiComponent.getAttributes().get(
740: "tooltip");
741: if (tooltipAttribute instanceof Boolean
742: && ((Boolean) tooltipAttribute).booleanValue()) {
743: tooltip = true;
744: }
745: return tooltip;
746: }
747:
748: /**
749: * @param converterClass
750: * @return
751: */
752: Converter getConverterForClass(Class converterClass) {
753: if (converterClass == null) {
754: return null;
755: }
756: try {
757: ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder
758: .getFactory(FactoryFinder.APPLICATION_FACTORY);
759: Application application = aFactory.getApplication();
760: return (application.createConverter(converterClass));
761: } catch (Exception e) {
762: return (null);
763: }
764: }
765:
766: public static String getResourceURL(FacesContext context,
767: String path) {
768: return context.getApplication().getViewHandler()
769: .getResourceURL(context, path);
770: }
771: }
|