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

The following are Jave code examples for showing how to use getClientId() of the javax.faces.component.UIComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: oscm   File: ExportBillingDataCtrl.java   Source Code and License Vote up 6 votes
public void validateFromAndToDate(final FacesContext context,
        final UIComponent toValidate, final Object value) {
    model.setFailedDateComponentId("");
    validator.setToDate(getModel().getToDate());
    validator.setFromDate(getModel().getFromDate());
    String clientId = toValidate.getClientId(context);
    try {
        validator.validate(context, toValidate, value);
    } catch (ValidatorException ex) {
        context.addMessage(
                clientId,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, ex
                        .getLocalizedMessage(), null));
        model.setFailedDateComponentId(clientId);
    }

}
 
Example 2
Project: myfaces-trinidad   File: RenderUtils.java   Source Code and License Vote up 6 votes
/**
 *  Retrieves id of the form the component is contained in.
 *
 * @param context the faces context object
 * @param component UIComponent whose container form id is to be retuirned
 *
 * @return String id of the form if one exists in component's hierarchy,
 *                otherwise null
 */
public static String getFormId(
  FacesContext context,
  UIComponent  component)
{
  UIComponent form = null;
  while (component != null)
  {
    if ((component instanceof UIForm) ||
        (component instanceof UIXForm))
    {
      form = component;
      break;
    }

    component = component.getParent();
  }

  if (form == null)
    return null;

  return form.getClientId(context);
}
 
Example 3
Project: myfaces-trinidad   File: ShowOneListRendererBase.java   Source Code and License Vote up 6 votes
/**
 *  Find the child whose Id is passed as argument.
 *
 *  If the specified child can't be found, doesn't do anything.
 *
 *  @param context the facesContext object
 *  @param parent which may contain disclosedChildId as it's child
 *  @param disclosedChildId id of the child to be found among it's children
 *
 */
@SuppressWarnings("unchecked")
private static UIComponent _findChild(FacesContext context,
                                      UIComponent component,
                                      String disclosedChildId)
{
  if  (disclosedChildId == null)
  {
    return null;
  }

  for(UIComponent child : (List<UIComponent>)component.getChildren())
  {
    String childId = child.getClientId(context);
    if (disclosedChildId.equals(childId))
    {
      return child;
    }
  }

  return null;
}
 
Example 4
Project: myfaces-trinidad   File: RenderUtils.java   Source Code and License Vote up 6 votes
/**
 * Returns the clientId used by the renderer in place of the clientId used by the component.
 * Certain renderers render their root element with a clientId that differs from the one
 * used by the component.
 * @param context FacesContent.
 * @param component UIComponent.
 * @return component clientId if the renderer clientId is null. Otherwise clientId used by 
 * renderer.
 */
public static String getRendererClientId(
  FacesContext context, 
  UIComponent component) 
{
  String clientId = component.getClientId(context);
  String family = component.getFamily();
  String rendererType = component.getRendererType();
  if (rendererType != null)
  {
    Renderer renderer = context.getRenderKit().getRenderer(family, rendererType);
    if (renderer instanceof CoreRenderer)
    {
      CoreRenderer coreRenderer = (CoreRenderer) renderer;
      String rendererClientId = coreRenderer.getClientId(context, component);
      return rendererClientId == null ? clientId : rendererClientId;
    }
  }
  return clientId;
}
 
Example 5
Project: myfaces-trinidad   File: MenuSelectedValueBoundValue.java   Source Code and License Vote up 6 votes
public Object getValue(UIXRenderingContext context)
{
    
  UIComponent stamp = getStamp(_menuComponent);
  
  if(stamp != null)
  { 
    // Save the current key  
    Object oldPath =_menuComponent.getRowKey();
    boolean isNewPath = setNewPath(_menuComponent);
    if (isNewPath)
    {
      String clientId = stamp.getClientId(context.getFacesContext());
      _menuComponent.setRowKey(oldPath);
      return clientId;
    }
  }
  
  return null;
}
 
Example 6
Project: myfaces-trinidad   File: TreeTableRenderer.java   Source Code and License Vote up 5 votes
/**
 * @todo Set "expanded" vs. "collapsed" correctly on the queued
 *  DisclosureEvent
 * @todo deal with null and exceptions
 */
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  decodeSelection(facesContext, component);

  Map<String, String> parameters =
    facesContext.getExternalContext().getRequestParameterMap();

  Object source = parameters.get(XhtmlConstants.SOURCE_PARAM);
  clientId = clientId == null ? component.getClientId(facesContext) : clientId;
  if (clientId.equals(source))
  {
    UIXTreeTable treeTable = (UIXTreeTable) component;
    TreeUtils.decodeExpandEvents(parameters, component,
                                 TreeUtils.getFocusRowKey(treeTable));
    TreeUtils.decodeFocusEvent(parameters, component);
    TreeUtils.decodeGotoEvent(parameters, component);
    // bug 4522210:
    RequestContext.getCurrentInstance().addPartialTarget(component);
  }
}
 
Example 7
Project: myfaces-trinidad   File: SubformRenderer.java   Source Code and License Vote up 5 votes
@Override
public void encodeBegin(FacesContext context, UIComponent component)
{
  boolean isDefault = ((UIXSubform) component).isDefault();
  String clientId = component.getClientId(context);
  getSubformList(context, false, true).add(clientId);
  if (isDefault)
    getSubformList(context, true, true).add(clientId);
}
 
Example 8
Project: myfaces-trinidad   File: HtmlCommandButtonRenderer.java   Source Code and License Vote up 5 votes
@Override
public void decode(FacesContext context, UIComponent component)
{
  Object source =
    context.getExternalContext().getRequestParameterMap().get("source");

  String clientId = component.getClientId(context);
  if ((source != null) &&
      source.equals(clientId))
  {
    (new ActionEvent(component)).queue();
  }
}
 
Example 9
Project: myfaces-trinidad   File: PollRenderer.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  Map<String, String> parameters =
    facesContext.getExternalContext().getRequestParameterMap();

  Object event = parameters.get(XhtmlConstants.EVENT_PARAM);
  if (XhtmlConstants.POLL_EVENT.equals(event))
  {
    Object source = parameters.get(XhtmlConstants.SOURCE_PARAM);
    String id = clientId == null ? component.getClientId(facesContext) : clientId;

    if (id.equals(source))
    {
      // This component always uses PPR (unless not supported at all)
      PartialPageUtils.forcePartialRendering(facesContext);

      // And forcibly re-render ourselves - because that's how
      // we get the poll re-started
      RequestContext.getCurrentInstance().addPartialTarget(component);

      UIXPoll poll = (UIXPoll) component;
      (new PollEvent(component)).queue();
      if (poll.isImmediate())
        facesContext.renderResponse();
    }
  }
}
 
Example 10
Project: myfaces-trinidad   File: PPRResponseWriter.java   Source Code and License Vote up 5 votes
private void _pushPartialTarget(
  UIComponent component,
  String      elementName)
  throws IOException
{
  PPRTag tag = null;

  // If we're already inside a target, don't bother
  if (!_isInsideTarget())
  {
    if (component != null)
    {
      String clientId = component.getClientId(_facesContext);
      String renderedClientId = RenderUtils.getRendererClientId(_facesContext, component);
      if (_state.pprContext.isPartialTarget(clientId))
      {
        tag = new PPRTag(clientId, renderedClientId);
        _state.enteringPPR = component;
      }
    }
  }

  if (tag != null)
  {
    super.flush();
    tag.startUpdate(_state.pprContext, elementName);
  }

  _state.componentStack.add(tag);
}
 
Example 11
Project: myfaces-trinidad   File: EditableValueRenderer.java   Source Code and License Vote up 5 votes
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  if (skipDecode(facesContext))
    return;

  Object submittedValue;
  if (!wasSubmitted(facesContext, component))
    submittedValue = null;
  else
  {
    if (clientId == null)
    {
      clientId = component.getClientId(facesContext);
    }
    submittedValue = getSubmittedValue(facesContext, component, clientId);
  }

  if (_LOG.isFinest())
  {
    if (clientId == null)
    {
      clientId = component.getClientId(facesContext);
    }
    _LOG.finest("Value submitted for ID {0} is {1}",
      new Object[]{clientId, submittedValue});
  }

  EditableValueHolder evh = (EditableValueHolder) component;
  evh.setSubmittedValue(submittedValue);
}
 
Example 12
Project: myfaces-trinidad   File: CommandLinkRenderer.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  FacesBean    facesBean,
  String       clientId)
{
  RequestContext requestContext = RequestContext.getCurrentInstance();
  ReturnEvent returnEvent =
    requestContext.getDialogService().getReturnEvent(component);
  if (returnEvent != null)
  {
    returnEvent.queue();
  }
  else
  {
    Map<String, String> parameterMap =
      facesContext.getExternalContext().getRequestParameterMap();

    Object source = parameterMap.get("javax.faces.source");
    
    // Support the legacy as well as JSF2 parameter name
    if (source == null) 
    {
      source = parameterMap.get("source");  
    }
    
    if (clientId == null)
    {
      clientId = component.getClientId(facesContext);
    }

    if ((source != null) && source.equals(clientId))
    {
      (new ActionEvent(component)).queue();
      if (getPartialSubmit(component, facesBean))
      {
        PartialPageUtils.forcePartialRendering(facesContext);
      }
    }
  }
}
 
Example 13
Project: myfaces-trinidad   File: SingleStepRenderer.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
public void decode(FacesContext context, UIComponent component)
{
  Map<String, String> parameters =  
    context.getExternalContext().getRequestParameterMap();
  
  Object event = parameters.get(UIConstants.EVENT_PARAM);

  if (UIConstants.GOTO_EVENT.equals(event))
  {
    Object source = parameters.get(UIConstants.SOURCE_PARAM);

    String id = component.getClientId(context);

    if (id.equals(source))
    {

      Object newValue = parameters.get(UIConstants.VALUE_PARAM);

      int newValueInt = -1;

      if ( newValue != null)
      {
        try{
          newValueInt = Integer.parseInt(newValue.toString());
        }
        catch ( NumberFormatException nfe)
        {
          _LOG.severe(nfe);
        }
      }


      // queue the action on the singleStep component
      // set immediate to true when going back (no validation)
      // and set to false when going forward (validation).
      UIXSingleStep singleStep = (UIXSingleStep) component;

      int oldValueInt = singleStep.getSelectedStep();
      if (newValueInt < oldValueInt )
      {
        singleStep.setActionType(UIXSingleStep.PREVIOUS_ACTION_TYPE);

      }
      else
      {
        singleStep.setActionType(UIXSingleStep.NEXT_ACTION_TYPE);

      }



      // queue an action event
      // This must be added to queue AFTER the actionType is set
      (new ActionEvent(component)).queue();
    }
  }
}
 
Example 14
Project: myfaces-trinidad   File: RenderUtils.java   Source Code and License Vote up 4 votes
private static String _getRelativeId(
  FacesContext context,
  UIComponent  from,
  String       relativeId,
  int          colonCount)
{


  if (colonCount == 1)
    return relativeId.substring(1);
  else if (colonCount > 1)
  {
    relativeId = relativeId.substring(colonCount);
  }
    
  // if the component is not a NamingContainer, then we need to 
  // get the component's naming container and set this as the 'from'.

  if (!(from instanceof NamingContainer))
  {
    from = _getParentNamingContainer(from);
  }
  // pop out of the naming containers if there are multiple colons
  // from will be null if there are no more naming containers
  for (int j = 1; j < colonCount; j++)
  {
    from = _getParentNamingContainer(from);
  }

  // assumption is no one but the parent naming container modifies its
  // client id
  if (from == null)
    return relativeId;
  else
  {
    return (from.getClientId(context) +
            NamingContainer.SEPARATOR_CHAR + relativeId);
  }


}
 
Example 15
Project: myfaces-trinidad   File: CorePanelChoiceRenderer.java   Source Code and License Vote up 4 votes
/**
 * @inheritDoc
 *
 */
@Override
protected void renderListDisplay(FacesContext context,
                                 UIComponent component,
                                 String disclosedChildId)
  throws IOException
{
  // This renders the select controls alongwith javascript onchange handler.
  UIXRenderingContext rCtx =
    getRenderingContext(context, component);

  String compId = component.getClientId(context);

  ResponseWriter out = context.getResponseWriter();

  // draw table to contain the select UI control
  out.startElement("table", component);
  out.writeAttribute("id", compId + _CHOICE_TABLE_SUFFIX_ID_CONST, null);
  out.writeAttribute("border", "0", null);
  out.writeAttribute("cellspacing", "0", null);
  out.writeAttribute("cellpadding", "0", null);

  if (!XhtmlLafRenderer.isInaccessibleMode(rCtx))
  {
    out.writeAttribute("summary", "", null);
  }

  out.startElement("tr", component);

  renderSelectLabel(rCtx, component, out, compId);

  // Render filler / separator between label and select control
  renderSpacerTD(out, component, getLabelControlSeparatorSize());

  _renderSelectItemInTD(context,
                        component,
                        disclosedChildId);

  out.endElement("tr");
  out.endElement("table");
}
 
Example 16
Project: myfaces-trinidad   File: CorePanelChoiceRenderer.java   Source Code and License Vote up 4 votes
/**
 *  Generates markup for rendering HTML select control.
 *
 *  The select control markup is contained within a TD element.
 */
@SuppressWarnings("unchecked")
private void _renderSelectItemInTD(FacesContext context,
                                   UIComponent component,
                                   String disclosedChildId)
  throws IOException
{
  String compId = component.getClientId(context);
  ResponseWriter out = context.getResponseWriter();
  UIXRenderingContext rCtx = getRenderingContext(context, component);

  out.startElement("td", component);
  out.writeAttribute("valign", "top", null);
  out.writeAttribute("nowrap", Boolean.TRUE, null);

  out.startElement("select", component);
  out.writeAttribute("id", compId + _CHOICE_SELECT_SUFFIX_ID_CONST, null);
  out.writeAttribute("name", compId + _CHOICE_SELECT_SUFFIX_ID_CONST,null);

  XhtmlLafRenderer.renderStyleClassAttribute(rCtx, getFieldTextClass());

  // construct the javascript for submitting the form
  String onChangeJS = _getChoiceOnchangeJS(context,rCtx, component, compId);
  if (onChangeJS != null)
  {
    out.writeAttribute("onchange", onChangeJS, null);
  }

  // Render options now.
  ListIterator<UIComponent> children = component.getChildren().listIterator();
  while (children.hasNext())
  {
    UIComponent child = children.next();
    if (child instanceof UIXShowDetail)
    {
      UIXShowDetail detailItem = (UIXShowDetail) child;

      Boolean disabledObj =
        (Boolean) detailItem.getAttributes().get("disabled");

      boolean disabled = false; // by default is enabled.
      if (disabledObj != null)
      {
        disabled = disabledObj.booleanValue();
      }

      if (disabled)
      {
        // MSDN DHTML Reference says disabled not supported for option element
        // hence don't render disabled options at all to be consistent 
        // across browsers. See Bug 4561967.
        continue;
      }

      String childTitle = (String) detailItem.getAttributes().get("text");
      String childClientId = child.getClientId(context);

      out.startElement("option", component);
      out.writeAttribute("id", childClientId, null);
      if (childClientId.equals(disclosedChildId))
      {
        out.writeAttribute("selected", Boolean.TRUE, null);
      }

      if (childTitle != null)
        out.writeText(childTitle, null);

      out.endElement("option");
    }
  }
  out.endElement("select");

  out.endElement("td");
}
 
Example 17
Project: myfaces-trinidad   File: PanelAccordionRenderer.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  Map<String, String> parameters =
    facesContext.getExternalContext().getRequestParameterMap();

  Object event = parameters.get(XhtmlConstants.EVENT_PARAM);
  if (XhtmlConstants.HIDE_EVENT.equals(event) ||
      XhtmlConstants.SHOW_EVENT.equals(event))
  {
    Object source = parameters.get(XhtmlConstants.SOURCE_PARAM);
    String id = clientId == null ? component.getClientId(facesContext) : clientId;

    if (id.equals(source))
    {
      boolean isDisclosed = XhtmlConstants.SHOW_EVENT.equals(event);
      String itemId = parameters.get("targetItem");
      if (itemId != null)
      {
        List<UIComponent> children = component.getChildren();
        for (UIComponent child : children)
        {
          if (!(child instanceof UIXShowDetail))
            continue;

          // Don't even bother with disabled showDetailItems -
          // a malicious user should not be able to force
          // a disabled item open by dummying up an event
          if (!child.isRendered() || _isItemDisabled(child))
            continue;

          if (itemId.equals(child.getClientId(facesContext)))
          {
            (new DisclosureEvent(child, isDisclosed)).queue();
            RequestContext rc = RequestContext.getCurrentInstance();

            // Don't force PPR on for the browsers that do not support Ajax
            Object cap = rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_PARTIAL_RENDERING);
            if ((cap != null) && (Boolean.TRUE.equals(cap)))
            {
              RequestContext.getCurrentInstance().addPartialTarget(component);
              PartialPageUtils.forcePartialRendering(facesContext);
            }

            break;
          }
        }
      }
    }
  }
}
 
Example 18
Project: myfaces-trinidad   File: CoreRenderer.java   Source Code and License Vote up 4 votes
/**
 * Decodes the behaviors of this component, if it is the component that is the source
 * of the call to the server and the event matches behaviors that are attached to
 * the component
 *
 * @param facesContext the faces context
 * @param component the component
 * @param bean the faces bean
 * @return the client ID if it was retrieved, null otherwise
 */
protected final String decodeBehaviors(
  FacesContext facesContext,
  UIComponent  component,
  FacesBean    bean)
{
  if (!(component instanceof ClientBehaviorHolder))
  {
    return null;
  }

  // Check if there are client behaviors first as it should be faster to access then
  // getting the behavior event from the request parameter map (fewer method calls)
  Map<String, List<ClientBehavior>> behaviorsMap = ((ClientBehaviorHolder)component).getClientBehaviors();
  if (behaviorsMap.isEmpty())
  {
    return null;
  }

  // Get the behavior event sent by the client, if any
  Map<String, String> requestParams = facesContext.getExternalContext().getRequestParameterMap();
  String event = requestParams.get(_BEHAVIOR_EVENT_KEY);
  if (event == null)
  {
    return null;
  }

  // Does the component have behaviors for this event type?
  List<ClientBehavior> behaviors = behaviorsMap.get(event);
  if (behaviors == null || behaviors.isEmpty())
  {
    return null;
  }

  // See if this is the submitting component
  String clientId = component.getClientId(facesContext);
  String sourceClientId = requestParams.get("javax.faces.source");
  if (clientId.equals(sourceClientId))
  {
    // Decode the behaviors
    for (ClientBehavior behavior: behaviors)
    {
      behavior.decode(facesContext, component);
    }
  }

  return clientId;
}
 
Example 19
Project: myfaces-trinidad   File: CoreRenderKit.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
public boolean launchDialog(
  FacesContext       context,
  UIViewRoot         targetRoot,
  UIComponent        source,
  Map<String,Object> processParameters,
  boolean            useWindow,
  Map<String,Object> windowProperties)
{
  // If we're not being asked to use a separate window,
  // just fallback on the default launchDialog() code
  if (!useWindow)
    return false;

  // And if we don't support separate windows at all, then bail
  // there too
  if (!_supportsSeparateWindow(context))
    return false;

  String sourceId = (source == null) ? null : source.getClientId(context);
  String formId = RenderUtils.getFormId(context, source);

  if (windowProperties == null)
    windowProperties = new HashMap<String,Object>();

  // Copy properties from the source component to the dialog properties
  if (source != null)
  {
    Map<String, Object> sourceAttrs = source.getAttributes();
    _copyProperty(windowProperties, "width", sourceAttrs, "windowWidth");
    _copyProperty(windowProperties, "height", sourceAttrs, "windowHeight");
  }

  Map<String, Object> pageFlowScope = 
    RequestContext.getCurrentInstance().getPageFlowScope();
  
  if (processParameters != null)
    pageFlowScope.putAll(processParameters);

  RequestContext rc = RequestContext.getCurrentInstance();
  DialogRequest request = new DialogRequest(targetRoot,
                                            sourceId,
                                            formId,
                                            windowProperties,
                                            usePopupForDialog(context, rc));
  _getDialogList(context, true).add(request);
  return true;
}
 
Example 20
Project: myfaces-trinidad   File: DialogServiceImpl.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
public ReturnEvent getReturnEvent(UIComponent source)
{
  FacesContext context = _getFacesContext();
  if (TrinidadFilterImpl.isExecutingDialogReturn(context))
  {
    Map<String, String> parameterMap =
      context.getExternalContext().getRequestParameterMap();
    String returnParam = parameterMap.get(_RETURN_PARAM);
    if (returnParam == null)
      return null;

    String clientId = source.getClientId(context);
    if (!returnParam.equals(clientId))
      return null;
  }
  else
  {
    DialogRenderKitService service = _getDialogRenderKitService(context);
    if (service == null)
      return null;
    if (!service.isReturning(context, source))
      return null;
  }

  // OK, we think we are returning to this component.  Create
  // the ReturnEvent.
  // =-=AEW Should we automatically add the component as a partial
  // target???
  Object o = context.getExternalContext().getSessionMap().
           remove(_DIALOG_RETURN_KEY);

  Object returnValue = null;
  Map<Object, Object> returnParams = null;
  if (o != null)
  {
    returnValue = ((Object[]) o)[0];
    returnParams = (Map<Object, Object>)((Object[]) o)[1];
  }

  ReturnEvent returnEvent =
     new ReturnEvent(source, returnValue, returnParams);

  if (_LOG.isFine())
    _LOG.fine("Obtained ReturnEvent {0}", returnEvent);

  return returnEvent;
}