Created
February 17, 2012 18:31
-
-
Save bleathem/1854742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package co.cfly.jsf.renderkit; | |
| import java.io.IOException; | |
| import javax.faces.application.ResourceDependencies; | |
| import javax.faces.application.ResourceDependency; | |
| import javax.faces.component.EditableValueHolder; | |
| import javax.faces.component.UIComponent; | |
| import javax.faces.component.UIMessage; | |
| import javax.faces.context.FacesContext; | |
| import co.cfly.jsf.component.AbstractDecorate; | |
| import co.cfly.jsf.component.AbstractDecorateContainer; | |
| import org.richfaces.component.UIRichMessage; | |
| import org.richfaces.renderkit.RendererBase; | |
| /** | |
| * @author Cody Lerum | |
| */ | |
| @ResourceDependencies({@ResourceDependency(name = "message.reslib", library = "org.richfaces", target = ""), @ResourceDependency(name = "msg.ecss", library = "org.richfaces", target = "")}) | |
| public class DecorateRendererBase extends RendererBase { | |
| public AbstractDecorate getDecorate(UIComponent component) { | |
| return (AbstractDecorate) component; | |
| } | |
| public UIMessage getMessage(AbstractDecorate component) { | |
| return (UIMessage) component.getMessage(); | |
| } | |
| protected static AbstractDecorateContainer getDecorateContainer(UIComponent component) { | |
| UIComponent parent = component.getParent(); | |
| while (parent != null && parent.getRendererType() != null) { | |
| if (parent instanceof AbstractDecorateContainer) { | |
| return (AbstractDecorateContainer) parent; | |
| } else { | |
| parent = parent.getParent(); | |
| } | |
| } | |
| return null; | |
| } | |
| public boolean getRequired(UIComponent valueComponent) { | |
| return isInput(valueComponent) && ((EditableValueHolder) valueComponent).isRequired(); | |
| } | |
| public boolean isInput(UIComponent valueComponent) { | |
| return valueComponent instanceof EditableValueHolder; | |
| } | |
| public UIComponent getValueComponent(FacesContext facesContext, UIComponent component) { | |
| int editableValueCount = 0; | |
| UIComponent editableValueComponent = null; | |
| for (UIComponent c : component.getChildren()) { | |
| if (c instanceof EditableValueHolder) { | |
| editableValueComponent = c; | |
| editableValueCount++; | |
| } | |
| } | |
| if (component.getChildCount() == 0) { | |
| throw new RuntimeException("Must contain at least 1 child component."); | |
| } else if (editableValueCount == 1) { | |
| return editableValueComponent; | |
| } else if (editableValueCount > 1) { | |
| throw new RuntimeException("Can't have more than 1 EditableValueHolder child"); | |
| } else { | |
| return component.getChildren().get(0); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment