public void deleteUploadedFile(ActionEvent actionEvent) {

    UICommand uiCommand = (UICommand) actionEvent.getComponent();
    String fileId = (String) uiCommand.getValue();

    try {
      List<UploadedFile> uploadedFiles = htmlInputFileModelBean.getUploadedFiles();

      UploadedFile uploadedFileToDelete = null;

      for (UploadedFile uploadedFile : uploadedFiles) {

        if (uploadedFile.getId().equals(fileId)) {
          uploadedFileToDelete = uploadedFile;

          break;
        }
      }

      if (uploadedFileToDelete != null) {
        uploadedFileToDelete.delete();
        uploadedFiles.remove(uploadedFileToDelete);
        logger.debug("Deleted file=[{0}]", uploadedFileToDelete.getName());
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }
示例#2
0
 /*
  * (non-Javadoc)
  *
  * @see javax.faces.component.UIComponentBase#queueEvent(javax.faces.event.FacesEvent)
  */
 public void queueEvent(FacesEvent event) {
   if (event instanceof ActionEvent) {
     _commandBrige.queueEvent(event);
   } else {
     super.queueEvent(event);
   }
 }
示例#3
0
 /*
  * (non-Javadoc)
  *
  * @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
  */
 public void broadcast(FacesEvent event) throws AbortProcessingException {
   if (event instanceof ActionEvent) {
     _commandBrige.broadcast(event);
   } else {
     super.broadcast(event);
   }
 }
  /* (non-Javadoc)
   * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
   */
  public void setUp() throws Exception {
    super.setUp();

    form = new HtmlForm();
    form.setId("form");
    form2 = new HtmlForm();
    form2.setId("form2");
    facesContext.getViewRoot().getChildren().add(form);
    facesContext.getViewRoot().getChildren().add(form2);

    stp1 = (UISimpleTogglePanel) application.createComponent("org.richfaces.SimpleTogglePanel");
    stp1.setId("simpleTogglePanel1");
    stp1.setOpened(true);
    stp1.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE);

    openMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    openMarker1.setId("openMarker");
    openMarker1.setValue("open");

    closeMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    closeMarker1.setId("closeMarker");
    closeMarker1.setValue("close");

    stp1.getFacets().put(openMarker1.getId(), openMarker1);
    stp1.getFacets().put(closeMarker1.getId(), closeMarker1);
    form.getChildren().add(stp1);

    stp2 = (UISimpleTogglePanel) application.createComponent("org.richfaces.SimpleTogglePanel");
    stp2.setId("simpleTogglePanel2");
    stp2.setOpened(false);
    stp2.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE);

    openMarker2 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    openMarker2.setId("openMarker");
    openMarker2.setValue("open");

    closeMarker2 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    closeMarker2.setId("closeMarker");
    closeMarker2.setValue("close");

    stp2.getFacets().put(openMarker2.getId(), openMarker2);
    stp2.getFacets().put(closeMarker2.getId(), closeMarker2);
    form2.getChildren().add(stp2);

    input = (UIInput) application.createComponent(UIInput.COMPONENT_TYPE);
    input.setValue("");
    input.setId("opened");
    input.getAttributes().put("onchange", "return true;");
    stp1.getChildren().add(input);

    command = new HtmlCommandLink();
    command.setId("command");
    stp1.getChildren().add(command);
  }
示例#5
0
 /*
  * (non-Javadoc)
  *
  * @see javax.faces.component.UIInput#restoreState(javax.faces.context.FacesContext,
  *      java.lang.Object)
  */
 public void restoreState(FacesContext context, Object state) {
   WidgetState componentState = (WidgetState) state;
   super.restoreState(context, componentState.parentState);
   _module = componentState.moduleName;
   _widget = componentState.widgetName;
   _bundleBase = componentState.bundleBasename;
   _bundleName = componentState.bundleName;
   _style = componentState.style;
   _styleClass = componentState.styleClass;
   _layout = componentState.layout;
   _commandBrige.restoreState(context, componentState.commandState);
 }
示例#6
0
 /*
  * (non-Javadoc)
  *
  * @see javax.faces.component.UIInput#saveState(javax.faces.context.FacesContext)
  */
 public Object saveState(FacesContext context) {
   WidgetState state = new WidgetState();
   state.parentState = super.saveState(context);
   state.commandState = _commandBrige.saveState(context);
   state.moduleName = _module;
   state.widgetName = _widget;
   state.bundleBasename = _bundleBase;
   state.bundleName = _bundleName;
   state.style = _style;
   state.styleClass = _styleClass;
   state.layout = _layout;
   return state;
 }
  @Override
  public void queueEvent(FacesEvent event) {
    if (event instanceof ActionEvent) {
      if (event.getComponent() == this) {
        if (isImmediate()) {
          event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
        } else if (isBypassUpdates()) {
          event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
        } else {
          event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        }
      }

      // UICommand set Phase ID for all ActionEvents - bypass it.
      getParent().queueEvent(event);
    } else {
      super.queueEvent(event);
    }
  }
  public static void switchAddEditBaseForm(String formName, boolean isEdit) {

    FacesContext context = FacesContext.getCurrentInstance();

    UICommand btnAdd = (UICommand) context.getViewRoot().findComponent(formName + ":btnAdd");
    UICommand btnUpdate = (UICommand) context.getViewRoot().findComponent(formName + ":btnUpdate");
    UICommand btnCancel = (UICommand) context.getViewRoot().findComponent(formName + ":btnCancel");

    if (btnAdd != null) btnAdd.setRendered(!isEdit);
    btnUpdate.setRendered(isEdit);
    btnCancel.setRendered(isEdit);

    context.renderResponse();
  }
示例#9
0
 /**
  * @return
  * @see javax.faces.component.UICommand#isImmediate()
  */
 public boolean isImmediate() {
   return _commandBrige.isImmediate();
 }
示例#10
0
 public void setActionListener(MethodBinding actionListener) {
   _commandBrige.setActionListener(actionListener);
 }
示例#11
0
 public void setAction(MethodBinding action) {
   _commandBrige.setAction(action);
 }
示例#12
0
 public void removeActionListener(ActionListener listener) {
   _commandBrige.removeActionListener(listener);
 }
示例#13
0
 /** @param action */
 public void setActionExpression(MethodExpression action) {
   _commandBrige.setActionExpression(action);
 }
示例#14
0
 /** @return */
 public MethodExpression getActionExpression() {
   return _commandBrige.getActionExpression();
 }
示例#15
0
 /**
  * @param immediate
  * @see javax.faces.component.UICommand#setImmediate(boolean)
  */
 public void setImmediate(boolean immediate) {
   _commandBrige.setImmediate(immediate);
 }
示例#16
0
 public UIWidget() {
   _commandBrige = new UICommand();
   _commandBrige.setParent(this);
 }
示例#17
0
 public void addActionListener(ActionListener listener) {
   _commandBrige.addActionListener(listener);
 }
示例#18
0
 public MethodBinding getActionListener() {
   return _commandBrige.getActionListener();
 }
示例#19
0
 public ActionListener[] getActionListeners() {
   // TODO Auto-generated method stub
   return _commandBrige.getActionListeners();
 }
示例#20
0
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    javax.faces.component.UICommand command = null;
    try {
      command = (javax.faces.component.UICommand) component;
    } catch (ClassCastException cce) {
      throw new IllegalStateException(
          "Component "
              + component.toString()
              + " not expected type.  Expected: javax.faces.component.UICommand.  Perhaps you're missing a tag?");
    }

    if (action != null) {
      command.setActionExpression(action);
    }
    if (actionListener != null) {
      command.addActionListener(new MethodExpressionActionListener(actionListener));
    }
    if (immediate != null) {
      if (!immediate.isLiteralText()) {
        command.setValueExpression("immediate", immediate);
      } else {
        command.setImmediate(
            java.lang.Boolean.valueOf(immediate.getExpressionString()).booleanValue());
      }
    }
    if (label != null) {
      if (!label.isLiteralText()) {
        command.setValueExpression("label", label);
      } else {
        command.getAttributes().put("label", label.getExpressionString());
      }
    }
    if (oncommand != null) {
      if (!oncommand.isLiteralText()) {
        command.setValueExpression("oncommand", oncommand);
      } else {
        command.getAttributes().put("oncommand", oncommand.getExpressionString());
      }
    }
    if (onclick != null) {
      if (!onclick.isLiteralText()) {
        command.setValueExpression("onclick", onclick);
      } else {
        command.getAttributes().put("onclick", onclick.getExpressionString());
      }
    }
    if (onfocusin != null) {
      if (!onfocusin.isLiteralText()) {
        command.setValueExpression("onfocusin", onfocusin);
      } else {
        command.getAttributes().put("onfocusin", onfocusin.getExpressionString());
      }
    }
    if (onfocusout != null) {
      if (!onfocusout.isLiteralText()) {
        command.setValueExpression("onfocusout", onfocusout);
      } else {
        command.getAttributes().put("onfocusout", onfocusout.getExpressionString());
      }
    }
    if (onmousedown != null) {
      if (!onmousedown.isLiteralText()) {
        command.setValueExpression("onmousedown", onmousedown);
      } else {
        command.getAttributes().put("onmousedown", onmousedown.getExpressionString());
      }
    }
    if (onmousemove != null) {
      if (!onmousemove.isLiteralText()) {
        command.setValueExpression("onmousemove", onmousemove);
      } else {
        command.getAttributes().put("onmousemove", onmousemove.getExpressionString());
      }
    }
    if (onmouseout != null) {
      if (!onmouseout.isLiteralText()) {
        command.setValueExpression("onmouseout", onmouseout);
      } else {
        command.getAttributes().put("onmouseout", onmouseout.getExpressionString());
      }
    }
    if (onmouseover != null) {
      if (!onmouseover.isLiteralText()) {
        command.setValueExpression("onmouseover", onmouseover);
      } else {
        command.getAttributes().put("onmouseover", onmouseover.getExpressionString());
      }
    }
    if (onmouseup != null) {
      if (!onmouseup.isLiteralText()) {
        command.setValueExpression("onmouseup", onmouseup);
      } else {
        command.getAttributes().put("onmouseup", onmouseup.getExpressionString());
      }
    }
    if (style != null) {
      if (!style.isLiteralText()) {
        command.setValueExpression("style", style);
      } else {
        command.getAttributes().put("style", style.getExpressionString());
      }
    }
    if (styleClass != null) {
      if (!styleClass.isLiteralText()) {
        command.setValueExpression("styleClass", styleClass);
      } else {
        command.getAttributes().put("styleClass", styleClass.getExpressionString());
      }
    }
    if (type != null) {
      if (!type.isLiteralText()) {
        command.setValueExpression("type", type);
      } else {
        command.getAttributes().put("type", type.getExpressionString());
      }
    }
    if (value != null) {
      if (!value.isLiteralText()) {
        command.setValueExpression("value", value);
      } else {
        command.setValue(value.getExpressionString());
      }
    }
  }
示例#21
0
 public void getOptions(ActionEvent ae) {
   UICommand command = (UICommand) ae.getComponent();
   fireOptions = (String) options.get(command.getId());
   displayOptions();
 }