Java Code Examples for javax.faces.component.UIComponent#encodeBegin()

The following examples show how to use javax.faces.component.UIComponent#encodeBegin() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Helper method for recursively encoding a component.
 * 
 * @param context
 *            the given FacesContext
 * @param component
 *            the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    component.encodeBegin(context);

    if (component.getRendersChildren())
    {
        component.encodeChildren(context);
    } else
    {
        Iterator iter = component.getChildren().iterator();

        while (iter.hasNext())
        {
            UIComponent child = (UIComponent) iter.next();
            encodeRecursive(context, child);
        }
    }
    component.encodeEnd(context);
}
 
Example 2
protected void encodeRecursive(FacesContext context, UIComponent component) throws IOException {

        if (component.isRendered() == false) {
            return;
        }

        component.encodeBegin(context);
        if (component.getRendersChildren()) {
            component.encodeChildren(context);
        } else {
            Iterator kids = component.getChildren().iterator();
            while (kids.hasNext()) {
                UIComponent kid = (UIComponent) kids.next();
                encodeRecursive(context, kid);
            }
        }
        component.encodeEnd(context);

    }
 
Example 3
/**
 * Helper method for recursively encoding a component.
 * 
 * @param context
 *            the given FacesContext
 * @param component
 *            the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    component.encodeBegin(context);

    if (component.getRendersChildren())
    {
        component.encodeChildren(context);
    } else
    {
        Iterator iter = component.getChildren().iterator();

        while (iter.hasNext())
        {
            UIComponent child = (UIComponent) iter.next();
            encodeRecursive(context, child);
        }
    }
    component.encodeEnd(context);
}
 
Example 4
/**
 * Helper method for recursively encoding a component.
 * 
 * @param context
 *            the given FacesContext
 * @param component
 *            the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    component.encodeBegin(context);

    if (component.getRendersChildren())
    {
        component.encodeChildren(context);
    } else
    {
        Iterator iter = component.getChildren().iterator();

        while (iter.hasNext())
        {
            UIComponent child = (UIComponent) iter.next();
            encodeRecursive(context, child);
        }
    }
    component.encodeEnd(context);
}
 
Example 5
public void encodeChildren(FacesContext context, UIComponent component)
	throws IOException
{
  if (!component.isRendered())
  {
    return;
  }

  Iterator children = component.getChildren().iterator();
  while (children.hasNext()) {
    UIComponent child = (UIComponent) children.next();
    if(!((child instanceof org.sakaiproject.tool.messageforums.jsf.BarLinkComponent)||
        (child instanceof HtmlOutputText)))
    {
      child.encodeBegin(context);
      child.encodeChildren(context);
      child.encodeEnd(context);
    }
  }
}
 
Example 6
/**
 * Helper method for recursively encoding a component.
 * 
 * @param context
 *            the given FacesContext
 * @param component
 *            the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    component.encodeBegin(context);

    if (component.getRendersChildren())
    {
        component.encodeChildren(context);
    } else
    {
        Iterator iter = component.getChildren().iterator();

        while (iter.hasNext())
        {
            UIComponent child = (UIComponent) iter.next();
            encodeRecursive(context, child);
        }
    }
    component.encodeEnd(context);
}
 
Example 7
/**
 * Helper method for recursively encoding a component.
 * 
 * @param context
 *            the given FacesContext
 * @param component
 *            the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    component.encodeBegin(context);

    if (component.getRendersChildren())
    {
        component.encodeChildren(context);
    } else
    {
        Iterator iter = component.getChildren().iterator();

        while (iter.hasNext())
        {
            UIComponent child = (UIComponent) iter.next();
            encodeRecursive(context, child);
        }
    }
    component.encodeEnd(context);
}
 
Example 8
/**
 * Helper method for recursively encoding a component.
 * 
 * @param context
 *            the given FacesContext
 * @param component
 *            the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    component.encodeBegin(context);

    if (component.getRendersChildren())
    {
        component.encodeChildren(context);
    } else
    {
        Iterator iter = component.getChildren().iterator();

        while (iter.hasNext())
        {
            UIComponent child = (UIComponent) iter.next();
            encodeRecursive(context, child);
        }
    }
    component.encodeEnd(context);
}
 
Example 9
/**
 * Helper method for recursively encoding a component.
 * @param context the given FacesContext
 * @param component the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context,
  UIComponent component) throws IOException
{
  if (!component.isRendered())
  {
    return;
  }

  component.encodeBegin(context);

  if (component.getRendersChildren())
  {
    component.encodeChildren(context);
  }
  else
  {
    Iterator iter = component.getChildren().iterator();

    while (iter.hasNext())
    {
      UIComponent child = (UIComponent) iter.next();
      encodeRecursive(context, child);
    }
  }
  component.encodeEnd(context);
}
 
Example 10
public void encodeChildren(FacesContext context, UIComponent component)
	throws IOException 
{
  if (context == null || component == null) 
  {
    throw new NullPointerException();
  }

  String test = (String) component.getAttributes().get("test");
  if(test!=null)
    test = test.trim();
  
  if((test==null) || (test.equals("")))
  {
    Iterator kids = component.getChildren().iterator();
    
    while (kids.hasNext()) 
    {
      UIComponent kid = (UIComponent) kids.next();
      kid.encodeBegin(context);
      if (kid.getRendersChildren()) {
        kid.encodeChildren(context);
      }
      kid.encodeEnd(context);
    }
  }
  else
  {
  }
}
 
Example 11
public void encodeChildren(FacesContext context, UIComponent component)
	throws IOException 
{
  if (context == null || component == null) 
  {
    throw new NullPointerException();
  }

  String test = (String) component.getAttributes().get("test");
  if(test!=null)
    test = test.trim();
  
  if((test!=null) && (!test.equals("")))
  {
    Iterator kids = component.getChildren().iterator();
    
    while (kids.hasNext()) 
    {
      UIComponent kid = (UIComponent) kids.next();
      kid.encodeBegin(context);
      if (kid.getRendersChildren()) {
        kid.encodeChildren(context);
      }
      kid.encodeEnd(context);
    }
  }
  else
  {
  }
}
 
Example 12
Source Project: BootsFaces-OSP   File: R.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Renders the Child of a Component
 * 
 * @param fc
 * @param child
 * @throws IOException
 */
public static void renderChild(FacesContext fc, UIComponent child) throws IOException {
	if (!child.isRendered()) {
		return;
	}

	child.encodeBegin(fc);

	if (child.getRendersChildren()) {
		child.encodeChildren(fc);
	} else {
		renderChildren(fc, child);
	}
	child.encodeEnd(fc);
}
 
Example 13
/**
 * Helper method for recursively encoding a component.
 * @param context the given FacesContext
 * @param component the UIComponent to render
 * @throws IOException
 */
public static void encodeRecursive(FacesContext context,
  UIComponent component) throws IOException
{
  if (!component.isRendered())
  {
    return;
  }

  component.encodeBegin(context);

  if (component.getRendersChildren())
  {
    component.encodeChildren(context);
  }
  else
  {
    Iterator iter = component.getChildren().iterator();

    while (iter.hasNext())
    {
      UIComponent child = (UIComponent) iter.next();
      encodeRecursive(context, child);
    }
  }
  component.encodeEnd(context);
}
 
Example 14
public void encodeChildren(FacesContext context, UIComponent component)
	throws IOException 
{
  if (context == null || component == null) 
  {
    throw new NullPointerException();
  }

  String test = (String) component.getAttributes().get("test");
  if(test!=null)
    test = test.trim();
  
  if((test==null) || (test.equals("")))
  {
    Iterator kids = component.getChildren().iterator();
    
    while (kids.hasNext()) 
    {
      UIComponent kid = (UIComponent) kids.next();
      kid.encodeBegin(context);
      if (kid.getRendersChildren()) {
        kid.encodeChildren(context);
      }
      kid.encodeEnd(context);
    }
  }
  else
  {
  }
}
 
Example 15
public void encodeChildren(FacesContext context, UIComponent component)
	throws IOException 
{
  if (context == null || component == null) 
  {
    throw new NullPointerException();
  }

  String test = (String) component.getAttributes().get("test");
  if(test!=null)
    test = test.trim();
  
  if((test!=null) && (!test.equals("")))
  {
    Iterator kids = component.getChildren().iterator();
    
    while (kids.hasNext()) 
    {
      UIComponent kid = (UIComponent) kids.next();
      kid.encodeBegin(context);
      if (kid.getRendersChildren()) {
        kid.encodeChildren(context);
      }
      kid.encodeEnd(context);
    }
  }
  else
  {
  }
}
 
Example 16
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {

  if (!component.isRendered()) {
    return;
  }

  ResponseWriter writer = context.getResponseWriter();
  String jsfId = (String) RendererUtil.getAttribute(context, component, "id");
  String id = jsfId;

  if (component.getId() != null &&
      !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
  {
    id = component.getClientId(context);
  }

  String title = (String) RendererUtil.getAttribute(context, component, "title");
  Object tmpFoldStr = RendererUtil.getAttribute(context, component, "hideByDefault");
  boolean foldDiv = tmpFoldStr != null && "true".equals(tmpFoldStr);
  String foldImage = foldDiv ? FOLD_IMG_HIDE : FOLD_IMG_SHOW;
  writer.write("<" + BARTAG + " class=\"" + BARSTYLE + "\">");
  writer.write("<table style=\"width: 100%;\" class=\"discTria\" cellpadding=\"0\" cellspacing=\"0\" >");
  writer.write("<tr><td  class=\"discTria\" onclick=\"javascript:showHideDivBlock('" + id +
      "', '" +  RESOURCE_PATH + "');\">" );
  writer.write("  <img id=\"" + id + "__img_hide_division_" + "\" alt=\"" +
      title + "\"");
  writer.write("    src=\""   + foldImage + "\" style=\"" + CURSOR + "\" />");
  writer.write("<h4>"  + title + "</h4>");
  writer.write("</td><td class=\"discTria\">&nbsp;</td>");
  writer.write("<td  class=\"itemAction\" style=\"text-align: right;\">");
  List childrenList = component.getChildren();
  for(int i=0; i<childrenList.size(); i++)
  	{
	UIComponent thisComponent = (UIComponent)childrenList.get(i);
    if(thisComponent instanceof org.sakaiproject.tool.messageforums.jsf.BarLinkComponent
       ||thisComponent instanceof HtmlOutputText)
    {
      thisComponent.encodeBegin(context);
      thisComponent.encodeChildren(context);
      thisComponent.encodeEnd(context);
    }
  }
  writer.write("</td></tr></table>");
  writer.write("</"+ BARTAG + ">");
  if(foldDiv) {
    writer.write("<div style=\"display:none\" " +
        " id=\"" + id + "__hide_division_" + "\">");
          } else {
              writer.write("<div style=\"display:block\" " +
                      " id=\"" + id + "__hide_division_" + "\">");
          }
}
 
Example 17
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
	HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();

	ResponseWriter writer = context.getResponseWriter();

	if (!renderAsFragment(context))
	{
		// The stylesheets and javascripts to include are really the portal's responsibility
		// so get them from the portal through the request attributes.
		// Any tool-specific stylesheets need to be placed after Sakai's base CSS (so that
		// tool-specific overrides can take place), but before the installation's skin CSS
		// (so that the tool can be skinned).
		String headBaseCss = (String)req.getAttribute("sakai.html.head.css.base");
		if (headBaseCss == null || headBaseCss.length() == 0) {
			// include default stylesheet
			headBaseCss = "<link href=\"/jsf-resource/css/sakai.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
		}
		String toolCssHref = (String) RendererUtil.getAttribute(context, component, "toolCssHref");
		if (toolCssHref != null) {
			toolCssHref = "<link href=\"" + toolCssHref + "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
		}			
		String headSkinCss = (String)req.getAttribute("sakai.html.head.css.skin");
		String headJs = (String)req.getAttribute("sakai.html.head.js");
		String bodyonload = (String) req.getAttribute("sakai.html.body.onload");

           // SAK-23099 - Set the lang tag to the current user's locale.
           Locale locale = LocaleUtil.getLocale(context);

           String lang = locale.getLanguage();

           if(lang == null || lang.equals("")) lang = "en";

           String countryCode = locale.getCountry();
           if(countryCode != null && countryCode.length() > 0) {
               lang += "-" + countryCode;
           }

		writer.write("<!DOCTYPE html>\n");
		writer.write("<html lang=\"" + lang + "\" dir=\"" + LocaleUtil.getOrientation(locale) + "\">\n");
		writer.write("<head>\n");
		String title = (String) RendererUtil.getAttribute(context, component, "title");
		if (title != null)
		{
			writer.write("<title>");
			writer.write(title);
			writer.write("</title>\n");
		}

		writer.write(headBaseCss);
		if (toolCssHref != null) writer.write(toolCssHref);
		if (headSkinCss != null) writer.write(headSkinCss);
		if (headJs != null) writer.write(headJs);

		// Useful to include something in the head
		UIComponent headFacet = component.getFacet("head");
		if (headFacet!=null) { 
			headFacet.encodeBegin(context);
			headFacet.encodeChildren(context);
			headFacet.encodeEnd(context);
		}
		
		writer.write("</head>\n");

		writer.write("<body");

		if (bodyonload != null && bodyonload.length() > 0)
		{
			writer.write(" onload=\"");
			writer.write(bodyonload);
			writer.write("\"");
		}
		writer.write(">\n");

	}

	writer.write("<div class=\"portletBody\">\n");
}
 
Example 18
/**
 * Core workhouse method of the dynamic renderers.
 * @param context FacesContext
 * @param component UIComponent
 * @throws IOException
 */
protected void renderData(FacesContext context, UIComponent component) throws
  IOException
{
  boolean multiColumn = component instanceof MultiColumnComponent;
  ResponseWriter writer = context.getResponseWriter();

  UIData data = (UIData) component;

  int first = data.getFirst();
  int rows = data.getRows();

  for (int i = first, n = 0; n < rows; i++, n++)
  {
    data.setRowIndex(i);
    if (!data.isRowAvailable())
    {
      break;
    }
    ////////////////////////////////////
    //  TR
    ////////////////////////////////////
    writer.startElement("tr", data);

    Iterator iter = data.getChildren().iterator();
    while (iter.hasNext())
    {
      UIComponent child = (UIComponent) iter.next();

      if (child instanceof UIColumn)
      {
        writer.startElement("td", child);
        writer.write("debug UIColumn");
        RendererUtil.encodeRecursive(context, child);
        writer.endElement("td");
      }
      else if (child instanceof UIData)
      {
        writer.write("debug UIData");
        child.encodeBegin(context);
        child.encodeChildren(context);
        child.encodeEnd(context);
      }
    }
    ////////////////////////////////////
    //  /TR
    ////////////////////////////////////
    writer.endElement("tr");
    writer.write("\n");
  }
}
 
Example 19
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {

  if (!component.isRendered()) {
    return;
  }

  ResponseWriter writer = context.getResponseWriter();
  String jsfId = (String) RendererUtil.getAttribute(context, component, "id");
  String id = jsfId;

  if (component.getId() != null &&
      !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
  {
    id = component.getClientId(context);
  }

  String title = (String) RendererUtil.getAttribute(context, component, "title");
  Object tmpFoldStr = RendererUtil.getAttribute(context, component, "hideByDefault");
  boolean foldDiv = tmpFoldStr != null && "true".equals(tmpFoldStr);
  String foldImage = foldDiv ? FOLD_IMG_HIDE : FOLD_IMG_SHOW;
  writer.write("<" + BARTAG + " class=\"" + BARSTYLE + "\">");
  writer.write("<table style=\"width: 100%;\" class=\"discTria\" cellpadding=\"0\" cellspacing=\"0\" >");
  writer.write("<tr><td  class=\"discTria\" onclick=\"javascript:showHideDivBlock('" + id +
      "', '" +  RESOURCE_PATH + "');\">" );
  writer.write("  <img id=\"" + id + "__img_hide_division_" + "\" alt=\"" +
      title + "\"");
  writer.write("    src=\""   + foldImage + "\" style=\"" + CURSOR + "\" />");
  writer.write("<h4>"  + title + "</h4>");
  writer.write("</td><td class=\"discTria\">&nbsp;</td>");
  writer.write("<td  class=\"itemAction\" style=\"text-align: right;\">");
  List childrenList = component.getChildren();
  for(int i=0; i<childrenList.size(); i++)
  	{
	UIComponent thisComponent = (UIComponent)childrenList.get(i);
    if(thisComponent instanceof org.sakaiproject.tool.messageforums.jsf.BarLinkComponent
       ||thisComponent instanceof HtmlOutputText)
    {
      thisComponent.encodeBegin(context);
      thisComponent.encodeChildren(context);
      thisComponent.encodeEnd(context);
    }
  }
  writer.write("</td></tr></table>");
  writer.write("</"+ BARTAG + ">");
  if(foldDiv) {
    writer.write("<div style=\"display:none\" " +
        " id=\"" + id + "__hide_division_" + "\">");
          } else {
              writer.write("<div style=\"display:block\" " +
                      " id=\"" + id + "__hide_division_" + "\">");
          }
}
 
Example 20
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
	HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();

	ResponseWriter writer = context.getResponseWriter();

	if (!renderAsFragment(context))
	{
		// The stylesheets and javascripts to include are really the portal's responsibility
		// so get them from the portal through the request attributes.
		// Any tool-specific stylesheets need to be placed after Sakai's base CSS (so that
		// tool-specific overrides can take place), but before the installation's skin CSS
		// (so that the tool can be skinned).
		String headBaseCss = (String)req.getAttribute("sakai.html.head.css.base");
		if (headBaseCss == null || headBaseCss.length() == 0) {
			// include default stylesheet
			headBaseCss = "<link href=\"/jsf-resource/css/sakai.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
		}
		String toolCssHref = (String) RendererUtil.getAttribute(context, component, "toolCssHref");
		if (toolCssHref != null) {
			toolCssHref = "<link href=\"" + toolCssHref + "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
		}			
		String headSkinCss = (String)req.getAttribute("sakai.html.head.css.skin");
		String headJs = (String)req.getAttribute("sakai.html.head.js");
		String bodyonload = (String) req.getAttribute("sakai.html.body.onload");

           // SAK-23099 - Set the lang tag to the current user's locale.
           Locale locale = LocaleUtil.getLocale(context);

           String lang = locale.getLanguage();

           if(lang == null || lang.equals("")) lang = "en";

           String countryCode = locale.getCountry();
           if(countryCode != null && countryCode.length() > 0) {
               lang += "-" + countryCode;
           }

		writer.write("<!DOCTYPE html>\n");
		writer.write("<html lang=\"" + lang + "\" dir=\"" + LocaleUtil.getOrientation(locale) + "\">\n");
		writer.write("<head>\n");
		String title = (String) RendererUtil.getAttribute(context, component, "title");
		if (title != null)
		{
			writer.write("<title>");
			writer.write(title);
			writer.write("</title>\n");
		}

		writer.write(headBaseCss);
		if (toolCssHref != null) writer.write(toolCssHref);
		if (headSkinCss != null) writer.write(headSkinCss);
		if (headJs != null) writer.write(headJs);

		// Useful to include something in the head
		UIComponent headFacet = component.getFacet("head");
		if (headFacet!=null) { 
			headFacet.encodeBegin(context);
			headFacet.encodeChildren(context);
			headFacet.encodeEnd(context);
		}
		
		writer.write("</head>\n");

		writer.write("<body");

		if (bodyonload != null && bodyonload.length() > 0)
		{
			writer.write(" onload=\"");
			writer.write(bodyonload);
			writer.write("\"");
		}
		writer.write(">\n");

	}

	writer.write("<div class=\"portletBody\">\n");
}