get Submitted Value of Component in Java

public static UIComponent findComponent(UIComponent topComponent, String compId) { 
            if (compId==null) 
                    throw new NullPointerException("Component identifier cannot be null"); 

            if (compId.equals(topComponent.getId())) 
                    return topComponent; 

            if (topComponent.getChildCount()>0) { 
                    List<UIComponent> childComponents= topComponent.getChildren(); 

                    for (UIComponent currChildComponent : childComponents) { 
                            UIComponent foundComponent=findComponent(currChildComponent, compId); 
                            if (foundComponent!=null) 
                                    return foundComponent; 
            return null; 
    public static Object getSubmittedValue(String compId) {
    	UIComponent c = findComponent(FacesContext.getCurrentInstance().getViewRoot(), compId);
    	// value submitted from the browser 
    	Object o = ((UIInput) c).getSubmittedValue(); 
    	if( null == o ){ 
           // else not yet submitted
           o = ((UIInput) c).getValue();
    	return o;

to use this snippet, you need both methods, but from your Java code call the method getSubmittedValue as parameter the id of the Component. It returns an Object who should be cast to the right class

F van der Linden
December 2, 2011 10:45 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

No comments yetLogin first to comment...