code: 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();
      }
docs: 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