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 org.w3c.dom.Element;
038: import org.w3c.dom.Text;
039:
040: import javax.faces.component.UIComponent;
041: import javax.faces.component.UISelectOne;
042: import javax.faces.context.FacesContext;
043: import javax.faces.model.SelectItem;
044: import java.io.IOException;
045: import java.util.HashSet;
046: import java.util.Set;
047:
048: public class RadioRenderer extends SelectManyCheckboxListRenderer {
049:
050: protected void renderOption(FacesContext facesContext,
051: UIComponent uiComponent, SelectItem selectItem,
052: boolean renderVertically, Element rootTR, int counter,
053: Object componentValue) throws IOException {
054: UISelectOne uiSelectOne = (UISelectOne) uiComponent;
055: DOMContext domContext = DOMContext.attachDOMContext(
056: facesContext, uiSelectOne);
057: Element rootTable = (Element) domContext.getRootNode();
058:
059: Object submittedValue = uiSelectOne.getSubmittedValue();
060: if (submittedValue == null) {
061: submittedValue = componentValue;
062: }
063: if (renderVertically) {
064: rootTR = domContext.createElement("tr");
065: rootTable.appendChild(rootTR);
066: }
067: String labelClass = null;
068: boolean disabled = false;
069: if (uiSelectOne.getAttributes().get("disabled") != null
070: && uiSelectOne.getAttributes().get("disabled").equals(
071: Boolean.TRUE)) {
072: disabled = true;
073:
074: }
075: if (selectItem.isDisabled()) {
076: disabled = true;
077: }
078: labelClass = (String) uiSelectOne.getAttributes().get(
079: "styleClass");
080: if (labelClass != null && disabled) {
081: labelClass += "-dis";
082: }
083:
084: Element td = domContext.createElement("td");
085: rootTR.appendChild(td);
086:
087: Element input = domContext.createElement("input");
088: td.appendChild(input);
089: input.setAttribute("type", "radio");
090:
091: if (disabled) {
092: input.setAttribute("disabled", "disabled");
093: }
094:
095: HashSet excludes = new HashSet();
096: String accesskey = (String) uiComponent.getAttributes().get(
097: "accesskey");
098: if (accesskey != null) {
099: input.setAttribute("accesskey", accesskey);
100: excludes.add("accesskey");
101: }
102:
103: Object selectItemValue = selectItem.getValue();
104:
105: if (selectItemValue != null
106: && String.valueOf(selectItemValue).equals(
107: String.valueOf(componentValue))) {
108: input.setAttribute("checked", "checked");
109: } else {
110: input.removeAttribute("checked");
111: }
112:
113: input.setAttribute("name", uiSelectOne
114: .getClientId(facesContext));
115: input.setAttribute("id", uiComponent.getClientId(facesContext)
116: + ":_" + counter);
117: input.setAttribute("value", (formatComponentValue(facesContext,
118: uiSelectOne, selectItem.getValue())));
119:
120: addJavaScript(facesContext, uiSelectOne, input, excludes);
121: // style is rendered on containing table
122: excludes.add("style");
123: excludes.add("readonly");
124: excludes.add("disabled");
125:
126: PassThruAttributeRenderer.renderAttributes(facesContext,
127: uiSelectOne, getExcludesArray(excludes));
128:
129: Element label = domContext.createElement("label");
130: td.appendChild(label);
131:
132: if (labelClass != null) {
133: label.setAttribute("class", labelClass);
134: }
135: String itemLabel = selectItem.getLabel();
136: if (itemLabel != null) {
137: Text labelText = domContext.getDocument().createTextNode(
138: itemLabel);
139: label.appendChild(labelText);
140: }
141: }
142:
143: protected void addJavaScript(FacesContext facesContext,
144: UIComponent uiSelectOne, Element input, Set excludes) {
145: }
146: }
|