public void onSubmit() {
   Note note = getModelObject();
   if (note == null) {
     BugeaterSession sess = (BugeaterSession) Session.get();
     IUserBean userBean = sess.getUserBean();
     if (newStatus == null) {
       // Create a plain ordinary note
       note =
           new Note()
               .setIssue(EditNotePage.this.getModelObject())
               .setText(textModel.getObject())
               .setUserID(userBean.getId());
     } else {
       // Change status with the given note text
       note =
           issueService
               .changeStatus(
                   EditNotePage.this.getModelObject(),
                   userBean,
                   newStatus,
                   textModel.getObject())
               .getNote();
     }
   } else {
     note.setText(textModel.getObject());
   }
   noteService.save(note);
   PageParameters params = new PageParameters();
   params.add(BugeaterConstants.PARAM_NAME_ISSUE_ID, String.valueOf(note.getIssue().getId()));
   setResponsePage(ViewIssuePage.class, params);
 }
  @SuppressWarnings("unchecked")
  public EditNotePage(PageParameters params) {
    super(params);
    if (params.containsKey(BugeaterConstants.PARAM_NAME_NOTE_ID)) {
      try {
        Note note = noteService.load(params.getLong(BugeaterConstants.PARAM_NAME_NOTE_ID));
        init(new IssueModel(note.getIssue()), new NoteModel(note), null);
      } catch (StringValueConversionException svce) {
        throw new IllegalArgumentException(svce);
      }
    } else if (params.containsKey(BugeaterConstants.PARAM_NAME_ISSUE_ID)) {
      try {
        Long issueid = params.getLong(BugeaterConstants.PARAM_NAME_ISSUE_ID);
        IssueStatus newStatus = null;
        if (params.containsKey(BugeaterConstants.PARAM_NAME_ISSUE_STATUS)) {
          try {
            newStatus =
                IssueStatus.fromOrdinal(params.getInt(BugeaterConstants.PARAM_NAME_ISSUE_STATUS));
          } catch (StringValueConversionException svce) {
            throw new IllegalArgumentException(svce);
          }
        }

        init(new IssueModel(issueid), new NoteModel((Long) null), newStatus);
      } catch (StringValueConversionException svce) {
        logger.error(svce);
      }
    } else {
      setResponsePage(Home.class);
    }
  }
  /**
   * Encode a page class target.
   *
   * <p>If you override this method to behave different then also {@link
   * #addBookmarkablePageParameters(Request, RequestParameters)} should be overridden to by in sync
   * with that behaviour.
   *
   * @param requestCycle the current request cycle
   * @param requestTarget the target to encode
   * @return the encoded url
   */
  protected CharSequence encode(
      RequestCycle requestCycle, IBookmarkablePageRequestTarget requestTarget) {
    // Begin encoding URL
    final AppendingStringBuffer url = new AppendingStringBuffer(64);
    url.append(urlPrefix(requestCycle));

    // Get page Class
    final Class pageClass = requestTarget.getPageClass();
    final Application application = Application.get();

    // Find pagemap name
    String pageMapName = requestTarget.getPageMapName();
    if (pageMapName == null) {
      IRequestTarget currentTarget = requestCycle.getRequestTarget();
      if (currentTarget instanceof IPageRequestTarget) {
        Page currentPage = ((IPageRequestTarget) currentTarget).getPage();
        final PageMap pageMap = currentPage.getPageMap();
        if (pageMap.isDefault()) {
          pageMapName = "";
        } else {
          pageMapName = pageMap.getName();
        }
      } else {
        pageMapName = "";
      }
    }

    boolean firstParameter = true;
    if (!application.getHomePage().equals(pageClass)
        || !"".equals(pageMapName)
        || requestTarget instanceof BookmarkableListenerInterfaceRequestTarget) {
      firstParameter = false;
      url.append('?');
      url.append(WebRequestCodingStrategy.BOOKMARKABLE_PAGE_PARAMETER_NAME);
      url.append('=');

      // Add <page-map-name>:<bookmarkable-page-class>
      url.append(pageMapName + Component.PATH_SEPARATOR + pageClass.getName());
    }

    // Is it a bookmarkable interface listener?
    if (requestTarget instanceof BookmarkableListenerInterfaceRequestTarget) {
      BookmarkableListenerInterfaceRequestTarget listenerTarget =
          (BookmarkableListenerInterfaceRequestTarget) requestTarget;
      if (firstParameter == true) {
        url.append("?");
      } else {
        url.append("&");
      }
      firstParameter = false;
      url.append(INTERFACE_PARAMETER_NAME);
      url.append("=");
      url.append(Component.PATH_SEPARATOR);
      url.append(listenerTarget.getComponentPath());
      url.append(Component.PATH_SEPARATOR);
      url.append(Component.PATH_SEPARATOR);
      url.append(listenerTarget.getInterfaceName());
    }

    // Get page parameters
    final PageParameters parameters = requestTarget.getPageParameters();
    if (parameters != null) {
      for (Object element : parameters.keySet()) {
        final String key = (String) element;
        final String value = parameters.getString(key);
        if (value != null) {
          String escapedValue = value;
          try {
            escapedValue =
                URLEncoder.encode(
                    escapedValue,
                    application.getRequestCycleSettings().getResponseRequestEncoding());
          } catch (UnsupportedEncodingException ex) {
            log.error(ex.getMessage(), ex);
          }
          if (!firstParameter) {
            url.append('&');
          } else {
            firstParameter = false;
            url.append('?');
          }
          url.append(key);
          url.append('=');
          url.append(escapedValue);
        }
      }
    }
    return requestCycle.getOriginalResponse().encodeURL(url);
  }