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.JSFAttr;
019: import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
020:
021: import javax.faces.component.UIComponent;
022: import javax.faces.component.UISelectMany;
023: import javax.faces.component.UISelectOne;
024: import javax.faces.component.html.HtmlSelectManyListbox;
025: import javax.faces.component.html.HtmlSelectOneListbox;
026: import javax.faces.context.FacesContext;
027: import javax.faces.convert.ConverterException;
028: import java.io.IOException;
029:
030: /**
031: * @author Thomas Spiegl (latest modification by $Author: baranda $)
032: * @author Anton Koinov
033: * @version $Revision: 533376 $ $Date: 2007-04-28 18:01:42 +0200 (Sa, 28 Apr 2007) $
034: */
035: public class HtmlListboxRendererBase extends HtmlRenderer {
036: public void encodeEnd(FacesContext facesContext,
037: UIComponent uiComponent) throws IOException {
038: org.apache.myfaces.shared_impl.renderkit.RendererUtils
039: .checkParamValidity(facesContext, uiComponent, null);
040:
041: int size = (Integer) uiComponent.getAttributes().get(
042: JSFAttr.SIZE_ATTR);
043:
044: if (uiComponent instanceof UISelectMany) {
045: HtmlRendererUtils.renderListbox(facesContext,
046: (UISelectMany) uiComponent, isDisabled(
047: facesContext, uiComponent), size);
048: } else if (uiComponent instanceof HtmlSelectOneListbox) {
049: HtmlRendererUtils.renderListbox(facesContext,
050: (UISelectOne) uiComponent, isDisabled(facesContext,
051: uiComponent), size);
052: } else {
053: throw new IllegalArgumentException(
054: "Unsupported component class "
055: + uiComponent.getClass().getName());
056: }
057: }
058:
059: protected boolean isDisabled(FacesContext facesContext,
060: UIComponent uiComponent) {
061: //TODO: overwrite in extended HtmlListboxRenderer and check for enabledOnUserRole
062: if (uiComponent instanceof HtmlSelectManyListbox) {
063: return ((HtmlSelectManyListbox) uiComponent).isDisabled();
064: } else if (uiComponent instanceof HtmlSelectOneListbox) {
065: return ((HtmlSelectOneListbox) uiComponent).isDisabled();
066: } else {
067: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
068: .getBooleanAttribute(
069: uiComponent,
070: org.apache.myfaces.shared_impl.renderkit.html.HTML.DISABLED_ATTR,
071: false);
072: }
073: }
074:
075: public void decode(FacesContext facesContext,
076: UIComponent uiComponent) {
077: RendererUtils.checkParamValidity(facesContext, uiComponent,
078: null);
079:
080: if (uiComponent instanceof UISelectMany) {
081: HtmlRendererUtils.decodeUISelectMany(facesContext,
082: uiComponent);
083: } else if (uiComponent instanceof UISelectOne) {
084: HtmlRendererUtils.decodeUISelectOne(facesContext,
085: uiComponent);
086: } else {
087: throw new IllegalArgumentException(
088: "Unsupported component class "
089: + uiComponent.getClass().getName());
090: }
091: }
092:
093: public Object getConvertedValue(FacesContext facesContext,
094: UIComponent uiComponent, Object submittedValue)
095: throws ConverterException {
096: org.apache.myfaces.shared_impl.renderkit.RendererUtils
097: .checkParamValidity(facesContext, uiComponent, null);
098:
099: if (uiComponent instanceof UISelectMany) {
100: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
101: .getConvertedUISelectManyValue(facesContext,
102: (UISelectMany) uiComponent, submittedValue);
103: } else if (uiComponent instanceof UISelectOne) {
104: return RendererUtils.getConvertedUIOutputValue(
105: facesContext, (UISelectOne) uiComponent,
106: submittedValue);
107: } else {
108: throw new IllegalArgumentException(
109: "Unsupported component class "
110: + uiComponent.getClass().getName());
111: }
112: }
113:
114: }
|