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);
 }
Ejemplo n.º 2
0
  public void updateModel(FacesContext facesContext) {
    if (facesContext == null) {
      throw new NullPointerException();
    }

    if (!isValid() || !isLocalValueSet()) {
      return;
    }

    ValueExpression ve = getValueExpression("value");
    if (ve == null) {
      return;
    }

    Throwable caught = null;
    FacesMessage message = null;
    try {
      ve.setValue(facesContext.getELContext(), getLocalValue());
      setValue(null);
      setLocalValueSet(false);
    } catch (ELException e) {
      caught = e;
      String messageStr = e.getMessage();
      Throwable result = e.getCause();
      while (null != result && result.getClass().isAssignableFrom(ELException.class)) {
        messageStr = result.getMessage();
        result = result.getCause();
      }

      if (messageStr == null) {
        message =
            ServiceTracker.getService(MessageFactory.class)
                .createMessage(
                    facesContext,
                    FacesMessage.SEVERITY_ERROR,
                    FacesMessages.UIINPUT_UPDATE,
                    MessageUtil.getLabel(facesContext, this));
      } else {
        message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr);
      }
      setValid(false);
    } catch (Exception e) {
      caught = e;
      // message = MessageFactory.getMessage(facesContext, UPDATE_MESSAGE_ID,
      // MessageFactory.getHeader(facesContext, this));
      setValid(false);
    }

    if (caught != null) {
      assert message != null;

      @SuppressWarnings({"ThrowableInstanceNeverThrown"})
      UpdateModelException toQueue = new UpdateModelException(message, caught);
      ExceptionQueuedEventContext eventContext =
          new ExceptionQueuedEventContext(facesContext, toQueue, this, PhaseId.UPDATE_MODEL_VALUES);
      facesContext
          .getApplication()
          .publishEvent(facesContext, ExceptionQueuedEvent.class, eventContext);
    }
  }
  private Converter getConverterForValue(FacesContext context, UIComponent component) {
    Converter converter = ((ValueHolder) component).getConverter();
    if (converter == null) {
      ValueExpression expression = component.getValueExpression("value");

      if (expression != null) {
        Class<?> containerClass =
            ServiceTracker.getService(context, GenericsIntrospectionService.class)
                .getContainerClass(context, expression);

        converter = InputUtils.getConverterForType(context, containerClass);
      }
    }
    return converter;
  }
Ejemplo n.º 4
0
  private void updateModel(int newPage) {

    FacesContext facesContext = getFacesContext();
    UIComponent dataTable = getDataTable();

    if (isRendered(dataTable)) {
      dataTable.getAttributes().put("first", (newPage - 1) * getRows(dataTable));
    }

    Map<String, Object> attributes = dataTable.getAttributes();
    attributes.put(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE, newPage);

    ValueExpression ve = getValueExpression("page");
    if (ve != null) {
      try {
        ve.setValue(facesContext.getELContext(), newPage);
        attributes.remove(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE);
      } catch (ELException e) {
        String messageStr = e.getMessage();
        Throwable result = e.getCause();
        while (null != result && result.getClass().isAssignableFrom(ELException.class)) {
          messageStr = result.getMessage();
          result = result.getCause();
        }
        FacesMessage message;
        if (null == messageStr) {
          message =
              ServiceTracker.getService(MessageFactory.class)
                  .createMessage(
                      facesContext,
                      FacesMessages.UIINPUT_UPDATE,
                      MessageUtil.getLabel(facesContext, this));
        } else {
          message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr);
        }
        facesContext.getExternalContext().log(message.getSummary(), result);
        facesContext.addMessage(getClientId(facesContext), message);
        facesContext.renderResponse();
      } catch (IllegalArgumentException e) {
        FacesMessage message =
            ServiceTracker.getService(MessageFactory.class)
                .createMessage(
                    facesContext,
                    FacesMessages.UIINPUT_UPDATE,
                    MessageUtil.getLabel(facesContext, this));
        facesContext.getExternalContext().log(message.getSummary(), e);
        facesContext.addMessage(getClientId(facesContext), message);
        facesContext.renderResponse();
      } catch (Exception e) {
        FacesMessage message =
            ServiceTracker.getService(MessageFactory.class)
                .createMessage(
                    facesContext,
                    FacesMessages.UIINPUT_UPDATE,
                    MessageUtil.getLabel(facesContext, this));
        facesContext.getExternalContext().log(message.getSummary(), e);
        facesContext.addMessage(getClientId(facesContext), message);
        facesContext.renderResponse();
      }
    }
  }
Ejemplo n.º 5
0
 private MessageFactory getMessageFactory(FacesContext context) {
   return ServiceTracker.getService(MessageFactory.class);
 }
Ejemplo n.º 6
0
 /**
  * This method ensures that component which should be focused will be present in the page in the
  * time of running script (oncomplete).
  */
 public void renderOncompleteScript(FacesContext context, String script) {
   JavaScriptService javaScriptService = ServiceTracker.getService(JavaScriptService.class);
   javaScriptService.addScript(context, new JSLiteral(script));
 }
Ejemplo n.º 7
0
 public void setFocusToSecondInput(ComponentSystemEvent event) {
   FacesContext context = FacesContext.getCurrentInstance();
   FocusManager focusManager = ServiceTracker.getService(context, FocusManager.class);
   focusManager.focus("input2");
 }
Ejemplo n.º 8
0
 public static final SkinFactory getInstance(FacesContext context) {
   return ServiceTracker.getService(context, SkinFactory.class);
 }