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

The following examples show how to use javax.faces.component.UIComponent#getAttributes() . 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 check out the related API usage on the sidebar.
Example 1
Source File: Tooltip.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public static void generateTooltip(FacesContext context, UIComponent component, ResponseWriter rw)
		throws IOException {
	Map<String, Object> attrs = component.getAttributes();
	String tooltip = (String) attrs.get("tooltip");
	if (null != tooltip) {
		//set default values first, if not present
		String position = (String) attrs.get("tooltipPosition");
		if (null == position) // compatibility for the HTML-style using "-" characters instead of camelcase
			position = (String) attrs.get("tooltip-position");
		if (null == position)
			position = "auto";
		String container = (String) attrs.get("tooltipContainer");
		if (null == container) // compatibility for the HTML-style using "-" characters instead of camelcase
			container = (String) attrs.get("tooltip-container");
		if (null == container || container.length() == 0)
			container = "body";
		verifyAndWriteTooltip(context, rw, tooltip, position, container);
	}
}
 
Example 2
Source File: Tooltip.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public static void activateTooltips(FacesContext context, UIComponent component, String id) throws IOException {
	Map<String, Object> attributes = component.getAttributes();
	if (attributes.get("tooltip") != null) {
		id = id.replace(":", "\\\\:"); // we need to escape the id for
										// jQuery
		String delayOptions = generateDelayAttributes(attributes);
		String options = "";
		if (null != delayOptions)
			options = "'delay':" + delayOptions + ",";
		if (options.length() > 0)
			options = "{" + options.substring(0, options.length() - 1) + "}";

		String js = "$(function () {\n" + "$('#" + id + "').tooltip(" + options + ")\n" + "});\n";
		//destroy existing tooltips to prevent ajax bugs in some browsers and prevent memory leaks (see #323 and #220)
		js+="$('.tooltip').tooltip('destroy'); ";
		context.getResponseWriter().write("<script type='text/javascript'>" + js + "</script>");
	}
}
 
Example 3
Source File: PaddingConverter.p.vm.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
private int getPadding(FacesContext context, UIComponent component) {
    if (component.getAttributes() != null && component.getAttributes().containsKey(PADDING_PARAMETER)) {
        return Integer.valueOf((String) component.getAttributes().get(PADDING_PARAMETER));
    } else {
        String message = messageSource.getMessage(PADDING_ID, null, context.getViewRoot().getLocale());
        throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
    }
}
 
Example 4
Source File: JSEventHandlerRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the standard Javascript event handlers.
 * @param rw The response writer
 * @param component the current component
 * @throws IOException thrown if something goes wrong when writing the HTML code
 */
public static void generateJSEventHandlers(ResponseWriter rw, UIComponent component) throws IOException {
	Map<String, Object> attributes = component.getAttributes();
	String[] eventHandlers = {"onclick", "onblur", "onmouseover"};
       for (String event:eventHandlers) {
       	String handler = A.asString(attributes.get(event));
       	if (null != handler) {
       		rw.writeAttribute(event, handler, event);
       	}
       }
}
 
Example 5
Source File: DateTimeConverter.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
public static String getPattern(UIComponent component) {
	Map<String, Object> properties = component.getAttributes();
	String pattern = (String) properties.get("dateFormat");
	if (null == pattern) {
		pattern = (String) properties.get("pattern");
	}
	if (null == pattern) {
		pattern = "MM/dd/yyyy";
	}
	return pattern;
}
 
Example 6
Source File: TimerBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
* <p>Method Generator: org.sakaiproject.tool.assessment.devtools.RenderMaker</p>
*
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

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

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

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

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

      writer.write("\n");
      writer.write("\n<script language=\"javascript\">");
      writer.write("\n// Timer Bar - Version 1.0");
      writer.write("\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
      writer.write("\n  var loadedcolor='gray' ;            // PROGRESS BAR COLOR");


      writer.write("\n  var unloadedcolor='green';         // COLOR OF UNLOADED AREA");

      writer.write("\n  var bordercolor='navy';            // COLOR OF THE BORDER");
      writer.write("\n  var barheight = " + attrMap.get("height") + "; // HEIGHT OF PROGRESS BAR IN PIXELS");
      writer.write("\n  var barwidth = " + attrMap.get("width") + "; // WIDTH OF THE BAR IN PIXELS");
      writer.write("\n  var waitTime = " + attrMap.get("wait") + "; // NUMBER OF SECONDS FOR PROGRESSBAR");
      writer.write("\n  var loaded = " + attrMap.get("elapsed") + "*10; // TENTHS OF A SECOND ELAPSED");
      writer.write("\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
      writer.write("\n");
      writer.write("\n  var action = function()");
      writer.write("\n {");
      writer.write("\n   " + attrMap.get("expireScript") + ";");
      writer.write("\n  alert(\""  + attrMap.get("expireMessage") + "\");");
      writer.write("\n }");
      writer.write("\n");
      writer.write("\n</script>");
      writer.write("\n<script language=\"javascript\" src=\"" +
           "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
      writer.write("\n");

     if (clientId != null)
       {
       writer.endElement("span");
     }
 }
 
Example 7
Source File: TimerBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
* <p>Method Generator: org.sakaiproject.tool.assessment.devtools.RenderMaker</p>
*
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

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

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

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

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

      writer.write("\n");
      writer.write("\n<script language=\"javascript\">");
      writer.write("\n// Timer Bar - Version 1.0");
      writer.write("\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
      writer.write("\n  var loadedcolor='gray' ;            // PROGRESS BAR COLOR");


      writer.write("\n  var unloadedcolor='green';         // COLOR OF UNLOADED AREA");

      writer.write("\n  var bordercolor='navy';            // COLOR OF THE BORDER");
      writer.write("\n  var barheight = " + attrMap.get("height") + "; // HEIGHT OF PROGRESS BAR IN PIXELS");
      writer.write("\n  var barwidth = " + attrMap.get("width") + "; // WIDTH OF THE BAR IN PIXELS");
      writer.write("\n  var waitTime = " + attrMap.get("wait") + "; // NUMBER OF SECONDS FOR PROGRESSBAR");
      writer.write("\n  var loaded = " + attrMap.get("elapsed") + "*10; // TENTHS OF A SECOND ELAPSED");
      writer.write("\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
      writer.write("\n");
      writer.write("\n  var action = function()");
      writer.write("\n {");
      writer.write("\n   " + attrMap.get("expireScript") + ";");
      writer.write("\n  alert(\""  + attrMap.get("expireMessage") + "\");");
      writer.write("\n }");
      writer.write("\n");
      writer.write("\n</script>");
      writer.write("\n<script language=\"javascript\" src=\"" +
           "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
      writer.write("\n");

     if (clientId != null)
       {
       writer.endElement("span");
     }
 }
 
Example 8
Source File: ProgressBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

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

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

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

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

     writer.write("\n");
     writer.write("\n<script language=\"javascript\">");
     writer.write("\n// Timer Bar - Version 1.0");
     writer.write(
         "\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
     writer.write(
         "\n  var loadedcolor='blue' ;            // PROGRESS BAR COLOR");
     writer.write(
         "\n  var unloadedcolor='white';         // COLOR OF UNLOADED AREA");
     writer.write(
         "\n  var bordercolor='white';            // COLOR OF THE BORDER");
     writer.write("\n  var barheight = 45; // HEIGHT OF PROGRESS BAR IN PIXELS");
     writer.write("\n  var barwidth = 300; // WIDTH OF THE BAR IN PIXELS");
     writer.write("\n  var waitTime = " + attrMap.get("wait") +
                  "; // NUMBER OF SECONDS FOR PROGRESSBAR");
     writer.write("\n  var loaded = 0; // TENTHS OF A SECOND ELAPSED");
     writer.write(
         "\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
     writer.write("\n");
     writer.write("\n  var action = function()");
     writer.write("\n {");
     writer.write("\n }");
     writer.write("\n</script>");
     writer.write("\n<script language=\"javascript\" src=\"" +
          "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
     writer.write("\n");

     if (clientId != null) {
       writer.endElement("span");
     }
 }
 
Example 9
Source File: R.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
/**
 * Encodes a Column
 * 
 * @param rw
 * @param c
 * @param span
 * @param cxs
 * @param csm
 * @param clg
 * @param offset
 * @param oxs
 * @param osm
 * @param olg
 * @param style
 * @param sclass
 * @throws IOException
 */
public static final void encodeColumn(ResponseWriter rw, UIComponent c, int span, int cxs, int csm, int clg,
		int offset, int oxs, int osm, int olg, String style, String sclass) throws IOException {

	rw.startElement("div", c);
	Map<String, Object> componentAttrs = new HashMap<String, Object>();

	if (c != null) {
		rw.writeAttribute("id", c.getClientId(), "id");
		Tooltip.generateTooltip(FacesContext.getCurrentInstance(), c, rw);
		componentAttrs = c.getAttributes();
	}

	StringBuilder sb = new StringBuilder();
	if (span > 0 || offset > 0) {
		if (span > 0) {
			sb.append(COLMD).append(span);
		}
		if (offset > 0) {
			if (span > 0) {
				sb.append(" ");
			}
			sb.append(OFFSET + offset);
		}
	}

	if (cxs > 0) {
		sb.append(" col-xs-").append(cxs);
	}
	if (componentAttrs.get("col-xs") != null && cxs == 0) {
		sb.append(" hidden-xs");
	}

	if (csm > 0) {
		sb.append(" col-sm-").append(csm);
	}
	if (componentAttrs.get("col-sm") != null && csm == 0) {
		sb.append(" hidden-sm");
	}

	if (clg > 0) {
		sb.append(" col-lg-").append(clg);
	}
	if (componentAttrs.get("col-lg") != null && clg == 0) {
		sb.append(" hidden-lg");
	}

	if (oxs > 0) {
		sb.append(" col-xs-offset-").append(oxs);
	}
	if (osm > 0) {
		sb.append(" col-sm-offset-").append(osm);
	}
	if (olg > 0) {
		sb.append(" col-lg-offset-").append(olg);
	}

	if (sclass != null) {
		sb.append(" ").append(sclass);
	}
	rw.writeAttribute("class", sb.toString().trim(), "class");
	if (style != null) {
		rw.writeAttribute("style", style, "style");
	}

	if (null != c) {
		Tooltip.activateTooltips(FacesContext.getCurrentInstance(), c);
	}
}
 
Example 10
Source File: TimerBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
* <p>Method Generator: org.sakaiproject.tool.assessment.devtools.RenderMaker</p>
*
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

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

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

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

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

      writer.write("\n");
      writer.write("\n<script language=\"javascript\">");
      writer.write("\n// Timer Bar - Version 1.0");
      writer.write("\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
      writer.write("\n  var loadedcolor='gray' ;            // PROGRESS BAR COLOR");


      writer.write("\n  var unloadedcolor='green';         // COLOR OF UNLOADED AREA");

      writer.write("\n  var bordercolor='navy';            // COLOR OF THE BORDER");
      writer.write("\n  var barheight = " + attrMap.get("height") + "; // HEIGHT OF PROGRESS BAR IN PIXELS");
      writer.write("\n  var barwidth = " + attrMap.get("width") + "; // WIDTH OF THE BAR IN PIXELS");
      writer.write("\n  var waitTime = " + attrMap.get("wait") + "; // NUMBER OF SECONDS FOR PROGRESSBAR");
      writer.write("\n  var loaded = " + attrMap.get("elapsed") + "*10; // TENTHS OF A SECOND ELAPSED");
      writer.write("\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
      writer.write("\n");
      writer.write("\n  var action = function()");
      writer.write("\n {");
      writer.write("\n   " + attrMap.get("expireScript") + ";");
      writer.write("\n  alert(\""  + attrMap.get("expireMessage") + "\");");
      writer.write("\n }");
      writer.write("\n");
      writer.write("\n</script>");
      writer.write("\n<script language=\"javascript\" src=\"" +
           "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
      writer.write("\n");

     if (clientId != null)
       {
       writer.endElement("span");
     }
 }
 
Example 11
Source File: TimerBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
* <p>Method Generator: org.sakaiproject.tool.assessment.devtools.RenderMaker</p>
*
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

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

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

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

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

      writer.write("\n");
      writer.write("\n<script language=\"javascript\">");
      writer.write("\n// Timer Bar - Version 1.0");
      writer.write("\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
      writer.write("\n  var loadedcolor='gray' ;            // PROGRESS BAR COLOR");


      writer.write("\n  var unloadedcolor='green';         // COLOR OF UNLOADED AREA");

      writer.write("\n  var bordercolor='navy';            // COLOR OF THE BORDER");
      writer.write("\n  var barheight = " + attrMap.get("height") + "; // HEIGHT OF PROGRESS BAR IN PIXELS");
      writer.write("\n  var barwidth = " + attrMap.get("width") + "; // WIDTH OF THE BAR IN PIXELS");
      writer.write("\n  var waitTime = " + attrMap.get("wait") + "; // NUMBER OF SECONDS FOR PROGRESSBAR");
      writer.write("\n  var loaded = " + attrMap.get("elapsed") + "*10; // TENTHS OF A SECOND ELAPSED");
      writer.write("\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
      writer.write("\n");
      writer.write("\n  var action = function()");
      writer.write("\n {");
      writer.write("\n   " + attrMap.get("expireScript") + ";");
      writer.write("\n  alert(\""  + attrMap.get("expireMessage") + "\");");
      writer.write("\n }");
      writer.write("\n");
      writer.write("\n</script>");
      writer.write("\n<script language=\"javascript\" src=\"" +
           "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
      writer.write("\n");

     if (clientId != null)
       {
       writer.endElement("span");
     }
 }
 
Example 12
Source File: ProgressBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

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

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

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

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

     writer.write("\n");
     writer.write("\n<script language=\"javascript\">");
     writer.write("\n// Timer Bar - Version 1.0");
     writer.write(
         "\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
     writer.write(
         "\n  var loadedcolor='blue' ;            // PROGRESS BAR COLOR");
     writer.write(
         "\n  var unloadedcolor='white';         // COLOR OF UNLOADED AREA");
     writer.write(
         "\n  var bordercolor='white';            // COLOR OF THE BORDER");
     writer.write("\n  var barheight = 45; // HEIGHT OF PROGRESS BAR IN PIXELS");
     writer.write("\n  var barwidth = 300; // WIDTH OF THE BAR IN PIXELS");
     writer.write("\n  var waitTime = " + attrMap.get("wait") +
                  "; // NUMBER OF SECONDS FOR PROGRESSBAR");
     writer.write("\n  var loaded = 0; // TENTHS OF A SECOND ELAPSED");
     writer.write(
         "\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
     writer.write("\n");
     writer.write("\n  var action = function()");
     writer.write("\n {");
     writer.write("\n }");
     writer.write("\n</script>");
     writer.write("\n<script language=\"javascript\" src=\"" +
          "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
     writer.write("\n");

     if (clientId != null) {
       writer.endElement("span");
     }
 }
 
Example 13
Source File: R.java    From BootsFaces-OSP with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a CSS class to a component in the view tree. The class is appended
 * to the styleClass value.
 * 
 * @param c
 *            the component
 * @param aclass
 *            the CSS class to be added
 */
protected static void addClass2Component(UIComponent c, String aclass) {
	Map<String, Object> a = c.getAttributes();
	if (a.containsKey("styleClass")) {
		a.put("styleClass", a.get("styleClass") + " " + aclass);
	} else {
		a.put("styleClass", aclass);
	}
}