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

The following examples show how to use javax.faces.component.UIComponent#getFacet() . 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
/**
 * This methods generates the HTML code of the current b:breadcrumbs. <code>encodeBegin</code> generates the
 * start of the component. After the, the JSF framework calls <code>encodeChildren()</code> to generate the HTML
 * code between the beginning and the end of the component. For instance, in the case of a panel component the
 * content of the panel is generated by <code>encodeChildren()</code>. After that, <code>encodeEnd()</code> is
 * called to generate the rest of the HTML code.
 *
 * @param context the FacesContext.
 * @param component the current b:breadcrumbs.
 * @throws IOException thrown if something goes wrong when writing the HTML code.
 */
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
	if (!component.isRendered()) {
		return;
	}
	ResponseWriter rw = context.getResponseWriter();

	// End point / current page
	UIComponent end = component.getFacet("end");
	if (end != null) {
		rw.startElement("li", component);
		end.encodeAll(context);
		rw.endElement("li");
	}

	rw.endElement("ol");
	Tooltip.activateTooltips(context, component);
}
 
Example 2
public UIComponent getExtraFacet(AbstractDataView dataView, int index){
    // the "extra" facets are row facets [see AbstractDataView.getRowFacetNames()]
    List<UIComponent> children = TypedUtil.getChildren(dataView);
    if( children.isEmpty() ){
        // Note, children will only be empty in JUnit tests 
        // where UIDataView.buildContents is not called.
        return null;
    }
    UIComponent row = children.get(0);
    if(index==0) {
        UIComponent c = row.getFacet(UIDataView.FACET_EXTRA_N);
        if(c!=null) {
            return c;
        }
    }
    return row.getFacet(UIDataView.FACET_EXTRA_N+index);
}
 
Example 3
public UIComponent getCategoryRowFacet(AbstractDataView dataView, int index){
    // the "categoryRow" facets are row facets [see AbstractDataView.getRowFacetNames()]
    List<UIComponent> children = TypedUtil.getChildren(dataView);
    if( children.isEmpty() ){
        // Note, children will only be empty in JUnit tests 
        // where UIDataView.buildContents is not called.
        return null;
    }
    UIComponent row = children.get(0);
    if(index==0) {
        UIComponent c = row.getFacet(UIDataView.FACET_CATEGORY_N);
        if(c!=null) {
            return c;
        }
    }
    return row.getFacet(UIDataView.FACET_CATEGORY_N+index);
}
 
Example 4
private void generateMultiColumnSearchRow(FacesContext context, DataTable dataTable, ResponseWriter rw)
	throws IOException {
	rw.startElement("tr", dataTable);
	List<UIComponent> columns = dataTable.getChildren();
	for (UIComponent column : columns) {
		if (!column.isRendered()) {
			continue;
		}
		rw.startElement("td", dataTable);
		Object footerStyle = column.getAttributes().get("footerStyle");
		if (footerStyle != null) {
			rw.writeAttribute("style", footerStyle, null);
		}
		Object searchable = column.getAttributes().get("searchable");
		if (searchable == null || ((searchable instanceof Boolean) && ((Boolean) searchable).equals(Boolean.TRUE))
			|| ((searchable instanceof String) && ((String) searchable).equalsIgnoreCase("true"))) {
			Object footerStyleClass = column.getAttributes().get("footerStyleClass");
			if (footerStyleClass != null) {
				rw.writeAttribute("class", "bf-multisearch " + footerStyleClass, null);
			} else {
				rw.writeAttribute("class", "bf-multisearch", null);
			}
			if (column.getFacet("header") != null) {
				UIComponent facet = column.getFacet("header");
				facet.encodeAll(context);
			} else if (column.getAttributes().get("label") != null) {
				rw.writeText(column.getAttributes().get("label"), null);
			}
		}
		rw.endElement("td");
	}
	rw.endElement("tr");
}
 
Example 5
Source Project: BootsFaces-OSP   File: ModalRenderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This methods generates the HTML code of the current b:modal.
 * <code>encodeBegin</code> generates the start of the component. After the,
 * the JSF framework calls <code>encodeChildren()</code> to generate the
 * HTML code between the beginning and the end of the component. For
 * instance, in the case of a panel component the content of the panel is
 * generated by <code>encodeChildren()</code>. After that,
 * <code>encodeEnd()</code> is called to generate the rest of the HTML code.
 *
 * @param context
 *            the FacesContext.
 * @param component
 *            the current b:modal.
 * @throws IOException
 *             thrown if something goes wrong when writing the HTML code.
 */
@Override
public void encodeEnd(FacesContext context, UIComponent component)
		throws IOException {
	if (!component.isRendered()) {
		return;
	}
	ResponseWriter rw = context.getResponseWriter();

	rw.endElement("div"); // modal-body
               
               String cid=component.getClientId(context);

	UIComponent foot = component.getFacet("footer");
	if (foot != null) {
		rw.startElement("div", component); // modal-footer
                       rw.writeAttribute("id", cid+"_footer", "id");
		rw.writeAttribute("class", "modal-footer", "class");
		foot.encodeAll(context);

		rw.endElement("div"); // modal-footer
	}
	rw.endElement("div"); // modal-content
	rw.endElement("div"); // modal-dialog
	rw.endElement("div"); // modal
	initModal(rw, cid);
}
 
Example 6
/**
 * This methods generates the HTML code of the current b:breadcrumbs. <code>encodeBegin</code> generates the
 * start of the component. After the, the JSF framework calls <code>encodeChildren()</code> to generate the HTML
 * code between the beginning and the end of the component. For instance, in the case of a panel component the
 * content of the panel is generated by <code>encodeChildren()</code>. After that, <code>encodeEnd()</code> is
 * called to generate the rest of the HTML code.
 *
 * @param context the FacesContext.
 * @param component the current b:breadcrumbs.
 * @throws IOException thrown if something goes wrong when writing the HTML code.
 */
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
	if (!component.isRendered()) {
		return;
	}
	Breadcrumbs breadcrumbs = (Breadcrumbs) component;
	ResponseWriter rw = context.getResponseWriter();
	String clientId = breadcrumbs.getClientId();

	rw.startElement("ol", breadcrumbs);

	rw.writeAttribute("id", clientId, "id");

	String style = breadcrumbs.getStyle();
	if (null != style && style.length() > 0) {
		rw.writeAttribute("style", style, "style");
	}

	Tooltip.generateTooltip(context, breadcrumbs, rw);

	String styleClass = breadcrumbs.getStyleClass();
	if (null == styleClass) {
		styleClass = "";
	}
	rw.writeAttribute("class", "breadcrumb ".concat(styleClass), "class");

	// Root node
	UIComponent root = component.getFacet("root");
	if (root != null) {
		rw.startElement("li", component);
		root.encodeAll(context);
		rw.endElement("li");
	}
}
 
Example 7
protected void initViewDefinition(FacesContext context, AbstractDataView dataView, ViewDefinition viewDef) {
    List<UIComponent> children = TypedUtil.getChildren(dataView); 
    viewDef.dataView = dataView;
    viewDef.dataModel = dataView.getDataModel();
    viewDef.showItemsFlat = dataView.isShowItemsFlat(); 
    viewDef.detailsOnClient = dataView.isDetailsOnClient() || (Boolean)getProperty(PROP_SHOWHIDEONCLIENT);
    viewDef.collapsibleDetails = dataView.isCollapsibleDetail();
    viewDef.expandedDetailDefault = dataView.isExpandedDetail();
    
    if(viewDef.collapsibleDetails) {
        viewDef.showHideDetailFunctionName = ExtLibUtil.encodeJSFunctionName(dataView.getClientId(context));
    }
    viewDef.summaryColumn = dataView.getSummaryColumn();
    if(!children.isEmpty()) {
        UIComponent row = children.get(0);
        viewDef.summaryFacet = row.getFacet(AbstractDataView.FACET_SUMMARY); // row facet
        viewDef.detailFacet = row.getFacet(AbstractDataView.FACET_DETAIL);// row facet
    }
    viewDef.hasSummary = viewDef.summaryColumn!=null || viewDef.summaryFacet!=null;  
    viewDef.hasDetail = viewDef.detailFacet!=null;
    viewDef.nColumns =   (viewDef.hasCheckBoxColumn?1:0) // CheckBox
                       + 1 // Data - always
                       + (viewDef.collapsibleDetails?1:0); // Collapsible details
    viewDef.viewRowRefresh = dataView.isRowRefresh(context);
    viewDef.rows = dataView.getRows();
    
}
 
Example 8
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 9
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 10
@Override
protected void initViewDefinition(FacesContext context, AbstractDataView _dataView, ViewDefinition viewDef) {
    UIDataView dataView = (UIDataView)_dataView;
    super.initViewDefinition(context, dataView, viewDef);
    List<UIComponent> children = TypedUtil.getChildren(dataView); 
    viewDef.columnTitles = dataView.isColumnTitles();
    viewDef.collapsibleCategory = dataView.isCollapsibleCategory();
    viewDef.collapsibleRows = dataView.isCollapsibleRows();
    viewDef.multiColumnCount = Math.max(1,dataView.getMultiColumnCount());
    viewDef.categoryColumns = dataView.getCategoryColumn();
    viewDef.categoryCount = viewDef.categoryColumns!=null ? viewDef.categoryColumns.size() : 0;
    if(!children.isEmpty()) {
        UIComponent row = children.get(0);
        viewDef.iconFacet = row.getFacet(UIDataView.FACET_ICON);// row facet
    }
    viewDef.hasCategoryRow = viewDef.categoryCount>0 || getCategoryRowFacet(_dataView, 0)!=null;
    viewDef.hasCheckBoxColumn = dataView.isShowCheckbox();
    viewDef.hasHeaderCheckBoxColumn = dataView.isShowHeaderCheckbox();
    if(viewDef.hasCheckBoxColumn) {
        viewDef.checkboxFieldName = dataView.getClientId(context)+":_colcbox"; // $NON-NLS-1$
        viewDef.checkboxFieldNamePrefix = dataView.getClientId(context);
        viewDef.checkboxFieldNameSuffix = ":_colcbox"; // $NON-NLS-1$
    }
    viewDef.iconColumn = dataView.getIconColumn();
    viewDef.hasIconColumn = viewDef.iconColumn!=null || viewDef.iconFacet!=null;
    viewDef.extraColumns = dataView.getExtraColumns();
    viewDef.hasExtraColumns = viewDef.extraColumns!=null && !viewDef.extraColumns.isEmpty();
    viewDef.nColumns =   (viewDef.hasCheckBoxColumn?1:0) // CheckBox 
                       + (viewDef.hasIconColumn?1:0) // Icon
                       + 1 // Data - always
                       + (viewDef.hasExtraColumns?(viewDef.extraColumns.size()):0) // Extra columns
                       + (viewDef.collapsibleDetails?1:0); // Collapsible details
    
    // Apply different constraints
    
    // In case of multiple columns
    if(viewDef.multiColumnCount>1) {
        // Expand/collapse details must do a full refresh as we cannot refresh a row cell
        viewDef.viewRowRefresh = false;
    }
    
    viewDef.isInfiniteScroll = getInfiniteScroll(dataView.getInfiniteScroll(), context);
}
 
Example 11
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 12
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");
}