Ejemplo n.º 1
0
  protected void processDecodes(FacesContext faces, Object argument) {
    if (!this.isRendered()) return;
    this.decode(faces);

    SubmittedValue submittedValue = UIOrderingList.this.submittedValueHolder;
    if (submittedValue != null) {
      Object modelValue = getValue();
      Iterator iterator = submittedValue.dataMap.entrySet().iterator();
      while (iterator.hasNext()) {
        Entry entry = (Entry) iterator.next();
        Object value = entry.getValue();

        if (!isSuitableValue(modelValue, value)) {
          String messageText =
              Messages.getMessage(Messages.INVALID_VALUE, MessageUtil.getLabel(faces, this), value);

          FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageText, null);
          faces.addMessage(this.getClientId(faces), message);

          setValid(false);
          break;
        }
      }
    }

    this.iterate(faces, decodeVisitor, argument);

    if (isImmediate()) {
      executeValidate(faces);
    }

    if (!isValid()) {
      faces.renderResponse();
    }
  }
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);
    }
  }
Ejemplo n.º 3
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();
      }
    }
  }