protected void encodeProgressStateProlog(
      FacesContext context, UIComponent component, ProgressBarState currentState)
      throws IOException {

    ResponseWriter responseWriter = context.getResponseWriter();
    responseWriter.startElement(HtmlConstants.DIV_ELEM, component);
    responseWriter.writeAttribute(
        HtmlConstants.ID_ATTRIBUTE, component.getClientId(context) + ".rmng", null);
    responseWriter.writeAttribute(
        HtmlConstants.CLASS_ATTRIBUTE,
        HtmlUtil.concatClasses("rf-pb-rmng", component.getAttributes().get("remainingClass")),
        null);

    responseWriter.writeAttribute(
        HtmlConstants.STYLE_ATTRIBUTE,
        getContentStyle(currentState == ProgressBarState.progressState),
        null);

    responseWriter.startElement(HtmlConstants.DIV_ELEM, component);
    responseWriter.writeAttribute(
        HtmlConstants.CLASS_ATTRIBUTE,
        HtmlUtil.concatClasses("rf-pb-prgs", component.getAttributes().get("progressClass")),
        null);
    responseWriter.writeAttribute(
        HtmlConstants.ID_ATTRIBUTE, component.getClientId(context) + ".prgs", null);
    responseWriter.writeAttribute(
        HtmlConstants.STYLE_ATTRIBUTE, "width: " + getWidth(component) + "%", null);
    responseWriter.endElement(HtmlConstants.DIV_ELEM);
  }
Пример #2
0
  protected String buildAjaxRequest(FacesContext context, AjaxSource source, UIComponent form) {
    UIComponent component = (UIComponent) source;
    String clientId = component.getClientId(context);

    AjaxRequestBuilder builder = new AjaxRequestBuilder();

    builder
        .source(clientId)
        .process(context, component, source.getProcess())
        .update(context, component, source.getUpdate())
        .async(source.isAsync())
        .global(source.isGlobal())
        .partialSubmit(source.isPartialSubmit(), source.isPartialSubmitSet())
        .onstart(source.getOnstart())
        .onerror(source.getOnerror())
        .onsuccess(source.getOnsuccess())
        .oncomplete(source.getOncomplete())
        .params(component);

    if (form != null) {
      builder.form(form.getClientId(context));
    }

    builder.preventDefault();

    return builder.build();
  }
 protected void encodeScript(FacesContext facesContext, UIComponent component) throws IOException {
   JavaScriptService javaScriptService = ServiceTracker.getService(JavaScriptService.class);
   JSFunction messageObject = new JSObject(getJSClassName(), component.getClientId(facesContext));
   Map<String, Object> attributes = component.getAttributes();
   Builder<String, Object> parametersBuilder = ImmutableMap.builder();
   String forId = (String) attributes.get("for");
   RendererUtils rendererUtils = RendererUtils.getInstance();
   if (!Strings.isNullOrEmpty(forId)) {
     UIComponent target = rendererUtils.findComponentFor(component, forId);
     if (null != target) {
       parametersBuilder.put("forComponentId", target.getClientId(facesContext));
     }
   }
   Severity level = getLevel(component);
   if (FacesMessage.SEVERITY_INFO != level) {
     parametersBuilder.put("level", level.getOrdinal());
   }
   if (!rendererUtils.isBooleanAttribute(component, "showSummary")) {
     parametersBuilder.put("showSummary", false);
   }
   if (rendererUtils.isBooleanAttribute(component, "showDetail")) {
     parametersBuilder.put("showDetail", true);
   }
   if (rendererUtils.isBooleanAttribute(component, "tooltip")) {
     parametersBuilder.put("tooltip", true);
   }
   if (isComponentMessages(component)) {
     parametersBuilder.put("isMessages", true);
   }
   messageObject.addParameter(parametersBuilder.build());
   // RendererUtils.getInstance().writeScript(facesContext, component, messageObject);
   javaScriptService.addPageReadyScript(facesContext, messageObject);
 }
Пример #4
0
 @Override
 public Object getAsObject(FacesContext context, UIComponent component, String value) {
   Messages.addInfo(component.getClientId(context), "Converter currently used: {0}", this);
   Messages.addInfo(component.getClientId(context), "EJB injected in converter: {0}", ejb);
   Messages.addInfo(component.getClientId(context), "CDI injected in converter: {0}", cdi);
   return value;
 }
Пример #5
0
  @Override
  public void doDecode(FacesContext context, UIComponent component) {
    final Map<String, String> map = context.getExternalContext().getRequestParameterMap();
    String newToggleState = map.get(component.getClientId(context) + NEW_NODE_TOGGLE_STATE);
    if (newToggleState != null) {

      AbstractTreeNode treeNode = (AbstractTreeNode) component;

      boolean initialState = treeNode.isExpanded();
      boolean newState = Boolean.valueOf(newToggleState);
      if (initialState ^ newState) {
        new TreeToggleEvent(treeNode, newState).queue();
      }

      PartialViewContext pvc = context.getPartialViewContext();
      if (pvc.isAjaxRequest()
          && map.get(component.getClientId(context) + TRIGGER_NODE_AJAX_UPDATE) != null) {
        pvc.getRenderIds()
            .add(
                component.getClientId(context)
                    + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
                    + AbstractTreeNode.SUBTREE_META_COMPONENT_ID);

        context.getAttributes().put(AJAX_TOGGLED_NODE_ATTRIBUTE, component.getClientId(context));
        context
            .getAttributes()
            .put(
                AJAX_TOGGLED_NODE_STATE_ATTRIBUTE,
                initialState ? TreeNodeState.expanded : TreeNodeState.collapsed);
      }
    }
  }
Пример #6
0
  @Override
  protected void doDecode(FacesContext context, UIComponent component) {

    Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();

    AbstractPanelMenuItem menuItem = (AbstractPanelMenuItem) component;
    String compClientId = component.getClientId(context);
    if (requestMap.get(compClientId) != null) {
      AbstractPanelMenu pm = getParentPanelMenu(menuItem);

      if (pm.isImmediate()) {
        menuItem.setImmediate(true);
      }
      new ActionEvent(menuItem).queue();

      if (context.getPartialViewContext().isPartialRequest()) {

        // TODO nick - why render item by default?
        context.getPartialViewContext().getRenderIds().add(component.getClientId(context));

        // TODO nick - this should be done on encode, not on decode
        addOnCompleteParam(context, component.getClientId(context));
      }
    }
  }
Пример #7
0
  public void validateCaptcha(FacesContext context, UIComponent toValidate, Object value) {

    if (c != null) {
      Map map = context.getExternalContext().getRequestParameterMap();
      String challenge = map.get("recaptcha_challenge_field").toString();
      String response = map.get("recaptcha_response_field").toString();
      HttpServletRequest req =
          (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
      ReCaptchaResponse resp = r.checkAnswer(req.getRemoteAddr(), challenge, response);
      if (!resp.isValid() || hasValidationErrors) {
        Logger.getLogger(ContactUsPage.class.getName())
            .info("INVALID RESPONSE: " + resp.getErrorMessage());
        ((UIInput) toValidate).setValid(false);
        if (hasValidationErrors) {
          context.addMessage(
              toValidate.getClientId(context),
              new FacesMessage(
                  "Some required information was entered incorrectly. Please press refresh below to get a new challenge, then correct the issue."));
          hasValidationErrors = false;
        } else {
          context.addMessage(
              toValidate.getClientId(context),
              new FacesMessage("Press refresh below to get a new challenge."));
          hasValidationErrors = false;
        }
      }
    }
  }
Пример #8
0
  @Override
  protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component)
      throws IOException {
    AbstractTooltip tooltip = (AbstractTooltip) component;

    writer.startElement(getMarkupElement(tooltip), component);
    writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context), "clientId");

    writer.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, "display: none;", null);
    writer.startElement(getMarkupElement(tooltip), component);
    writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) + ":wrp", null);
    writer.writeAttribute(CLASS_ATTRIBUTE, getStyleClass(component), null);

    int zindex = tooltip.getZindex();
    if (zindex == Integer.MIN_VALUE) {
      zindex = DEFAULT_ZINDEX_VALUE;
    }

    String style = concatStyles("z-index:" + zindex, getStyle(component));
    if (style != null && style.trim().length() > 0) {
      writer.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, style, null);
    }

    renderPassThroughAttributes(context, component, getPassThroughAttributes());

    writer.startElement(getMarkupElement(tooltip), component);
    writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) + ":cntr", null);
    writer.writeAttribute(CLASS_ATTRIBUTE, "rf-tt-cntr", null);

    if (tooltip.getMode() == TooltipMode.ajax) {
      encodeLoading(writer, context, tooltip);
    }

    encodeContentBegin(writer, context, tooltip);
  }
Пример #9
0
 @Override
 public void validate(FacesContext context, UIComponent component, Object value)
     throws ValidatorException {
   if (value instanceof String) {
     String enteredOgrn = ((String) value).replaceAll("_+$", "");
     Matcher matcher = OGRN_OGRNIP_REGEX.matcher(enteredOgrn);
     if (!matcher.matches()) {
       FacesMessage message = new FacesMessage();
       message.setDetail(ERROR_MESSAGE);
       message.setSummary(ERROR_MESSAGE);
       message.setSeverity(FacesMessage.SEVERITY_ERROR);
       context.addMessage(component.getClientId(), message);
       throw new ValidatorException(message);
     } else {
       boolean correct = true;
       int length;
       BigInteger divisor;
       if (enteredOgrn.length() == OGRN_LENGTH) {
         length = OGRN_LENGTH;
         divisor = OGRN_DIVISOR;
       } else {
         length = OGRNIP_LENGTH;
         divisor = OGRNIP_DIVISOR;
       }
       int last = Character.getNumericValue(enteredOgrn.charAt(length - 1));
       BigInteger ogrn = new BigInteger(enteredOgrn.substring(0, length - 1));
       BigInteger[] divisionResult = ogrn.divideAndRemainder(divisor);
       int remainder = divisionResult[1].intValue();
       if (remainder > REMAINDER_THRESHOLD) {
         remainder = remainder % 10;
       }
       if (remainder != last) {
         correct = false;
       }
       if (!correct) {
         FacesMessage message = new FacesMessage();
         message.setDetail(INCORRECT_BY_CHECK_DIGIT);
         message.setSummary(INCORRECT_BY_CHECK_DIGIT);
         message.setSeverity(FacesMessage.SEVERITY_ERROR);
         context.addMessage(component.getClientId(), message);
         throw new ValidatorException(message);
       }
     }
   } else {
     FacesMessage message = new FacesMessage();
     message.setDetail(ERROR_MESSAGE);
     message.setSummary(ERROR_MESSAGE);
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     context.addMessage(component.getClientId(), message);
     throw new ValidatorException(message);
   }
 }
Пример #10
0
    private void handleAddEvent(FacesContext context, PostAddToViewEvent event) {

      // if the root is transient, then no action is ever needed here
      if (context.getViewRoot().isTransient()) {
        return;
      }

      UIComponent added = event.getComponent();
      if (added.isTransient() || added instanceof UIViewRoot) {
        return;
      }

      // this component, while not transient may be a child or facet
      // of component that is.  We'll have to search the parent hierarchy
      // to the root to confirm.
      UIComponent parent = added.getParent();
      while (parent != null) {
        if (parent.isTransient()) {
          return;
        }
        parent = parent.getParent();
      }

      parent = added.getParent();
      if (dynamicAdds == null) {
        dynamicAdds = new LinkedHashMap<String, ComponentStruct>();
      }
      ComponentStruct toAdd = new ComponentStruct();

      toAdd.clientId = added.getClientId(context);
      toAdd.parentClientId = parent.getClientId(context);
      // this needs work
      int idx = parent.getChildren().indexOf(added);
      if (idx == -1) {
        // this must be a facet
        for (Map.Entry<String, UIComponent> facet : parent.getFacets().entrySet()) {
          if (facet.getValue() == added) {
            toAdd.facetName = facet.getKey();
            break;
          }
        }
      } else {
        toAdd.indexOfChildInParent = parent.getChildren().indexOf(added);
      }
      if (dynamicRemoves != null) {
        dynamicRemoves.remove(toAdd.clientId);
      }
      added.getAttributes().put(DYNAMIC_COMPONENT, Boolean.TRUE);
      dynamicAdds.put(toAdd.clientId, toAdd);
    }
Пример #11
0
    /**
     * Handle the add.
     *
     * @param context the Faces context.
     * @param component the UI component to add to the list as an ADD.
     */
    private void handleAdd(FacesContext context, UIComponent component) {
      if (!component.isTransient() && !hasTransientAncestor(component)) {
        if (component.getParent() != null && component.getParent().isInView()) {
          String id = component.getId();

          /*
           * Since adding a component, can mean you are really reparenting
           * it, we need to make sure the OLD clientId is not cached, we do
           * that by setting the id.
           */
          if (id != null) {
            component.setId(id);
          }

          if (component.getParent().getFacets().containsValue(component)) {
            Map facets = component.getParent().getFacets();
            Iterator entries = facets.entrySet().iterator();
            while (entries.hasNext()) {
              Map.Entry entry = (Map.Entry) entries.next();
              if (entry.getValue() == component) {
                incrementDynamicChildCount(component.getParent());
                component.clearInitialState();
                component
                    .getAttributes()
                    .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component));
                ComponentStruct struct = new ComponentStruct();
                struct.action = ComponentStruct.ADD;
                struct.facetName = entry.getKey().toString();
                struct.parentClientId = component.getParent().getClientId(context);
                struct.clientId = component.getClientId(context);
                struct.id = component.getId();
                handleAddRemoveWithAutoPrune(component, struct);
              }
            }
          } else {
            incrementDynamicChildCount(component.getParent());
            component.clearInitialState();
            component
                .getAttributes()
                .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component));
            ComponentStruct struct = new ComponentStruct();
            struct.action = ComponentStruct.ADD;
            struct.parentClientId = component.getParent().getClientId(context);
            struct.clientId = component.getClientId(context);
            struct.id = component.getId();
            handleAddRemoveWithAutoPrune(component, struct);
          }
        }
      }
    }
Пример #12
0
  /** If page >= 1 then it's a page number to show */
  @Attribute
  public int getPage() {

    UIComponent dataTable = getDataTable();
    Map<String, Object> attributes = dataTable.getAttributes();

    FacesContext facesContext = getFacesContext();
    Integer state =
        (Integer) attributes.get(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE);

    if (state != null) {
      return state;
    }

    if (this.page != null) {
      return page;
    }

    ValueExpression ve = getValueExpression("page");
    if (ve != null) {
      try {
        Integer pageObject = (Integer) ve.getValue(getFacesContext().getELContext());

        if (pageObject != null) {
          return pageObject;
        }
      } catch (ELException e) {
        throw new FacesException(e);
      }
    }

    return 1;
  }
  protected void encodeItems(
      FacesContext facesContext, UIComponent component, List<Object> fetchValues)
      throws IOException {
    AbstractAutocomplete comboBox = (AbstractAutocomplete) component;
    AutocompleteEncodeStrategy strategy = getStrategy(component);
    strategy.encodeItemsContainerBegin(facesContext, component);

    Object savedVar = saveVar(facesContext, comboBox.getVar());
    Map<String, String> requestParameters =
        facesContext.getExternalContext().getRequestParameterMap();
    String value = requestParameters.get(component.getClientId(facesContext) + "Value");
    Iterator<Object> itemsIterator = comboBox.getItems(facesContext, value).iterator();

    if (!itemsIterator.hasNext()) {
      strategy.encodeFakeItem(facesContext, component);
    } else {
      while (itemsIterator.hasNext()) {
        Object item = itemsIterator.next();

        setVar(facesContext, comboBox.getVar(), item);
        this.encodeItem(facesContext, comboBox, item, strategy);

        if (comboBox.getFetchValue() != null) {
          fetchValues.add(comboBox.getFetchValue().toString());
        } else if (item != null) {
          fetchValues.add(item.toString());
        }
      }
    }

    setVar(facesContext, comboBox.getVar(), savedVar);

    strategy.encodeItemsContainerEnd(facesContext, component);
  }
  protected Iterator<MessageForRender> getMessages(
      FacesContext context, String forClientId, UIComponent component) {

    Iterator<MessageForRender> msgIter;

    if (forClientId != null) {

      if (forClientId.length() != 0) {

        UIComponent result = RendererUtils.getInstance().findComponentFor(component, forClientId);
        if (result == null) {
          msgIter = Iterators.emptyIterator();
        } else {
          String clientId = result.getClientId(context);
          msgIter = getMessagesForId(context, clientId);
        }
      } else {
        msgIter = getMessagesForId(context, null);
      }
    } else {
      msgIter = Iterators.emptyIterator();
      Iterator<String> clientIdsWithMessages = context.getClientIdsWithMessages();
      while (clientIdsWithMessages.hasNext()) {
        String clientId = (String) clientIdsWithMessages.next();
        msgIter = Iterators.concat(msgIter, getMessagesForId(context, clientId));
      }
    }

    return msgIter;
  }
Пример #15
0
  // Decodes Behaviors if any match the behavior source/event.
  // As a convenience, returns component id, but only if it
  // was retrieved.  This allows us to avoid duplicating
  // calls to getClientId(), which can be expensive for
  // deep component trees.
  protected final String decodeBehaviors(FacesContext context, UIComponent component) {

    if (!(component instanceof ClientBehaviorHolder)) {
      return null;
    }

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

    String behaviorEvent = BEHAVIOR_EVENT_PARAM.getValue(context);

    if (null != behaviorEvent) {
      List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);

      if (behaviorsForEvent != null && behaviorsForEvent.size() > 0) {
        String behaviorSource = BEHAVIOR_SOURCE_PARAM.getValue(context);
        String clientId = component.getClientId();
        if (isBehaviorSource(context, behaviorSource, clientId)) {
          for (ClientBehavior behavior : behaviorsForEvent) {
            behavior.decode(context, component);
          }
        }

        return clientId;
      }
    }

    return null;
  }
  public String networkMeasure_action() {
    try {
      String result =
          networkDataService.runNetworkMeasure(networkMeasureType, networkMeasureParamterList);

      NetworkDataAnalysisEvent event = new NetworkDataAnalysisEvent();
      event.setLabel("Network Measure");
      event.setAttributeSet("N/A");
      event.setQuery(
          friendlyNameMap.get(networkMeasureType)
              + " ("
              + getNetworkMeasureParametersAsString(networkMeasureParamterList)
              + ")");
      event.setVertices(getLastEvent().getVertices());
      event.setEdges(getLastEvent().getEdges());
      event.setAddedAttribute(result); // in case we need to undo later
      events.add(event);

      // add measure to attributeList
      vertexAttributeSelectItems.add(new SelectItem(result));
      canUndo = true;

    } catch (Exception e) {
      FacesMessage message = new FacesMessage(e.getMessage());
      getFacesContext().addMessage(networkMeasureError.getClientId(getFacesContext()), message);
    }

    return null;
  }
Пример #17
0
  public void addBehaviors(String domEventName, String logicalEventName) {
    String name = domEventName;
    List<ClientBehavior> behaviorsList = getBehaviorsList(domEventName);

    if ((behaviorsList == null) && (logicalEventName != null)) {
      behaviorsList = getBehaviorsList(logicalEventName);
      name = logicalEventName;
    }

    if (behaviorsList == null) {
      return;
    }

    ClientBehaviorContext behaviorContext =
        ClientBehaviorContext.createClientBehaviorContext(
            facesContext,
            component,
            name,
            includeClientId ? component.getClientId(facesContext) : null,
            getParameters());

    for (ClientBehavior clientBehavior : behaviorsList) {
      String behaviorScript = clientBehavior.getScript(behaviorContext);

      if (isNotEmpty(behaviorScript)) {
        if (clientBehavior.getHints().contains(ClientBehaviorHint.SUBMITTING)) {
          hasSubmittingBehavior = true;
        }

        handlers.add(behaviorScript);
      }
    }
  }
 protected void calculateFormLabelWidth(FacesContext context, UIComponent component) {
   StringBuilder script = new StringBuilder();
   script.append("XSP.addOnLoad(function(){XSP.resizeForm("); // $NON-NLS-1$
   JavaScriptUtil.addString(script, component.getClientId(context));
   script.append(")});"); // $NON-NLS-1$
   ExtLibUtil.addScript(context, script.toString());
 }
  private static String getSubmitHandler(
      FacesContext context,
      UIComponent component,
      Collection<ClientBehaviorContext.Parameter> params,
      boolean preventDefault) {

    StringBuilder builder = new StringBuilder(256);

    String formClientId = getFormClientId(component, context);
    String componentClientId = component.getClientId(context);

    builder.append("qab.sf(document.getElementById('");
    builder.append(formClientId);
    builder.append("'),{");

    appendProperty(builder, componentClientId, componentClientId);

    if ((null != params) && (!params.isEmpty())) {
      for (ClientBehaviorContext.Parameter param : params) {
        appendProperty(builder, param.getName(), param.getValue());
      }
    }

    builder.append("})");

    if (preventDefault) {
      builder.append(";return false");
    }

    return builder.toString();
  }
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {

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

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

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

    String title = (String) RendererUtil.getAttribute(context, component, "title");
    Object tmpFoldStr = RendererUtil.getAttribute(context, component, "hideByDefault");
    String key = (String) RendererUtil.getAttribute(context, component, "key");

    writer.write("<fieldset>");
    writer.write("<legend>");
    writer.write(
        "<a role='button' data-toggle='collapse' aria-expanded='true' aria-target='"
            + id
            + "' href='#"
            + id
            + "' data-target=\"[id='"
            + id
            + "']\">"
            + title
            + "</a>");
    writer.write("</legend>");

    writer.write("<div class='collapse in' " + " id=\"" + id + "\">");
  }
Пример #21
0
  @SuppressWarnings("unchecked")
  @Override
  public void decode(FacesContext context, UIComponent component) {
    Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();

    Object event = requestMap.get(XhtmlConstants.EVENT_PARAM);

    if ((event != null) && event.equals(XhtmlConstants.GOTO_EVENT)) {
      Object source = requestMap.get(XhtmlConstants.SOURCE_PARAM);

      if (source != null && source.equals(component.getClientId(context))) {

        Object valueObject = requestMap.get(XhtmlConstants.VALUE_PARAM);

        // we piggyback on the size parameter.
        // 0 means we are moving to a previous step, 1 means we are
        // moving to the next step.
        Object sizeObject = requestMap.get(XhtmlConstants.SIZE_PARAM);

        if (valueObject != null) {
          int value = -1;

          try {
            value = Integer.parseInt(valueObject.toString());
          } catch (NumberFormatException nfe) {
            _LOG.severe(nfe);
          }

          int size = 0;

          try {
            size = Integer.parseInt(sizeObject.toString());
          } catch (NumberFormatException nfe) {
            _LOG.warning(nfe);
          }

          if (size < 0) size = 0;

          if (value >= 0) {
            UIXProcess process = (UIXProcess) component;
            Object oldPath = process.getRowKey();
            Object focusPath = process.getFocusRowKey();
            process.setRowKey(focusPath);
            UIComponent stamp = process.getNodeStamp();
            int index = process.getRowIndex();

            if (size == 0) {
              index = ProcessUtils.getBackIndex(process, stamp, index);
            } else {
              index = ProcessUtils.getNextIndex(process, stamp, index);
            }

            process.setRowIndex(index);
            new ActionEvent(stamp).queue();
            process.setRowKey(oldPath);
          }
        }
      }
    }
  }
Пример #22
0
  protected Iterator getMessageIter(
      FacesContext context, String forComponent, UIComponent component) {

    Iterator messageIter;
    // Attempt to use the "for" attribute to locate
    // messages.  Three possible scenarios here:
    // 1. valid "for" attribute - messages returned
    //    for valid component identified by "for" expression.
    // 2. zero length "for" expression - global errors
    //    not associated with any component returned
    // 3. no "for" expression - all messages returned.
    if (null != forComponent) {
      if (forComponent.length() == 0) {
        messageIter = context.getMessages(null);
      } else {
        UIComponent result = getForComponent(context, forComponent, component);
        if (result == null) {
          messageIter = Collections.EMPTY_LIST.iterator();
        } else {
          messageIter = context.getMessages(result.getClientId(context));
        }
      }
    } else {
      messageIter = context.getMessages();
    }
    return messageIter;
  }
Пример #23
0
  public static void decodeClientBehaviors(FacesContext facesContext, UIComponent uiComponent) {

    if (uiComponent instanceof ClientBehaviorHolder) {

      ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) uiComponent;
      Map<String, List<ClientBehavior>> clientBehaviorMap =
          clientBehaviorHolder.getClientBehaviors();

      Map<String, String> requestParameterMap =
          facesContext.getExternalContext().getRequestParameterMap();
      String behaviorEvent = requestParameterMap.get(FacesConstants.JAVAX_FACES_BEHAVIOR_EVENT);

      if (behaviorEvent != null) {

        List<ClientBehavior> clientBehaviors = clientBehaviorMap.get(behaviorEvent);

        if (clientBehaviors != null) {
          String source = requestParameterMap.get(FacesConstants.JAVAX_FACES_SOURCE);

          if (source != null) {
            String clientId = uiComponent.getClientId(facesContext);

            if (clientId.startsWith(source)) {

              for (ClientBehavior behavior : clientBehaviors) {
                behavior.decode(facesContext, uiComponent);
              }
            }
          }
        }
      }
    }
  }
Пример #24
0
  /**
   * Converts the entity to a String.
   *
   * @param facesContext current faces context
   * @param component current component
   * @param value current value of the entity
   * @return value converted to string.
   */
  public String getAsString(
      final FacesContext facesContext, final UIComponent component, final Object value) {

    logger.debug(
        String.format(
            "getAsString called value=%s, component=%s, value class=%s",
            value, component.getClientId(facesContext), value.getClass().getName()));
    if (value == null) {
      logger.debug("Value was null, can't convert");
      return "";
    }

    if (value instanceof String) {
      logger.debug("Value was a string");
      return value.toString();
    }

    BeanWrapper bwValue = new BeanWrapperImpl(value);

    try {
      String sValue = bwValue.getPropertyValue(idPropertyName).toString();
      logger.debug(String.format("string value %s", sValue));
      return sValue;
    } catch (Exception ex) {
      logger.debug("Unable to find value returning -1");
      return "-1";
    }
  }
  public void encodeClientScript(
      ResponseWriter writer, FacesContext facesContext, UIDataTableBase component)
      throws IOException {
    AbstractCollapsibleSubTable subTable = (AbstractCollapsibleSubTable) component;

    String id = subTable.getClientId(facesContext);

    UIComponent nestingForm = getUtils().getNestingForm(subTable);
    String formId = nestingForm != null ? nestingForm.getClientId(facesContext) : "";

    Map<String, Object> options = new HashMap<String, Object>();
    options.put("stateInput", subTable.getClientId(facesContext) + STATE);
    options.put("optionsInput", subTable.getClientId(facesContext) + OPTIONS);
    options.put("expandMode", subTable.getExpandMode());
    options.put("eventOptions", AjaxRendererUtils.buildEventOptions(facesContext, subTable));

    JSFunction jsFunction = new JSFunction("new RichFaces.ui.CollapsibleSubTable");
    jsFunction.addParameter(id);
    jsFunction.addParameter(formId);
    jsFunction.addParameter(options);

    writer.startElement(HtmlConstants.SCRIPT_ELEM, subTable);
    writer.writeAttribute(HtmlConstants.TYPE_ATTR, HtmlConstants.JAVASCRIPT_TYPE, null);
    writer.writeText(jsFunction.toScript(), null);
    writer.endElement(HtmlConstants.SCRIPT_ELEM);
  }
Пример #26
0
  private void writeTabsLine(ResponseWriter w, FacesContext context, UIComponent comp)
      throws IOException {
    w.startElement(DIV, comp);
    String id = comp.getClientId() + AbstractTabPanel.HEADER_META_COMPONENT;
    w.writeAttribute(ID_ATTRIBUTE, id, null);
    AbstractTabPanel tabPanel = (AbstractTabPanel) comp;
    if (tabPanel.isHeaderPositionedTop()) {
      w.writeAttribute(CLASS, "rf-tab-hdr-tabline-vis rf-tab-hdr-tabline-top", null);
    } else {
      w.writeAttribute(CLASS, "rf-tab-hdr-tabline-vis rf-tab-hdr-tabline-btm", null);
    }
    w.startElement("table", comp);
    w.writeAttribute(CLASS_ATTRIBUTE, "rf-tab-hdr-tabs", null);
    w.writeAttribute("cellspacing", "0", null);
    w.startElement(TBODY_ELEMENT, comp);
    w.startElement(TR_ELEMENT, comp);

    writeTopTabFirstSpacer(w, comp);

    writeTabLine(w, context, tabPanel);

    writeTopTabLastSpacer(w, comp);

    w.endElement(TR_ELEMENT);
    w.endElement(TBODY_ELEMENT);
    w.endElement("table");

    writeTopTabsControl(w, comp, "rf-tab-hdr-scrl-lft rf-tab-hdn", "\u00AB");
    writeTopTabsControl(w, comp, "rf-tab-hdr-tablst rf-tab-hdn", "\u2193");
    writeTopTabsControl(w, comp, "rf-tab-hdr-scrl-rgh rf-tab-hdn", "\u00BB");

    w.endElement(DIV_ELEM);
  }
Пример #27
0
 @Override
 protected JSObject getScriptObject(FacesContext context, UIComponent component) {
   return new JSObject(
       "RichFaces.ui.TabPanel",
       component.getClientId(context),
       getScriptObjectOptions(context, component));
 }
  public String automaticQuery_action() {
    try {
      int queryValue = 1;
      if (!StringUtil.isEmpty(automaticQueryNthValue)) {
        queryValue = Integer.valueOf(automaticQueryNthValue).intValue();
      }
      NetworkDataSubsetResult result =
          networkDataService.runAutomaticQuery(automaticQueryType, queryValue);

      NetworkDataAnalysisEvent event = new NetworkDataAnalysisEvent();
      event.setLabel("Automatic Query");
      event.setAttributeSet("N/A");
      event.setQuery(
          friendlyNameMap.get(automaticQueryType)
              + " ("
              + (StringUtil.isEmpty(automaticQueryNthValue) ? "1" : automaticQueryNthValue)
              + ")");
      event.setVertices(result.getVertices());
      event.setEdges(result.getEdges());
      events.add(event);
      canUndo = true;

    } catch (Exception e) {
      FacesMessage message = new FacesMessage(e.getMessage());
      getFacesContext().addMessage(automaticQueryError.getClientId(getFacesContext()), message);
    }

    return null;
  }
  /**
   * Collect all messages associated with components identified by <code>for</code> attribute and
   * return it. An empty list will be returned when there are no messages.
   *
   * @param context The involved faces context.
   * @param component The messages component.
   * @return All messages associated with components identified by <code>for</code> attribute.
   */
  protected List<FacesMessage> getMessages(FacesContext context, OmniMessages component) {
    String forClientIds = component.getFor();

    if (forClientIds == null) {
      return component.isGlobalOnly() ? context.getMessageList(null) : context.getMessageList();
    }

    List<FacesMessage> messages = new ArrayList<>();

    for (String forClientId : forClientIds.split("\\s+")) {
      UIComponent forComponent = component.findComponent(forClientId);

      if (forComponent == null) {
        continue;
      }

      messages.addAll(context.getMessageList(forComponent.getClientId(context)));

      if (!(forComponent instanceof UIInput)) {
        for (UIInput child : findComponentsInChildren(forComponent, UIInput.class)) {
          messages.addAll(context.getMessageList(child.getClientId(context)));
        }
      }
    }

    return messages;
  }
Пример #30
0
  public void validatePartialCredit(FacesContext context, UIComponent toValidate, Object value) {
    Integer pCredit = null;
    boolean isValid = true;
    if ("0.0".equals(value.toString())) {
      pCredit = 0;
    } else {
      try {
        pCredit = Integer.parseInt(value.toString());
      } catch (NumberFormatException e) {
        isValid = false;
      }
    }

    if (isValid && (pCredit == null || pCredit < 0 || pCredit > 99)) {
      isValid = false;
    }

    if (!isValid) {
      ((UIInput) toValidate).setValid(false);
      FacesMessage message = new FacesMessage();
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      String summary =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages",
              "partial_credit_limit_summary");
      String detail =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages",
              "partial_credit_limit_detail");
      message.setSummary(summary);
      message.setDetail(detail);
      context.addMessage(toValidate.getClientId(context), message);
    }
  }