public static String encodeComponent(final FacesContext context,
                                         final UIComponent component) throws IOException {
        final FacesContextStringResolverWrapper resolver = new FacesContextStringResolverWrapper(context);
        component.encodeAll(resolver);
        return resolver.getStringWriter().toString().replace("\n", "").trim();
    }
public static String encodeComponent ( final FacesContext context , final UIComponent component ) throws IOException { final FacesContextStringResolverWrapper resolver = new FacesContextStringResolverWrapper ( context ) ; component . encodeAll ( resolver ) ; return resolver . getStringWriter ( ) . toString ( ) . replace ( "\n" , "" ) . trim ( ) ; }
Encodes complete component by calling {@link UIComponent#encodeAll(FacesContext)}.

@param component component
@param context   {@link FacesContext}
@return the rendered string.
@throws IOException thrown by writer