Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.richfaces.renderkit.SelectManyRendererBase Maven / Gradle / Ivy
package org.richfaces.renderkit;
import org.richfaces.component.AbstractSelectManyComponent;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.component.util.SelectUtils;
import org.richfaces.renderkit.util.HtmlDimensions;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ResourceDependencies ({ @ResourceDependency (library = "org.richfaces" , name = "ajax.reslib" ),
@ResourceDependency (library = "org.richfaces" , name = "base-component.reslib" ),
@ResourceDependency (name = "jquery.position.js" ), @ResourceDependency (name = "richfaces-event.js" ),
@ResourceDependency (name = "richfaces-utils.js" ), @ResourceDependency (name = "richfaces-selection.js" ),
@ResourceDependency (library = "org.richfaces" , name = "inputBase.js" ),
@ResourceDependency (library = "org.richfaces" , name = "popup.js" ),
@ResourceDependency (library = "org.richfaces" , name = "list.js" ),
@ResourceDependency (library = "org.richfaces" , name = "listMulti.js" ),
@ResourceDependency (library = "org.richfaces" , name = "popupList.js" ),
@ResourceDependency (library = "org.richfaces" , name = "pickList.js" ),
@ResourceDependency (library = "org.richfaces" , name = "pickList.ecss" )})
public class SelectManyRendererBase extends InputRendererBase {
private static final String HIDDEN_SUFFIX = "Hidden" ;
public List getClientSelectItems (FacesContext facesContext, UIComponent component) {
AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
return SelectManyHelper.getClientSelectItems(facesContext, select, SelectUtils.getSelectItems(facesContext, component));
}
public String csvEncodeSelectedItems (List clientSelectItems) {
if (clientSelectItems == null || clientSelectItems.isEmpty()) {
return "" ;
}
StringBuilder sb = new StringBuilder();
Iterator iter = clientSelectItems.iterator();
while (iter.hasNext()) {
ClientSelectItem item = iter.next();
if (item.isSelected()) {
if (sb.length() > 0 ) {
sb.append("," );
}
sb.append(item.getConvertedValue());
}
}
return sb.toString();
}
@Override
protected void doDecode (FacesContext facesContext, UIComponent component) {
if (!(component instanceof AbstractSelectManyComponent)) {
throw new IllegalArgumentException(String.format("Component %s is not an AbstractSelectManyComponent" , component.getClientId(facesContext)));
}
AbstractSelectManyComponent picklist = (AbstractSelectManyComponent) component;
String hiddenClientId = picklist.getClientId(facesContext);
Map paramMap = facesContext.getExternalContext().getRequestParameterMap();
if (picklist.isDisabled()) {
return ;
}
String value = paramMap.get(hiddenClientId);
if (value != null ) {
if (value.trim().equals("" )) {
((EditableValueHolder) picklist).setSubmittedValue(new String[] {});
} else {
String[] reqValues = value.split("," );
((EditableValueHolder) picklist).setSubmittedValue(reqValues);
}
} else {
((EditableValueHolder) picklist).setSubmittedValue(new String[] {});
}
}
public Object getConvertedValue (FacesContext facesContext, UIComponent component, Object val) throws ConverterException {
return SelectManyHelper.getConvertedValue(facesContext, component, val);
}
public boolean hasColumnChildren (FacesContext facesContext, UIComponent component) {
AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
return select.columns().hasNext();
}
public boolean isHeaderExists (FacesContext facesContext, UIComponent component) {
AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
Iterator columnIterator = select.columns();
while (columnIterator.hasNext()) {
UIColumn column = columnIterator.next();
if (column.getFacet("header" ) != null ) {
return true ;
}
}
return false ;
}
protected String getMinListHeight (AbstractSelectManyComponent select) {
String height = HtmlDimensions.formatSize(select.getMinListHeight());
if (height == null || height.length() == 0 ) {
height = "20px" ;
}
return height;
}
protected String getMaxListHeight (AbstractSelectManyComponent select) {
String height = HtmlDimensions.formatSize(select.getMaxListHeight());
if (height == null || height.length() == 0 ) {
height = "100px" ;
}
return height;
}
protected String getListHeight (AbstractSelectManyComponent select) {
String height = HtmlDimensions.formatSize(select.getListHeight());
if (height == null || height.length() == 0 ) {
height = "auto" ;
}
return height;
}
protected String getListWidth (AbstractSelectManyComponent select) {
String width = HtmlDimensions.formatSize(select.getListWidth());
if (width == null || width.length() == 0 ) {
width = "200px" ;
}
return width;
}
public String encodeHeightAndWidth (UIComponent component) {
AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
String height = getListHeight(select);
if (!"auto" .equals(height)) {
height = (height != null && height.trim().length() != 0 ) ? ("height: " + height) : "" ;
} else {
String minHeight = getMinListHeight(select);
minHeight = (minHeight != null && minHeight.trim().length() != 0 ) ? ("min-height: " + minHeight) : "" ;
String maxHeight = getMaxListHeight(select);
maxHeight = (maxHeight != null && maxHeight.trim().length() != 0 ) ? ("max-height: " + maxHeight) : "" ;
height = concatStyles(minHeight, maxHeight);
}
String width = getListWidth(select);
width = (width != null && width.trim().length() != 0 ) ? ("width: " + width) : "" ;
return concatStyles(height, width);
}
public String getButtonClass (UIComponent component, String cssPrefix, String buttonClass) {
AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
if (!select.isDisabled()) {
return HtmlUtil.concatClasses(buttonClass, cssPrefix + SelectManyHelper.BUTTON_CSS);
} else {
return HtmlUtil.concatClasses(buttonClass, cssPrefix + SelectManyHelper.BUTTON_CSS, cssPrefix + SelectManyHelper.BUTTON_CSS_DIS);
}
}
}