[ http://mc4j.org/jira/browse/STS-417?page=comments#action_10805 ] 
            
Frederic Daoud commented on STS-417:
------------------------------------

"What is about..."

<c:if test="${user.allowed}" >
<s:link....></s:link>
</c:if>
<c:if test="${!user.allowed}" >
<span....></span>
</c:if>

That's exactly what enabled="" would be for, so that you do NOT write this kind 
of repetitive code.


> Add boolean 'enabled' (optional) attribute to stripes:link tag
> --------------------------------------------------------------
>
>                 Key: STS-417
>                 URL: http://mc4j.org/jira/browse/STS-417
>             Project: Stripes
>          Issue Type: New Feature
>          Components: Tag Library
>    Affects Versions: Release 1.5
>            Reporter: Frederic Daoud
>         Assigned To: Tim Fennell
>            Priority: Minor
>
> As discussed in this thread:
> http://thread.gmane.org/gmane.comp.java.stripes.user/4612
> I suggest adding a boolean attribute, 'enabled', to the stripes:link tag. 
> This attribute would be optional and true by default. If set to false, the 
> tag renders the body but not the link, such that the link appears as plain 
> text only. This is useful, for example, to enable links based on some dynamic 
> condition, e.g. user rights.
> <stripes:link href="..." enabled="${user.allowed}">Link</stripes:link>
> Very easy to implement, for example, against SVN trunk version 608:
> Index: src/net/sourceforge/stripes/tag/LinkTag.java
> ===================================================================
> --- src/net/sourceforge/stripes/tag/LinkTag.java        (revision 608)
> +++ src/net/sourceforge/stripes/tag/LinkTag.java        (working copy)
> @@ -31,6 +31,7 @@
>   * @author Tim Fennell
>   */
>  public class LinkTag extends LinkTagSupport implements BodyTag {
> +    private boolean enabled = true;
>      /**
>       * Does nothing.
> @@ -62,13 +63,17 @@
>      @Override
>      public int doEndTag() throws JspException {
>          try {
> -            set("href", buildUrl());
> -            writeOpenTag(getPageContext().getOut(), "a");
> +            if (enabled) {
> +                set("href", buildUrl());
> +                writeOpenTag(getPageContext().getOut(), "a");
> +            }
>              String body = getBodyContentAsString();
>              if (body != null) {
>                  getPageContext().getOut().write(body.trim());
>              }
> -            writeCloseTag(getPageContext().getOut(), "a");
> +            if (enabled) {
> +                writeCloseTag(getPageContext().getOut(), "a");
> +            }
>          }
>          catch (IOException ioe) {
>              throw new StripesJspException("IOException while writing output 
> in LinkTag.", ioe);
> @@ -80,6 +85,12 @@
>          return EVAL_PAGE;
>      }
> +    /** Sets the (optional) flag that indicates if the link is enabled. */
> +    public void setEnabled(boolean enabled) { this.enabled = enabled; }
> +
> +    /** Gets the (optional) flag that indicates if the link is enabled. */
> +    public boolean isEnabled() { return enabled; }
> +
>      /** Pass through to [EMAIL PROTECTED] LinkTagSupport#setUrl(String)}. */
>      public void   setHref(String href) { setUrl(href); }
>      /** Pass through to [EMAIL PROTECTED] LinkTagSupport#getUrl()}. */
> Index: resources/stripes.tld
> ===================================================================
> --- resources/stripes.tld       (revision 608)
> +++ resources/stripes.tld       (working copy)
> @@ -807,6 +807,16 @@
>              <type>java.lang.Object</type>
>          </attribute>
>          <attribute>
> +            <description>
> +                An optional flag indicating whether or not the link should 
> be enabled. If set to
> +                false, the link is considered to be disabled, and the link 
> tags will not be
> +                rendered; the link body will be rendered as plain text.
> +                Default value is true.
> +            </description>
> +            
> <name>enabled</name><required>false</required><rtexprvalue>true</rtexprvalue>
> +            <type>boolean</type>
> +        </attribute>
> +        <attribute>
>              <description>The character set used to encode the referenced 
> page. (HTML Pass-through)</description>
>              
> <name>charset</name><required>false</required><rtexprvalue>true</rtexprvalue>
>          </attribute>
> What do you think?
> Thanks,
> Freddy

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to