001: /*
002: * Copyright 2004 The Apache Software Foundation.
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: */
016: package org.apache.myfaces.shared_impl.renderkit.html;
017:
018: import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
019:
020: import javax.faces.component.UIComponent;
021: import javax.faces.component.UISelectMany;
022: import javax.faces.component.UISelectOne;
023: import javax.faces.component.html.HtmlSelectManyMenu;
024: import javax.faces.component.html.HtmlSelectOneMenu;
025: import javax.faces.context.FacesContext;
026: import javax.faces.convert.ConverterException;
027: import java.io.IOException;
028:
029: /**
030: * X-CHECKED: tlddoc of h:selectManyListbox
031: *
032: * @author Manfred Geiler (latest modification by $Author: manolito $)
033: * @author Thomas Spiegl
034: * @version $Revision: 380686 $ $Date: 2006-02-24 16:19:28 +0100 (Fr, 24 Feb 2006) $
035: */
036: public class HtmlMenuRendererBase extends HtmlRenderer {
037: //private static final Log log = LogFactory.getLog(HtmlMenuRenderer.class);
038:
039: public void encodeEnd(FacesContext facesContext,
040: UIComponent component) throws IOException {
041: RendererUtils.checkParamValidity(facesContext, component, null);
042:
043: if (component instanceof UISelectMany) {
044: HtmlRendererUtils.renderMenu(facesContext,
045: (UISelectMany) component, isDisabled(facesContext,
046: component));
047: } else if (component instanceof UISelectOne) {
048: HtmlRendererUtils.renderMenu(facesContext,
049: (UISelectOne) component, isDisabled(facesContext,
050: component));
051: } else {
052: throw new IllegalArgumentException(
053: "Unsupported component class "
054: + component.getClass().getName());
055: }
056: }
057:
058: protected boolean isDisabled(FacesContext facesContext,
059: UIComponent uiComponent) {
060: //TODO: overwrite in extended HtmlMenuRenderer and check for enabledOnUserRole
061: if (uiComponent instanceof HtmlSelectManyMenu) {
062: return ((HtmlSelectManyMenu) uiComponent).isDisabled();
063: } else if (uiComponent instanceof HtmlSelectOneMenu) {
064: return ((HtmlSelectOneMenu) uiComponent).isDisabled();
065: } else {
066: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
067: .getBooleanAttribute(
068: uiComponent,
069: org.apache.myfaces.shared_impl.renderkit.html.HTML.DISABLED_ATTR,
070: false);
071: }
072: }
073:
074: public void decode(FacesContext facesContext,
075: UIComponent uiComponent) {
076: org.apache.myfaces.shared_impl.renderkit.RendererUtils
077: .checkParamValidity(facesContext, uiComponent, null);
078:
079: if (uiComponent instanceof UISelectMany) {
080: HtmlRendererUtils.decodeUISelectMany(facesContext,
081: uiComponent);
082: } else if (uiComponent instanceof UISelectOne) {
083: HtmlRendererUtils.decodeUISelectOne(facesContext,
084: uiComponent);
085: } else {
086: throw new IllegalArgumentException(
087: "Unsupported component class "
088: + uiComponent.getClass().getName());
089: }
090: }
091:
092: public Object getConvertedValue(FacesContext facesContext,
093: UIComponent uiComponent, Object submittedValue)
094: throws ConverterException {
095: org.apache.myfaces.shared_impl.renderkit.RendererUtils
096: .checkParamValidity(facesContext, uiComponent, null);
097:
098: if (uiComponent instanceof UISelectMany) {
099: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
100: .getConvertedUISelectManyValue(facesContext,
101: (UISelectMany) uiComponent, submittedValue);
102: } else if (uiComponent instanceof UISelectOne) {
103: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
104: .getConvertedUIOutputValue(facesContext,
105: (UISelectOne) uiComponent, submittedValue);
106: } else {
107: throw new IllegalArgumentException(
108: "Unsupported component class "
109: + uiComponent.getClass().getName());
110: }
111: }
112:
113: }
|