/** * Copyright 2011 Intuit Inc. All Rights Reserved */ package com.intuit.tank.util; /* * #%L * JSF Support Beans * %% * Copyright (C) 2011 - 2015 Intuit Inc. * %% * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * #L% */ import java.util.Iterator; import javax.faces.component.UIComponent; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; /** * JSFUtil * * @author dangleton * */ public class JSFUtil { public static String getClientId(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); UIViewRoot root = context.getViewRoot(); UIComponent c = findComponent(root, componentId); return c != null ? c.getClientId(context) : null; } /** * Finds component with the given id */ private static UIComponent findComponent(UIComponent c, String id) { if (id.equals(c.getId())) { return c; } Iterator<UIComponent> kids = c.getFacetsAndChildren(); while (kids.hasNext()) { UIComponent found = findComponent(kids.next(), id); if (found != null) { return found; } } return null; } }