001: /* BaseListbox.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Aug 8, 2007 5:48:27 PM 2007, Created by Dennis.Chen
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.jsf.zul.impl;
020:
021: import java.util.Map;
022:
023: import javax.faces.context.FacesContext;
024:
025: import org.zkoss.zk.ui.Component;
026: import org.zkoss.zk.ui.event.Event;
027: import org.zkoss.zk.ui.event.EventListener;
028: import org.zkoss.zk.ui.event.Events;
029: import org.zkoss.zul.Radio;
030: import org.zkoss.zul.Radiogroup;
031:
032: /**
033: * The Base implementation of Radiogroup.
034: * This component should be declared nested under {@link org.zkoss.jsf.zul.Page}.
035: * @author Dennis.Chen
036: *
037: */
038: abstract public class BaseRadiogroup extends BranchInput {
039:
040: /**
041: * Override it, and return null, It means that do not map value of ValueHolder to zul component. i
042: * will take case value of ValueHolder to selecteItem of radiogroup .
043: * @return always null
044: */
045: public String getMappedAttributeName() {
046: return null;
047: }
048:
049: protected void afterZULComponentComposed(Component zulcomp) {
050: super .afterZULComponentComposed(zulcomp);
051:
052: if (isLocalValueSet() || getValueBinding("value") != null) {
053:
054: zulcomp.addEventListener("onProcessZULJSFSelection",
055: new ProcessSelection());
056:
057: //send onProcessZULJSFSelection as late as possible.
058: Events.postEvent("onProcessZULJSFSelection", zulcomp,
059: getValue());
060: }
061: }
062:
063: private class ProcessSelection implements EventListener {
064: public void onEvent(Event event) throws Exception {
065: Radiogroup radiogroup = (Radiogroup) event.getTarget();
066: Object value = event.getData();
067: processSelection(radiogroup, value);
068: }
069: }
070:
071: /**
072: * set selected item of listbox by value,
073: */
074: private void processSelection(Radiogroup radiogroup, Object value) {
075: if (value == null)
076: return;
077: //radiogroup.setSelectedIndex(-1);
078:
079: int size = -1;
080: Object data = null;
081:
082: size = radiogroup.getItemCount();
083:
084: for (int i = 0; i < size; i++) {
085: data = null;
086: Radio item = radiogroup.getItemAtIndex(i);
087: data = item.getValue();
088:
089: if (data != null && value.equals(data)) {
090: item.setSelected(true);
091: radiogroup.setSelectedItem(item);
092: }
093: }
094: }
095:
096: /**
097: * decode parameter in request,
098: * @param context
099: */
100: protected void clientInputDecode(FacesContext context) {
101: String clientId = this .getClientId(context);
102: Map requestMap = context.getExternalContext()
103: .getRequestParameterMap();
104: if (requestMap.containsKey(clientId)) {
105: String newValue = (String) context.getExternalContext()
106: .getRequestParameterMap().get(clientId);
107: if (newValue != null) {
108: setSubmittedValue(newValue);
109: }
110: }
111: }
112:
113: }
|