Java Code Examples for javax.faces.component.UIComponent#getChildCount()
The following examples show how to use
javax.faces.component.UIComponent#getChildCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventHandlerUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
/** * Find if an event handler had been assigned for a particular event. * @param component * @param eventName * @return */ @SuppressWarnings("unchecked") // $NON-NLS-1$ public static XspEventHandler findHandler(UIComponent component, String eventName) { if(component.getChildCount()>0) { List<UIComponent> kids = component.getChildren(); for(UIComponent kid: kids) { if(kid instanceof XspEventHandler) { XspEventHandler h = (XspEventHandler)kid; if(StringUtil.equals(h.getEvent(),eventName)) { return h; } } } } return null; }
Example 2
Source File: AfterExpressionResolver.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
/** * Collects every JSF node following the current JSF node within the same branch of the tree. * It's like "@next @next:@next @next:@next:@next ...". */ public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId, String originalExpression, String[] parameters) { List<UIComponent> result = new ArrayList<UIComponent>(); for (UIComponent parent : parentComponents) { UIComponent grandparent = component.getParent(); for (int i = 0; i < grandparent.getChildCount(); i++) { if (grandparent.getChildren().get(i) == parent) { i++; while (i<grandparent.getChildCount()) { result.add(grandparent.getChildren().get(i)); i++; } } } } if (result.size() > 0) { return result; } throw new FacesException("Invalid search expression - there's no successor to the component " + originalExpression); }
Example 3
Source File: BeforeExpressionResolver.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
/** * Collects everything preceding the current JSF node within the same branch of the tree. * It's like "@previous previous:@previous previous:@previous:@previous ...". */ public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId, String originalExpression, String[] parameters) { List<UIComponent> result = new ArrayList<UIComponent>(); for (UIComponent parent : parentComponents) { UIComponent grandparent = component.getParent(); for (int i = 0; i < grandparent.getChildCount(); i++) { if (grandparent.getChildren().get(i) == parent) { if(i == 0) //if this is the first element of this component tree level there is no previous throw new FacesException(ERROR_MESSAGE + originalExpression); //otherwise take the components before this one while ((--i)>=0) { result.add(grandparent.getChildren().get(i)); } return result; } } } throw new FacesException(ERROR_MESSAGE + originalExpression); }
Example 4
Source File: UIDojoExtListTextBox.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
static private AbstractPicker _findPickerFor(UIComponent parent, String id) { if(parent.getChildCount()>0 || parent.getFacetCount() > 0) { for (Iterator<UIComponent> i = TypedUtil.getFacetsAndChildren(parent); i.hasNext();) { UIComponent next = i.next(); // Look if this child is the label if(next instanceof AbstractPicker) { AbstractPicker lbl = (AbstractPicker)next; String _for = lbl.getFor(); if(StringUtil.equals(_for, id)) { return lbl; } } if (!(next instanceof NamingContainer)) { AbstractPicker n = _findPickerFor(next, id); if (n != null) { return n; } } } } return null; }
Example 5
Source File: FacesComponentUtility.java From oxTrust with MIT License | 6 votes |
public static void dumpComponentsTree(List<UIComponent> componetns, int level) { if ((componetns == null) || (componetns.size() == 0)) { return; } StringBuffer levelString = new StringBuffer(); for (int i = 0; i < level; i++) { levelString.append(" "); } for (UIComponent comp : componetns) { System.out.println(levelString + comp.getId()); if (comp.getChildCount() > 0) { dumpComponentsTree(comp.getChildren(), level++); } } }
Example 6
Source File: SelectMultiMenuRenderer.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
/** * Renders components added seamlessly behind the input field. * * @param context * the FacesContext * @param rw * the response writer * @param appendingAddOnFacet * optional facet behind the field. Can be null. * @param hasAppendingAddOn * optional facet in front of the field. Can be null. * @throws IOException * may be thrown by the response writer */ protected void addAppendingAddOnToInputGroup(FacesContext context, ResponseWriter rw, UIComponent appendingAddOnFacet, boolean hasAppendingAddOn, SelectMultiMenu menu) throws IOException { if (hasAppendingAddOn) { if (appendingAddOnFacet.getClass().getName().endsWith("Button") || (appendingAddOnFacet.getChildCount() > 0 && appendingAddOnFacet.getChildren().get(0).getClass().getName().endsWith("Button"))) { rw.startElement("div", menu); rw.writeAttribute("class", "input-group-btn", "class"); appendingAddOnFacet.encodeAll(context); rw.endElement("div"); } else { rw.startElement("span", menu); rw.writeAttribute("class", "input-group-addon", "class"); appendingAddOnFacet.encodeAll(context); rw.endElement("span"); } } }
Example 7
Source File: FacesComponentUtility.java From oxTrust with MIT License | 6 votes |
private static void resetInputComponents(UIComponent rootUIComponent) { if ((rootUIComponent == null) || (rootUIComponent.getChildCount() == 0)) { return; } for (UIComponent comp : rootUIComponent.getChildren()) { if (comp instanceof UIInput) { UIInput uiInput = (UIInput) comp; uiInput.setSubmittedValue(null); uiInput.setValid(true); uiInput.setLocalValueSet(false); uiInput.resetValue(); } resetInputComponents(comp); } }
Example 8
Source File: DynamicUIUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * Remove all the children from a component. * @param component the parent component * @param facets indicates if the facets should be removed as well */ public static void removeChildren(UIComponent component, boolean facets) { if(component.getChildCount()>0) { TypedUtil.getChildren(component).clear(); } if(component.getFacetCount()>0) { TypedUtil.getFacets(component).clear(); } }
Example 9
Source File: UIFormLayoutRow.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
private UIInput findEdit(UIComponent parent) { for(UIComponent c: TypedUtil.getChildren(parent)) { if(c instanceof UIInput) { return (UIInput)c; } if(c.getChildCount()>0) { UIInput e = findEdit(c); if(e!=null) { return e; } } } return null; }
Example 10
Source File: AbstractApplicationLayoutRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected boolean isEmptyChildren(UIComponent c) { if(c.getChildCount()>0) { // We should check the children one by one... for(UIComponent child: TypedUtil.getChildren(c)) { if(!isEmptyComponent(child)) { return false; } } } // No children, so the list is empty return true; }
Example 11
Source File: AbstractApplicationLayoutRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected void renderChildren(FacesContext context, UIComponent component) throws IOException { // encode component and children int count = component.getChildCount(); if(count>0) { List<?> children = component.getChildren(); for (int i=0; i<count; i++) { UIComponent child = (UIComponent)children.get(i); if(isRenderChild(context, child)) { FacesUtil.renderComponent(context, child); } } } }
Example 12
Source File: SelectMultiMenuRenderer.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Renders components added seamlessly in front of the input field. * * @param context * the FacesContext * @param rw * the response writer * @param prependingAddOnFacet * @param hasPrependingAddOn * @throws IOException * may be thrown by the response writer */ protected void addPrependingAddOnToInputGroup(FacesContext context, ResponseWriter rw, UIComponent prependingAddOnFacet, boolean hasPrependingAddOn, SelectMultiMenu menu) throws IOException { if (hasPrependingAddOn) { if (prependingAddOnFacet.getClass().getName().endsWith("Button") || (prependingAddOnFacet.getChildCount() > 0 && prependingAddOnFacet.getChildren().get(0).getClass().getName().endsWith("Button"))) { rw.startElement("div", menu); rw.writeAttribute("class", "input-group-btn", "class"); prependingAddOnFacet.encodeAll(context); rw.endElement("div"); } else if (prependingAddOnFacet instanceof HtmlOutputText) { HtmlOutputText out = (HtmlOutputText) prependingAddOnFacet; String sc = out.getStyleClass(); if (sc == null) sc = "input-group-addon"; else sc = sc + " " + "input-group-addon"; out.setStyleClass(sc); prependingAddOnFacet.encodeAll(context); } else { rw.startElement("span", menu); rw.writeAttribute("class", "input-group-addon", "class"); prependingAddOnFacet.encodeAll(context); rw.endElement("span"); } } }
Example 13
Source File: ResponsiveAppLayoutRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected void renderChildren(FacesContext context, UIComponent component) throws IOException { // encode component and children int count = component.getChildCount(); if (count > 0) { List<?> children = component.getChildren(); for (int i = 0; i < count; i++) { UIComponent child = (UIComponent) children.get(i); if (isRenderChild(context, child)) { FacesUtil.renderComponent(context, child); } } } }
Example 14
Source File: R.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Add the correct class * * @param parent * @param comp * @param ctx * @param rw * @throws IOException */ private static void decorateComponent(UIComponent parent, UIComponent comp, FacesContext ctx, ResponseWriter rw) throws IOException { if (comp instanceof Icon) ((Icon) comp).setAddon(true); // modifies the id of the icon String classToApply = "input-group-addon"; if (comp.getClass().getName().endsWith("Button") || comp.getChildCount() > 0) classToApply = "input-group-btn"; if (comp instanceof HtmlOutputText) { HtmlOutputText out = (HtmlOutputText)comp; String sc = out.getStyleClass(); if (sc == null) sc = classToApply; else sc = sc + " " + classToApply; out.setStyleClass(sc); comp.encodeAll(ctx); } else { rw.startElement("span", parent); rw.writeAttribute("class", classToApply, "class"); comp.encodeAll(ctx); rw.endElement("span"); } }
Example 15
Source File: SimpleResponsiveLayoutRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected boolean isEmptyChildren(UIComponent c) { if (c.getChildCount() > 0) { // We should check the children one by one... for (UIComponent child : TypedUtil.getChildren(c)) { if (!isEmptyComponent(child)) { return false; } } } // No children, so the list is empty return true; }
Example 16
Source File: ResponsiveAppLayoutRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected boolean isEmptyChildren(UIComponent c) { if (c.getChildCount() > 0) { // We should check the children one by one... for (UIComponent child : TypedUtil.getChildren(c)) { if (!isEmptyComponent(child)) { return false; } } } // No children, so the list is empty return true; }
Example 17
Source File: PreviousExpressionResolver.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
private UIComponent findPredecessor(UIComponent parent) { UIComponent grandparent = parent.getParent(); for (int i = 0; i < grandparent.getChildCount(); i++) { if (grandparent.getChildren().get(i) == parent) { if(i == 0) //if this is the first element of this component tree level there is no previous return null; //otherwise take the component before this one return grandparent.getChildren().get(i-1); } } return null; // unreachable code - but the compiler doesn't know that }
Example 18
Source File: RowGroupDataTableRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
public void encodeInnerHtml(FacesContext facesContext, UIComponent component)throws IOException { UIData uiData = (UIData) component; ResponseWriter writer = facesContext.getResponseWriter(); Styles styles = getStyles(uiData); int first = uiData.getFirst(); int rows = uiData.getRows(); int rowCount = uiData.getRowCount(); if (rows <= 0) { rows = rowCount - first; } int last = first + rows; if (last > rowCount) last = rowCount; for (int i = first; i < last; i++) { uiData.setRowIndex(i); if (!uiData.isRowAvailable()) { log.warn("Row is not available. Rowindex = " + i); return; } int columns = component.getChildCount(); renderCategoryRow(i, columns, uiData, writer, i==first); beforeRow(facesContext, uiData); HtmlRendererUtils.writePrettyLineSeparator(facesContext); renderRowStart(facesContext, writer, uiData, styles, i); List children = component.getChildren(); for (int j = 0, size = component.getChildCount(); j < size; j++) { UIComponent child = (UIComponent) children.get(j); if(child.isRendered()) { encodeColumnChild(facesContext, writer, uiData, child, styles, j); } } renderRowEnd(facesContext, writer, uiData); afterRow(facesContext, uiData); } }
Example 19
Source File: RowGroupDataTableRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
public void encodeInnerHtml(FacesContext facesContext, UIComponent component)throws IOException { UIData uiData = (UIData) component; ResponseWriter writer = facesContext.getResponseWriter(); Styles styles = getStyles(uiData); int first = uiData.getFirst(); int rows = uiData.getRows(); int rowCount = uiData.getRowCount(); if (rows <= 0) { rows = rowCount - first; } int last = first + rows; if (last > rowCount) last = rowCount; for (int i = first; i < last; i++) { uiData.setRowIndex(i); if (!uiData.isRowAvailable()) { log.warn("Row is not available. Rowindex = " + i); return; } int columns = component.getChildCount(); renderCategoryRow(i, columns, uiData, writer, i==first); beforeRow(facesContext, uiData); HtmlRendererUtils.writePrettyLineSeparator(facesContext); renderRowStart(facesContext, writer, uiData, styles, i); List children = component.getChildren(); for (int j = 0, size = component.getChildCount(); j < size; j++) { UIComponent child = (UIComponent) children.get(j); if(child.isRendered()) { encodeColumnChild(facesContext, writer, uiData, child, styles, j); } } renderRowEnd(facesContext, writer, uiData); afterRow(facesContext, uiData); } }
Example 20
Source File: NavbarRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 4 votes |
/** * Render the children of the navbar * @designer.publicmethod */ public void renderChildren(FacesContext context, ResponseWriter w, UIComponent component) throws IOException { // encode component and children // for children of the navbar we need to add a CSS class int count = component.getChildCount(); if(count>0) { List<?> children = component.getChildren(); for (int i=0; i<count; i++) { Object child = children.get(i); boolean addDiv = false; try{ //Determine if the child has a 'navbar-' CSS class assigned already Method method = child.getClass().getMethod("getStyleClass", (Class[])null); // $NON-NLS-1$ Object result = method.invoke(child, (Object[])null); String styleClass = (result != null) ? (String)result : null; if(styleClass != null && styleClass.contains((String)getProperty(PROP_NAVBARITEM_PREFIX))){ //navbar class already assigned, don't do anything addDiv = false; }else{ //no navbar class assigned, wrap the control in a div with class 'navbar-text' addDiv = true; w.startElement("div", component); // $NON-NLS-1$ w.writeAttribute("class", (String)getProperty(PROP_NAVBARITEM_DEFAULTCLASS), null); // $NON-NLS-1$ } } catch (Exception e) { if(BootstrapLogger.BOOTSTRAP.isErrorEnabled()) { BootstrapLogger.BOOTSTRAP.errorp(this, "renderChildren", e, "Exception occured while rendering Navbar children"); // $NON-NLS-1$ $NLX-NavbarRenderer.ExceptionoccuredwhilstrenderingNa-2$ } } UIComponent compChild = (UIComponent)child; FacesUtil.renderComponent(context, compChild); if(addDiv) { //close containing div w.endElement("div"); // $NON-NLS-1$ } } } }