Пример #1
0
  /**
   * Returns a url link with query strings on a label.
   *
   * <p>The <tt>linkProperties</tt> string contains name and value pairs of options. The name and
   * value are separated by colon, while each pair is separated by semi-colon.
   *
   * <p>Supported linkProperties are:
   *
   * <ul>
   *   <li>all options specified in <tt>getURL(String actionPath, String options)</tt> method.
   *   <li>noLinkOnEmptyQueryString: if true, no link is added to the label if the query string is
   *       empty.
   *   <li>noLinkOnCurrentUri: if true, no link is added to the label if the current uri is the same
   *       as action path.
   *   <li>confirm: This is the same as "onclick:return confirm('Do you agree?')". A html part like
   *       <tt>onclick="return confirm('Do you agree?');"</tt> will be added to the link.
   *   <li>popup: adds a pop-up window.
   *   <li>many other html and css key attributes--see the <tt>linkKeys</tt> section of the
   *       description of this class.
   * </ul>
   *
   * <p>Examples
   *
   * <pre>
   *      labelLink("Back to Home", "http://www.example.com", "", "confirm:'Do you agree?';id:good")
   *      result link: <a href="http://www.example.com" onclick="return confirm('Do you agree?');" id="good">Back to Home</a>
   *
   *      You can also use this because <tt>onclick</tt> is a key attribute:
   *      labelLink("Back to Home", "http://www.example.com", "", "onclick:return confirm('Do you agree?');id:good")
   *      result link: <a href="http://www.example.com" onclick="return confirm('Do you agree?');" id="good">Back to Home</a>
   *
   *      labelLink("Back to Home", "http://www.example.com", "", "popup:true")
   *      result link: <a href="http://www.example.com" onclick="window.open(this.href);return false;">Back to Home</a>
   *
   *      labelLink("Back to Home", "http://www.example.com", "", "popup:'http://www.google.com','new_window_name','height=440,width=650,resizable,top=200,left=250,scrollbars=yes'")
   *      result link: <a href="http://www.example.com" onclick="window.open('http://www.google.com','new_window_name','height=440,width=650,resizable,top=200,left=250,scrollbars=yes');">Back to Home</a>
   * </pre>
   *
   * @param targetElementId a view element id
   * @param label link label
   * @param actionPath path to an action
   * @param linkProperties map of link related properties
   * @return url link on the label
   */
  public static String labelLink(
      String targetElementId, String label, String actionPath, Map linkProperties) {
    if (linkProperties != null) {
      if ("true".equals(linkProperties.get(W.noLinkOnEmptyQueryString))) {
        String queryString = W.getQueryString(actionPath);
        if (queryString == null || "".equals(queryString.trim())) return label;
      }
    }

    String url = W.getURL(actionPath, linkProperties);

    if (linkProperties != null) {
      String uri = W.getHttpRequest().getRequestURI();
      if ("true".equals(linkProperties.get(W.noLinkOnCurrentUri)) && url.startsWith(uri)) {
        return label;
      }
    }

    return labelLink(targetElementId, label, url, linkProperties, null, null, null);
  }