/**
   * if TRANSFER_FUND_PARAMETER is a parameter, them doTransfer is invoked. doTranser presents the
   * web content to confirm and then execute a simulated transfer of funds. An initial request
   * should have a dollar amount specified. The amount will be stored and a confirmation form is
   * presented. The confirmation can be canceled or confirmed. Confirming the transfer will mark
   * this lesson as completed.
   *
   * @param s
   * @return Element will appropriate web content for a transfer of funds.
   */
  protected Element doTransfer(WebSession s) {
    String transferFunds =
        HtmlEncoder.encode(s.getParser().getRawParameter(TRANSFER_FUNDS_PARAMETER, ""));
    ElementContainer ec = new ElementContainer();

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

      HttpSession httpSession = s.getRequest().getSession();
      Integer transferAmount = (Integer) httpSession.getAttribute(TRANSFER_FUND_AMOUNT_ATTRIBUTE);

      if (transferFunds.equalsIgnoreCase(TRANSFER_FUNDS_PAGE)) {

        // present transfer form
        ec.addElement(new H1("Electronic Transfer:"));
        String action = getLink();
        Form form = new Form(action, Form.POST);
        form.addElement(new Input(Input.text, TRANSFER_FUNDS_PARAMETER, "0"));
        // if this token is present we won't mark the lesson as completed
        form.addElement(new Input(Input.submit));
        ec.addElement(form);

      } else if (transferFunds.equalsIgnoreCase(CONFIRM_TRANFER) && transferAmount != null) {

        // transfer is confirmed
        ec.addElement(new H1("Electronic Transfer Complete"));
        ec.addElement(new StringElement("Amount Transfered: " + transferAmount));
        makeSuccess(s);

      } else if (transferFunds.equalsIgnoreCase(CANCEL_TRANSFER)) {

        // clear any pending fund transfer
        s.getRequest().removeAttribute(TRANSFER_FUND_AMOUNT_ATTRIBUTE);

      } else if (transferFunds.length() > 0) {

        // save the transfer amount in the session
        transferAmount = new Integer(transferFunds);
        httpSession.setAttribute(TRANSFER_FUND_AMOUNT_ATTRIBUTE, transferAmount);

        // prompt for confirmation

        ec.addElement(new H1("Electronic Transfer Confirmation:"));
        ec.addElement(new StringElement("Amount to transfer: " + transferAmount));
        ec.addElement(new BR());
        String action = getLink();
        Form form = new Form(action, Form.POST);
        form.addElement(new Input(Input.submit, TRANSFER_FUNDS_PARAMETER, CONFIRM_TRANFER));
        form.addElement(new Input(Input.submit, TRANSFER_FUNDS_PARAMETER, CANCEL_TRANSFER));
        ec.addElement(form);
      }
    }
    // white space
    ec.addElement(new BR());
    ec.addElement(new BR());
    ec.addElement(new BR());
    return ec;
  }
Beispiel #2
0
  public void setup(WebSession s) {
    // call createContent first so messages will go somewhere

    Form form = new Form("attack", Form.POST).setName("form").setEncType("");

    form.addElement(wrapForm(s));

    TD lowerright = new TD().setHeight("100%").setVAlign("top").setAlign("left").addElement(form);
    TR row = new TR().addElement(lowerright);
    Table layout =
        new Table().setBgColor(HtmlColor.WHITE).setCellSpacing(0).setCellPadding(0).setBorder(0);

    layout.addElement(row);

    setContent(layout);
  }