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

The following examples show how to use javax.faces.component.UIComponent#getClientId() . 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: InputRichTextRenderer.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Standard decode method.
 * @param context
 * @param component
 */
public void decode(FacesContext context, UIComponent component)
{
  if( RendererUtil.isDisabledOrReadonly(context, component)) return;

  if (null == context || null == component
      || !(component instanceof org.sakaiproject.jsf2.component.InputRichTextComponent))
  {
    throw new IllegalArgumentException();
  }

  String clientId = component.getClientId(context);

  Map requestParameterMap = context.getExternalContext()
      .getRequestParameterMap();

  String newValue = (String) requestParameterMap.get(clientId + "_inputRichText");

  org.sakaiproject.jsf2.component.InputRichTextComponent comp = (org.sakaiproject.jsf2.component.InputRichTextComponent) component;
  comp.setSubmittedValue(newValue);
}
 
Example 2
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
private void saveChildState(FacesContext faces, UIComponent c) {

		if (c instanceof EditableValueHolder && !c.isTransient()) {
			String clientId = c.getClientId(faces);
			SavedState ss = this.getChildState().get(clientId);
			if (ss == null) {
				ss = new SavedState();
				this.getChildState().put(clientId, ss);
			}
			ss.populate((EditableValueHolder) c);
		}

		// continue hack
		Iterator itr = c.getFacetsAndChildren();
		while (itr.hasNext()) {
			saveChildState(faces, (UIComponent) itr.next());
		}
	}
 
Example 3
Source File: RequestTokenHtmlRenderer.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException
{
    ResponseWriter writer = facesContext.getResponseWriter();

    writer.startElement(INPUT_ELEMENT, component);
    writer.writeAttribute(TYPE_ATTRIBUTE, INPUT_TYPE_HIDDEN, null);

    String clientId = component.getClientId(facesContext);
    writer.writeAttribute(ID_ATTRIBUTE, clientId, null);
    writer.writeAttribute(NAME_ATTRIBUTE, clientId, null);

    String currentPostRequestToken = getPostRequestTokenManager().getCurrentToken();
    if (currentPostRequestToken != null)
    {
        writer.writeAttribute(VALUE_ATTRIBUTE, currentPostRequestToken, VALUE_ATTRIBUTE);
    }

    writer.endElement(INPUT_ELEMENT);
}
 
Example 4
Source File: CoreRenderer.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
protected void decodeBehaviors(FacesContext context, UIComponent component) {
	if (!(component instanceof ClientBehaviorHolder)) {
		return;
	}

	Map<String, List<ClientBehavior>> behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
	if (behaviors.isEmpty()) {
		return;
	}

	Map<String, String> params = context.getExternalContext().getRequestParameterMap();
	String behaviorEvent = params.get("javax.faces.behavior.event");
	if (null != behaviorEvent) {
		List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);

		if (behaviorsForEvent != null && !behaviorsForEvent.isEmpty()) {
			String behaviorSource = params.get("javax.faces.source");
			String clientId = component.getClientId(context);
			if (behaviorSource != null && clientId.equals(behaviorSource)) {
				for (ClientBehavior behavior : behaviorsForEvent) {
					behavior.decode(context, component);
				}
			}
		}
	}
}
 
Example 5
Source File: HideDivisionRenderer.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void encodeEnd(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);
    }

    writer.write("</div>");

//    writer.write("<script type=\"text/javascript\">");
//    writer.write("  showHideDiv('" + id +
//        "', '" +  RESOURCE_PATH + "');");
//    writer.write("</script>");
  }
 
Example 6
Source File: BsfUtils.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public static Locale selectLocale(Locale vrloc, Object loc, UIComponent comp) {
	java.util.Locale selLocale = vrloc;

	if (loc != null) {
		if (loc instanceof String) {
			selLocale = BsfUtils.toLocale((String) loc);
		} else if (loc instanceof java.util.Locale) {
			selLocale = (java.util.Locale) loc;
		} else {
			throw new IllegalArgumentException(
					"Type:" + loc.getClass() + " is not a valid locale type for " + comp.getFamily() + ":" + comp.getClientId());
		}
	}

	return selLocale;
}
 
Example 7
Source File: InputFileUploadRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component)
        throws IOException
{
    if (!component.isRendered()) return;

    ResponseWriter writer = context.getResponseWriter();
    String clientId = component.getClientId(context);
    //HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    // check that the structure of the form is valid
    boolean atDecodeTime = false;
    String errorMessage = checkForErrors(context, component, clientId, atDecodeTime);
    if (errorMessage != null)
    {
        addFacesMessage(context, clientId, errorMessage);
    }

    // output field that allows user to upload a file
    writer.startElement("input", null);
    writer.writeAttribute("type", "file", null);
    writer.writeAttribute("name", clientId + ID_INPUT_ELEMENT, null);
    String styleClass = (String) RendererUtil.getAttribute(context, component, "styleClass");
    if (styleClass != null) writer.writeAttribute("class", styleClass, null);
    boolean writeNullPassthroughAttributes = false;
    RendererUtil.writePassthroughAttributes(PASSTHROUGH_ATTRIBUTES,
            writeNullPassthroughAttributes, context, component);
    writer.endElement("input");

    // another comment
    // output hidden field that helps test that the filter is working right
    writer.startElement("input", null);
    writer.writeAttribute("type", "hidden", null);
    writer.writeAttribute("name", clientId + ID_HIDDEN_ELEMENT, null);
    writer.writeAttribute("value", "filter_is_functioning_properly", null);
    writer.endElement("input");
}
 
Example 8
Source File: UploadRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component)
		throws IOException {
	if (!component.isRendered())
		return;
	ResponseWriter writer = context.getResponseWriter();

	String clientId = component.getClientId(context);

	writer.startElement("input", component);
	writer.writeAttribute("type", "file", "type");
	writer.writeAttribute("name", clientId, "clientId");
	writer.endElement("input");
	writer.flush();
}
 
Example 9
Source File: UIDojoRadioButton.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public String getClientGroupName(FacesContext context) {
    String name = getGroupName();
    if (name == null) {
        name = getClientId(context);
    }
    else {
        int skip = getSkipContainers();
        UIComponent nc = (UIComponent)FacesUtil.getNamingContainer(this, skip);
        name = nc.getClientId(context) + ":" + name;
    }
    return name;
}
 
Example 10
Source File: TimerBarRenderer.java    From sakai with Educational Community License v2.0 5 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");
     }

      String contextPath = context.getExternalContext().getRequestContextPath();
      writer.write("\n<script type=\"text/javascript\" src=\"" +
        contextPath + SCRIPT_PATH + "timerbar.js\"></script>");
      writer.write("\n");

     if (clientId != null)
       {
       writer.endElement("span");
     }
 }
 
Example 11
Source File: DataLineRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * We put all our processing in the encodeChildren method
 * @param context
 * @param component
 * @throws IOException
 */
public void encodeChildren(FacesContext context, UIComponent component)
  throws IOException
{
  if (!component.isRendered())
  {
    return;
  }

  String clientId = null;

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

  ResponseWriter writer = context.getResponseWriter();

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

  UIData data = (UIData) component;

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

  // this is a special separator attribute, not supported by UIData
  String separator = (String) RendererUtil.getAttribute(context, component, "separator");
  if (separator==null) separator=" | ";

  for (int i = first, n = 0; n < rows; i++, n++)
  {
    data.setRowIndex(i);
    if (!data.isRowAvailable())
    {
      break;
    }

    // between any two iterations add separator if there is one
    if (i!=first) writer.write(separator);

    Iterator iter = data.getChildren().iterator();
    while (iter.hasNext())
    {
      UIComponent column = (UIComponent) iter.next();
      if (!(column instanceof UIColumn))
      {
        continue;
      }
      RendererUtil.encodeRecursive(context, column);
      }
    }
    if (clientId != null)
      {
      writer.endElement("span");
    }

  }
 
Example 12
Source File: Tooltip.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
public static void activateTooltips(FacesContext context, UIComponent component)
		throws IOException {
	String id = component.getClientId();
	activateTooltips(context, component, id);
}
 
Example 13
Source File: OutputDateRenderer.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.devtoolsRenderMaker</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 encodeBegin(FacesContext context, UIComponent component) throws
  IOException
{
  if (!component.isRendered())
  {
    return;
  }

  ResponseWriter writer = context.getResponseWriter();

  // this is a date object representing our date
  // this is a debug line, we are losing our date
  Date date = ((Date) RendererUtil.getDefaultedAttribute(
    context, component, "value", new Date()));
  // this is the formatted output representation of the date
  String dateStr = "";
  String formatStr = getFormatString(context, component);
  dateStr = format(date, formatStr);


  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");
  }
  writer.write(dateStr);
  if (clientId != null)
  {
    writer.endElement("span");
  }

}
 
Example 14
Source File: MobilePageRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    super.encodeBegin(context, component);
    ResponseWriter w = context.getResponseWriter();
    
    UIMobilePage page = (UIMobilePage)component;

    UIViewRootEx rootEx = (UIViewRootEx)context.getViewRoot();
    rootEx.setDojoParseOnLoad(true);
    rootEx.setDojoTheme(true);

    String clientId = component.getClientId(context);
    
    w.startElement("div", component); // $NON-NLS-1$
    
    // Setting a page name overrides the clientId. Therefore the user will need to make
    // sure that it's unique across the single application. Dojox.mobile requires us 
    // to use HTML ids meaning that normally the JSF client ids may appear in the URL, 
    // depending on the application this may be sub optimal, requiring this override.
    String pageName = page.getPageName();
    if(pageName != null){                
    	w.writeAttribute("pageName", pageName, "pageName"); // $NON-NLS-1$ $NON-NLS-2$        
    	w.writeAttribute("id", pageName, "id"); // $NON-NLS-1$ $NON-NLS-2$
    }
    else{
    	w.writeAttribute("pageName", clientId, "pageName"); // $NON-NLS-1$ $NON-NLS-2$        
    	w.writeAttribute("id", clientId, "id"); // $NON-NLS-1$ $NON-NLS-2$        	
    }
    
    String dojoType = getDojoType();
    if(StringUtil.isEmpty(dojoType)) {
        throw new IllegalStateException();
    }
    w.writeAttribute("dojoType", dojoType, "dojoType"); // $NON-NLS-1$ $NON-NLS-2$
    DojoModuleResource module = getDojoModule();
    if(module!=null) {
        ExtLibResources.addEncodeResource(rootEx, module);
    }
    
    boolean keepScrollPos = page.isKeepScrollPos();
    if(keepScrollPos != true/*defaults to true*/) {
        w.writeAttribute("keepScrollPos", "false", "keepScrollPos"); // $NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
    }
    
    boolean resetContent = page.isResetContent();
    if(resetContent) {
        w.writeAttribute("resetContent", resetContent, "resetContent"); // $NON-NLS-1$ $NON-NLS-2$
    }
    
    boolean preload = page.isPreload();
    if ( preload ) {
        w.writeAttribute("preload", preload, "preload"); // $NON-NLS-1$ $NON-NLS-2$
    }

    
    //TODO: should this be changed/removed/merged with preload?
    boolean loaded = preload; //loaded is not editable by the user
    if ( loaded ) {
        w.writeAttribute("loaded", loaded, "loaded"); // $NON-NLS-1$ $NON-NLS-2$
    }
    String onBeforeTransitionIn = page.getOnBeforeTransitionIn();
    if( null != onBeforeTransitionIn ){
        w.writeAttribute("onBeforeTransitionIn", onBeforeTransitionIn, "onBeforeTransitionIn"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    String onAfterTransitionIn = page.getOnAfterTransitionIn();
    if( null != onAfterTransitionIn ){
        w.writeAttribute("onAfterTransitionIn", onAfterTransitionIn, "onAfterTransitionIn"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    String onBeforeTransitionOut = page.getOnBeforeTransitionOut();
    if( null != onBeforeTransitionOut ){
        w.writeAttribute("onBeforeTransitionOut", onBeforeTransitionOut, "onBeforeTransitionOut"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    String onAfterTransitionOut = page.getOnAfterTransitionOut();
    if( null != onAfterTransitionOut ){
        w.writeAttribute("onAfterTransitionOut", onAfterTransitionOut, "onAfterTransitionOut"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    AttrsUtil.encodeAttrs(context, w, page);
    JSUtil.writeln(w);
}
 
Example 15
Source File: PopupRenderer.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.devtoolsRenderMaker</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 encodeBegin(FacesContext context, UIComponent component) throws
      IOException {

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

    ResponseWriter writer = context.getResponseWriter();
    String id = (String) component.getClientId(context);
    String title = (String) RendererUtil.getAttribute(context, component, "title");
    String url = (String) RendererUtil.getAttribute(context, component, "url");
    String target = (String) RendererUtil.getAttribute(context, component, "target");
    String toolbar = (String) RendererUtil.getAttribute(context, component, "toolbar");
    String menubar = (String) RendererUtil.getAttribute(context, component, "menubar");
    String personalbar = (String) RendererUtil.getAttribute(context, component, "personalbar");
// temporary workaround ClassCastException
    String width = null;//(String) RendererUtil.getAttribute(context, component, "width");
    String height = null; //(String) RendererUtil.getAttribute(context, component, "height");
    String scrollbars = (String) RendererUtil.getAttribute(context, component, "scrollbars");
    String resizable = (String) RendererUtil.getAttribute(context, component, "resizable");

    if (title == null) {
      title = "     ";
    }
    if (target == null) {
      target = "sakai_popup"; /** todo: put in resource*/
    }
    if (width == null) {
      width = "650";
    }
    if (height == null) {
      height = "375";
    }
    toolbar = RendererUtil.makeSwitchString(toolbar, false, true, true, true, false, false);
    menubar = RendererUtil.makeSwitchString(menubar, false, true, true, true, false, false);
    personalbar = RendererUtil.makeSwitchString(personalbar, false, true, true, true, false, false);
    scrollbars = RendererUtil.makeSwitchString(scrollbars, false, true, true, true, false, false);
    resizable = RendererUtil.makeSwitchString(resizable, false, true, true, true, false, false);

    String buttonSwitch = (String) RendererUtil.getAttribute(context, component, "useButton");
    boolean useButton = Boolean.getBoolean(
        RendererUtil.makeSwitchString(buttonSwitch, false, true, true, false, false, false));

    if (useButton) {
      writer.write("<!-- DEBUG: useButton=true -->");
      writer.write("<input");
      writer.write("  id=\"" + id + "\"");
      writer.write("  type=\"button\"");
      writer.write("  title=\"" + title + "\"");
      writer.write("  value=\"" + title + "\"");
      writer.write("  onclick=\"window.open('" + url + "','" + target +
                   "', 'toolbar=" + toolbar + ",menubar=" + menubar +
                   ",personalbar=" +
                   personalbar + ",width=" + width + ",height=" + height +
                   ",scrollbars=" + scrollbars + ",resizable=" + resizable +
                   "');\" />");
    }
    else {

      writer.write("<!-- DEBUG: useButton=false -->");
      writer.write("<a");
      writer.write("  id=\"" + id + "\"");
      writer.write("  title=\"" + title + "\"");
      writer.write("  href=\"#\"");
      writer.write("  onclick=\"window.open('" + url + "','" + target +
                   "', 'toolbar=" + toolbar + ",menubar=" + menubar +
                   ",personalbar=" +
                   personalbar + ",width=" + width + ",height=" + height +
                   ",scrollbars=" + scrollbars + ",resizable=" + resizable +
                   "');\" >");
      writer.write(title);
    }

  }
 
Example 16
Source File: DataLineRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * We put all our processing in the encodeChildren method
 * @param context
 * @param component
 * @throws IOException
 */
public void encodeChildren(FacesContext context, UIComponent component)
  throws IOException
{
  if (!component.isRendered())
  {
    return;
  }

  String clientId = null;

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

  ResponseWriter writer = context.getResponseWriter();

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

  UIData data = (UIData) component;

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

  // this is a special separator attribute, not supported by UIData
  String separator = (String) component.getAttributes().get("separator");
  if (separator==null) separator="";

  for (int i = first, n = 0; n < rows; i++, n++)
  {
    data.setRowIndex(i);
    if (!data.isRowAvailable())
    {
      break;
    }

    // between any two iterations add separator if there is one
    if (i!=first) writer.write(separator);

    Iterator iter = data.getChildren().iterator();
    while (iter.hasNext())
    {
      UIComponent column = (UIComponent) iter.next();
      if (!(column instanceof UIColumn))
      {
        continue;
      }
      RendererUtil.encodeRecursive(context, column);
      }
    }
    if (clientId != null)
      {
      writer.endElement("span");
    }

  }
 
Example 17
Source File: RichTextAreaRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component)
        throws IOException
{
    String clientId = component.getClientId(context);
    String textareaId = clientId+"_textarea";

    ResponseWriter writer = context.getResponseWriter();

    // value (text) of the HTMLArea
    Object value = null;
    if (component instanceof UIInput) value = ((UIInput) component).getSubmittedValue();
    if (value == null && component instanceof ValueHolder) value = ((ValueHolder) component).getValue();
    if (value == null) value = "";

    //escape the value so the wysiwyg editors don't get too clever and turn things
    //into tags that are not tags. 
    value = ComponentManager.get(FormattedText.class).escapeHtmlFormattedTextarea((String) value);

    // character height of the textarea
    int columns = -1;
    String columnsStr = (String) RendererUtil.getAttribute(context, component, "columns");
    if (columnsStr != null && columnsStr.length() > 0) columns = Integer.parseInt(columnsStr);
    
    // character width of the textarea
    int rows = -1;
    String rowsStr = (String) RendererUtil.getAttribute(context, component, "rows");
    if (rowsStr != null && rowsStr.length() > 0) rows = Integer.parseInt(rowsStr);
    	
    writer.write("<table border=\"0\"><tr><td>");
    writer.write("<textarea name=\"" + textareaId + "\" id=\"" + textareaId + "\"");
    if (columns > 0) writer.write(" cols=\""+columns+"\"");
    if (rows > 0) writer.write(" rows=\""+rows+"\"");
    writer.write(">");
    if (value != null)
       writer.write((String) value);
    writer.write("</textarea>");
    
    writer.write("<script type=\"text/javascript\">sakai.editor.launch('" + textareaId + "');</script>");
    
    //SAK-20818 be sure to close the table
    writer.write("</td></tr></table>\n");
    
 
}
 
Example 18
Source File: DataLineRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * We put all our processing in the encodeChildren method
 * @param context
 * @param component
 * @throws IOException
 */
public void encodeChildren(FacesContext context, UIComponent component)
  throws IOException
{
  if (!component.isRendered())
  {
    return;
  }

  String clientId = null;

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

  ResponseWriter writer = context.getResponseWriter();

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

  UIData data = (UIData) component;

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

  // this is a special separator attribute, not supported by UIData
  String separator = (String) component.getAttributes().get("separator");
  if (separator==null) separator="";

  for (int i = first, n = 0; n < rows; i++, n++)
  {
    data.setRowIndex(i);
    if (!data.isRowAvailable())
    {
      break;
    }

    // between any two iterations add separator if there is one
    if (i!=first) writer.write(separator);

    Iterator iter = data.getChildren().iterator();
    while (iter.hasNext())
    {
      UIComponent column = (UIComponent) iter.next();
      if (!(column instanceof UIColumn))
      {
        continue;
      }
      RendererUtil.encodeRecursive(context, column);
      }
    }
    if (clientId != null)
      {
      writer.endElement("span");
    }

  }
 
Example 19
Source File: ToolBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * We put all our processing in the encodeChildren method
 * @param context
 * @param component
 * @throws IOException
 */
public void encodeChildren(FacesContext context, UIComponent component) throws IOException
{
    if (!component.isRendered())
    {
        return;
    }

    String clientId = null;

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

    ResponseWriter writer = context.getResponseWriter();

    if (clientId != null)
    {
        writer.startElement("ul", component);
        //writer.append(" class=\"jsfToolbar\" "); // we don't seem to get here
    }

    @SuppressWarnings("unchecked")
    List<UIComponent> children = component.getChildren();

    // this is a special separator attribute, not supported by UIData
    String separator = (String) RendererUtil.getAttribute(context, component, "separator");
    if (separator == null)
    {
        separator = "";
    }

    boolean first = true;
    boolean foundCurrent = false;
    for( UIComponent child : children )
    {
        // should instead leave the span open, and the item should then add class and aria attributes
        // depending on the item is (disabled or not) and then close
        if (child.isRendered()) {
            if (!first)
            {
                writer.write("<li>");
            }
            else
            {
                writer.write("<li class=\"firstToolBarItem\">");
            }
            // SAK-23062 improve JSF options menu
            boolean current = false;
            if (!foundCurrent) {
                // check for the "current" attribute on the custom tag, mark that item as current if it set to true
                boolean hasCurrentIndicated = (child.getAttributes().get("current") != null); // NOTE: child.getAttributes().containsKey("current") will NOT work here
                current = (hasCurrentIndicated && ((Boolean)child.getAttributes().get("current")));
                /* this breaks too many other things
                 * if (!hasCurrentIndicated && !"javax.faces.Link".equals(child.getRendererType())) {
                 * // basically - if it is not a link, it is probably the current item
                 * current = true;
                 * }
                 */
            }
            if (current) {
                foundCurrent = true;
                writer.write("<span class=\"current\">");
            } else {
                writer.write("<span>");
            }
            RendererUtil.encodeRecursive(context, child);
            writer.write("</span></li> ");
            first = false;
        }
    }
    if (clientId != null)
    {
         writer.endElement("ul");
    }
}
 
Example 20
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");
     }
 }