All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.icesoft.faces.component.ext.HtmlSelectOneMenu Maven / Gradle / Ivy

There is a newer version: 3.3.0
Show newest version
/*
 * Copyright 2004-2012 ICEsoft Technologies Canada Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS
 * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.icesoft.faces.component.ext;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItem;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.model.SelectItem;

import com.icesoft.faces.component.CSS_DEFAULT;
import com.icesoft.faces.component.IceExtended;
import com.icesoft.faces.component.PORTLET_CSS_DEFAULT;
import com.icesoft.faces.component.ext.taglib.Util;
import com.icesoft.faces.context.effects.CurrentStyle;
import com.icesoft.faces.context.effects.Effect;
import com.icesoft.faces.context.effects.JavascriptContext;
import com.icesoft.faces.util.CoreUtils;
import com.icesoft.util.CoreComponentUtils;


/**
 * This is an extension of javax.faces.component.html.HtmlSelectOneMenu, which
 * provides some additional behavior to this component such as: 
  • default * classes for enabled and disabled state
  • provides partial submit * mechanism
  • changes the component's enabled and rendered state based * on the authentication
  • adds effects to the component
    • */ public class HtmlSelectOneMenu extends javax.faces.component.html.HtmlSelectOneMenu implements IceExtended { public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlSelectOneMenu"; public static final String RENDERER_TYPE = "com.icesoft.faces.Menu"; private static final boolean DEFAULT_VISIBLE = true; private String styleClass = null; private Boolean partialSubmit = null; private String enabledOnUserRole = null; private String renderedOnUserRole = null; private Effect effect; private Boolean visible = null; private Effect onclickeffect; private Effect ondblclickeffect; private Effect onmousedowneffect; private Effect onmouseupeffect; private Effect onmousemoveeffect; private Effect onmouseovereffect; private Effect onmouseouteffect; private Effect onkeypresseffect; private Effect onkeydowneffect; private Effect onkeyupeffect; private CurrentStyle currentStyle; private Effect onchangeeffect; public HtmlSelectOneMenu() { super(); setRendererType(RENDERER_TYPE); } /** * This method is used to communicate a focus request from the application * to the client browser. */ public void requestFocus() { CoreComponentUtils.setFocusId("null"); JavascriptContext.focus(FacesContext.getCurrentInstance(), this.getClientId( FacesContext.getCurrentInstance())); } public SelectItem[] getSelectItems() { List selectItems = new ArrayList(); Iterator children = this.getChildren().iterator(); while (children.hasNext()) { UIComponent child = (UIComponent) children.next(); if (child instanceof UISelectItem) { Object selectItemValue = ((UISelectItem) child).getValue(); if (selectItemValue != null && selectItemValue instanceof SelectItem) { selectItems.add(selectItemValue); } else { //If user defines only one member, either itemValue or itemLabel //The default implementation throws a null pointer exception. //So here we are identifying, if either itemValue or itemLabel is found, //Assigned its value to the other member assignDataIfNull(child); selectItems.add( new SelectItem( ((UISelectItem) child).getItemValue(), ((UISelectItem) child).getItemLabel(), ((UISelectItem) child).getItemDescription(), ((UISelectItem) child).isItemDisabled())); } } else if (child instanceof UISelectItems) { Object selectItemsValue = ((UISelectItems) child).getValue(); if (selectItemsValue != null) { if (selectItemsValue instanceof SelectItem) { selectItems.add(selectItemsValue); } else if (selectItemsValue instanceof Collection) { Iterator selectItemsIterator = ((Collection) selectItemsValue).iterator(); while (selectItemsIterator.hasNext()) { selectItems.add(selectItemsIterator.next()); } } else if (selectItemsValue instanceof SelectItem[]) { SelectItem selectItemArray[] = (SelectItem[]) selectItemsValue; for (int i = 0; i < selectItemArray.length; i++) { selectItems.add(selectItemArray[i]); } } else if (selectItemsValue instanceof Map) { Iterator selectItemIterator = ((Map) selectItemsValue).keySet().iterator(); while (selectItemIterator.hasNext()) { Object nextKey = selectItemIterator.next(); if (nextKey != null) { Object nextValue = ((Map) selectItemsValue).get(nextKey); if (nextValue != null) { selectItems.add( new SelectItem( nextValue.toString(), nextKey.toString())); } } } } else if (selectItemsValue instanceof String[]) { String stringItemArray[] = (String[]) selectItemsValue; for (int i = 0; i < stringItemArray.length; i++) { selectItems.add(new SelectItem(stringItemArray[i])); } } } } } return (SelectItem[]) selectItems .toArray(new SelectItem[selectItems.size()]); } static void assignDataIfNull(Object selectItem) { UISelectItem uiSelectItem = (UISelectItem) selectItem; if (uiSelectItem.getItemValue() == null) { if (uiSelectItem.getItemLabel() != null) { uiSelectItem.setItemValue(uiSelectItem.getItemLabel()); } } if (uiSelectItem.getItemLabel() == null) { if (uiSelectItem.getItemValue() != null) { uiSelectItem .setItemLabel(uiSelectItem.getItemValue().toString()); } } } public void setValueBinding(String s, ValueBinding vb) { if (s != null && s.indexOf("effect") != -1) { // If this is an effect attribute make sure Ice Extras is included JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } super.setValueBinding(s, vb); } /** *

      Set the value of the visible property.

      */ public void setVisible(boolean visible) { this.visible = Boolean.valueOf(visible); } /** *

      Return the value of the visible property.

      */ public boolean getVisible() { if (visible != null) { return visible.booleanValue(); } ValueBinding vb = getValueBinding("visible"); Boolean boolVal = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null; return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE; } /** *

      Set the value of the effect property.

      */ public void setEffect(Effect effect) { this.effect = effect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the effect property.

      */ public Effect getEffect() { if (effect != null) { return effect; } ValueBinding vb = getValueBinding("effect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the visible property.

      */ public void setPartialSubmit(boolean partialSubmit) { this.partialSubmit = Boolean.valueOf(partialSubmit); } /** *

      Return the value of the partialSubmit property.

      */ public boolean getPartialSubmit() { if (partialSubmit != null) { return partialSubmit.booleanValue(); } ValueBinding vb = getValueBinding("partialSubmit"); Boolean boolVal = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null; return boolVal != null ? boolVal.booleanValue() : Util.isParentPartialSubmit(this); } /** *

      Set the value of the enabledOnUserRole property.

      */ public void setEnabledOnUserRole(String enabledOnUserRole) { this.enabledOnUserRole = enabledOnUserRole; } /** *

      Return the value of the enabledOnUserRole property.

      */ public String getEnabledOnUserRole() { if (enabledOnUserRole != null) { return enabledOnUserRole; } ValueBinding vb = getValueBinding("enabledOnUserRole"); return vb != null ? (String) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the renderedOnUserRole property.

      */ public void setRenderedOnUserRole(String renderedOnUserRole) { this.renderedOnUserRole = renderedOnUserRole; } /** *

      Return the value of the renderedOnUserRole property.

      */ public String getRenderedOnUserRole() { if (renderedOnUserRole != null) { return renderedOnUserRole; } ValueBinding vb = getValueBinding("renderedOnUserRole"); return vb != null ? (String) vb.getValue(getFacesContext()) : null; } /** *

      Return the value of the rendered property.

      */ public boolean isRendered() { if (!Util.isRenderedOnUserRole(this)) { return false; } return super.isRendered(); } /** *

      Set the value of the styleClass property.

      */ public void setStyleClass(String styleClass) { this.styleClass = styleClass; } /** *

      Return the value of the styleClass property.

      */ public String getStyleClass() { return Util.getQualifiedStyleClass(this, styleClass, CSS_DEFAULT.SELECT_ONE_MENU_DEFAULT_STYLE_CLASS, "styleClass", isDisabled(), PORTLET_CSS_DEFAULT.PORTLET_FORM_FIELD); } /** *

      Return the value of the disabled property.

      */ public boolean isDisabled() { if (!Util.isEnabledOnUserRole(this)) { return true; } else { return super.isDisabled(); } } /** *

      Return the value of the onchangeeffect property.

      */ public Effect getOnchangeeffect() { if (onchangeeffect != null) { return onchangeeffect; } ValueBinding vb = getValueBinding("onchangeeffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onchangeeffect property.

      */ public void setOnchangeeffect(Effect onchangeeffect) { this.onchangeeffect = onchangeeffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the currentStyle property.

      */ public CurrentStyle getCurrentStyle() { return currentStyle; } /** *

      Set the value of the currentStyle property.

      */ public void setCurrentStyle(CurrentStyle currentStyle) { this.currentStyle = currentStyle; } /** *

      Set the value of the onclickeffect property.

      */ public void setOnclickeffect(Effect onclickeffect) { this.onclickeffect = onclickeffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the ondblclickeffect property.

      */ public Effect getOndblclickeffect() { if (ondblclickeffect != null) { return ondblclickeffect; } ValueBinding vb = getValueBinding("ondblclickeffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the ondblclickeffect property.

      */ public void setOndblclickeffect(Effect ondblclickeffect) { this.ondblclickeffect = ondblclickeffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onmousedowneffect property.

      */ public Effect getOnmousedowneffect() { if (onmousedowneffect != null) { return onmousedowneffect; } ValueBinding vb = getValueBinding("onmousedowneffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onmousedowneffect property.

      */ public void setOnmousedowneffect(Effect onmousedowneffect) { this.onmousedowneffect = onmousedowneffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onmouseupeffect property.

      */ public Effect getOnmouseupeffect() { if (onmouseupeffect != null) { return onmouseupeffect; } ValueBinding vb = getValueBinding("onmouseupeffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onmouseupeffect property.

      */ public void setOnmouseupeffect(Effect onmouseupeffect) { this.onmouseupeffect = onmouseupeffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onmousemoveeffect property.

      */ public Effect getOnmousemoveeffect() { if (onmousemoveeffect != null) { return onmousemoveeffect; } ValueBinding vb = getValueBinding("onmousemoveeffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onmousemoveeffect property.

      */ public void setOnmousemoveeffect(Effect onmousemoveeffect) { this.onmousemoveeffect = onmousemoveeffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onmouseovereffect property.

      */ public Effect getOnmouseovereffect() { if (onmouseovereffect != null) { return onmouseovereffect; } ValueBinding vb = getValueBinding("onmouseovereffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onmouseovereffect property.

      */ public void setOnmouseovereffect(Effect onmouseovereffect) { this.onmouseovereffect = onmouseovereffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onmouseouteffect property.

      */ public Effect getOnmouseouteffect() { if (onmouseouteffect != null) { return onmouseouteffect; } ValueBinding vb = getValueBinding("onmouseouteffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onmouseouteffect property.

      */ public void setOnmouseouteffect(Effect onmouseouteffect) { this.onmouseouteffect = onmouseouteffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onkeypresseffect property.

      */ public Effect getOnkeypresseffect() { if (onkeypresseffect != null) { return onkeypresseffect; } ValueBinding vb = getValueBinding("onkeypresseffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onkeypresseffect property.

      */ public void setOnkeypresseffect(Effect onkeypresseffect) { this.onkeypresseffect = onkeypresseffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onkeydowneffect property.

      */ public Effect getOnkeydowneffect() { if (onkeydowneffect != null) { return onkeydowneffect; } ValueBinding vb = getValueBinding("onkeydowneffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onkeydowneffect property.

      */ public void setOnkeydowneffect(Effect onkeydowneffect) { this.onkeydowneffect = onkeydowneffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onkeyupeffect property.

      */ public Effect getOnkeyupeffect() { if (onkeyupeffect != null) { return onkeyupeffect; } ValueBinding vb = getValueBinding("onkeyupeffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } /** *

      Set the value of the onkeyupeffect property.

      */ public void setOnkeyupeffect(Effect onkeyupeffect) { this.onkeyupeffect = onkeyupeffect; JavascriptContext .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext()); } /** *

      Return the value of the onkeyupeffect property.

      */ public Effect getOnclickeffect() { if (onclickeffect != null) { return onclickeffect; } ValueBinding vb = getValueBinding("onclickeffect"); return vb != null ? (Effect) vb.getValue(getFacesContext()) : null; } private String autocomplete; /** *

      Set the value of the autocomplete property.

      */ public void setAutocomplete(String autocomplete) { this.autocomplete = autocomplete; } /** *

      Return the value of the autocomplete property.

      */ public String getAutocomplete() { if (autocomplete != null) { return autocomplete; } ValueBinding vb = getValueBinding("autocomplete"); return vb != null ? (String) vb.getValue(getFacesContext()) : null; } /** *

      Gets the state of the instance as a Serializable * Object.

      */ public Object saveState(FacesContext context) { Object values[] = new Object[20]; values[0] = super.saveState(context); values[1] = partialSubmit; values[2] = enabledOnUserRole; values[3] = renderedOnUserRole; values[4] = styleClass; values[5] = effect; values[6] = onclickeffect; values[7] = ondblclickeffect; values[8] = onmousedowneffect; values[9] = onmouseupeffect; values[10] = onmousemoveeffect; values[11] = onmouseovereffect; values[12] = onmouseouteffect; values[13] = onkeypresseffect; values[14] = onkeydowneffect; values[15] = onkeyupeffect; values[16] = onchangeeffect; values[17] = autocomplete; values[18] = currentStyle; values[19] = visible; return ((Object) (values)); } /** *

      Perform any processing required to restore the state from the entries * in the state Object.

      */ public void restoreState(FacesContext context, Object state) { Object values[] = (Object[]) state; super.restoreState(context, values[0]); partialSubmit = (Boolean) values[1]; enabledOnUserRole = (String) values[2]; renderedOnUserRole = (String) values[3]; styleClass = (String) values[4]; effect = (Effect) values[5]; onclickeffect = (Effect) values[6]; ondblclickeffect = (Effect) values[7]; onmousedowneffect = (Effect) values[8]; onmouseupeffect = (Effect) values[9]; onmousemoveeffect = (Effect) values[10]; onmouseovereffect = (Effect) values[11]; onmouseouteffect = (Effect) values[12]; onkeypresseffect = (Effect) values[13]; onkeydowneffect = (Effect) values[14]; onkeyupeffect = (Effect) values[15]; onchangeeffect = (Effect) values[16]; autocomplete = (String) values[17]; currentStyle = (CurrentStyle) values[18]; visible = (Boolean) values[19]; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy