struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@btinternet.com>
Subject RE: tag for the blank string to "&nbsp;" ... performance
Date Thu, 20 Jun 2002 20:56:07 GMT
Alternatively, you could sub-class the struts PresentTag and override the
doStartTag() method to output the &nbsp; if the condition is not true (I
haven't tested it, but see below example).

Then use in the same way as the struts PresentTag ... how clear is that?

  <logic:presentNbsp name="theForm" property="theProp">
      <bean:write name="theForm" property="theProp"/>
  </logic:presentNbsp>


=======================================================================
import javax.servlet.jsp.JspException;
import org.apache.struts.util.ResponseUtils;
public class PresentTagNbsp extends
org.apache.struts.taglib.logic.PresentTag {

    /**
     * Perform the test required for this particular tag, and either
evaluate
     * or output a "&nbsp;"
     *
     * @exception JspException if a JSP exception occurs
     */
    public int doStartTag() throws JspException {

        // Present, output body
        if (condition())
            return (EVAL_BODY_INCLUDE);

        // Not Present, output &nbsp.
        ResponseUtils.write(pageContext, "&nbsp;");

        return (SKIP_BODY);

    }
}
=======================================================================

> -----Original Message-----
> From: emmanuel.boudrant [mailto:b7st@yahoo.fr]
> Sent: 19 June 2002 23:00
> To: Struts Users Mailing List; josephb@hereuare.com
> Subject: RE: tag for the blank string to "&nbsp;" ... performance
>
>
>
>
>
> <jsp:useBean id="theForm" class="xxx.TheFormClass" scope="session"/>
> <td>
>    <% if ( theForm.getTheProp() != null ) { %>
>         <%= theForm.getTheProp() %>
>    <% } else { %>&nbsp;<% } %>
>  </td>
>
> is's more readable ;) ... but scope must be known.
>
>
> -Emmanuel
>
>
>   Joseph Barefoot <josephb@hereuare.com> a écrit :
> >
> > Hi,
> >
> > I've got a simple question, custom tags decrease performance,
> > isn't it ? When using a custom tag, a object is instancied,
> > doStartTag, doEndTag... invoked.
> >
> > so why use a tag for making a simple test ?
>
> 4 reasons:
>
> 1. You are testing for the existence of a property of an
> Attribute, not the
> existence of the attribute itself. See below for the difference.
>
> 2. You are enforcing MVC concepts by limiting logic expressions
> in your JSP
>
> 3. By using the tag with no scope specified, the object with name
> "theForm"
> could be in any scope. Doing it the scriplet way would require
> you to write
> code for a specific scope (request, sesssion, etc.).
>
> 4. The tag is a a helluva lot easier to read than the corresponding
> scriplet (see below).
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > became
> >
> >
> >
> >
> >
> >
>
>
> The above would not have the desired effect. You would have to cast and
> invoke the getter. It would have to be:
>
>
> null ) { %>
>
>
>
>
> Note that this assumes the form bean is in the request. You would have to
> write more code if it could be either session or request scope. Note also
> that you are still invoking a custom tag to ouput the value, so if you're
> trying to eliminate tag overhead it should be:
>
>
> null ) { %>
>
>
>
>
>
> Isn't that fun to read? :):)
>
>
> >
> >
> > -Emmanuel
> >
> > James Mitchell a écrit :
> > DOH!!.....hehehe.....sorry, that's what I meant. (going thru my mail too
> > quickly)
> >
> > James Mitchell
> > Software Engineer\Struts Evangelist
> > Struts-Atlanta, the "Open Minded Developer Network"
> > http://struts-atlanta.open-tools.org
> >
> > > -----Original Message-----
> > > From: Joseph Barefoot [mailto:josephb@hereuare.com]
> > > Sent: Thursday, June 20, 2002 4:02 PM
> > > To: Struts Users Mailing List; Struts-Atlanta@open-tools.org
> > > Subject: RE: tag for the blank string to " "
> > >
> > >
> > > That's what we do, except the " " should be outside the logic tag, or
> > > it won't get ouputted when the property isn't present:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: James Mitchell [mailto:jmitchtx@telocity.com]
> > > > Sent: Wednesday, June 19, 2002 1:03 PM
> > > > To: Struts Users Mailing List
> > > > Subject: RE: tag for the blank string to " "
> > > >
> > > >
> > > > You might be frustrated by the way tables are displayed when a
> > > > is empty
> > > > (especially if you are using stylesheets to format your tables)
> > > >
> > > > Instead of rewriting a bunch tablib to support this, or
> calling helper
> > > > functions, I've overcome this by always adding a in
> > > every like
> > > > this....
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Hope this helps!
> > > >
> > > >
> > > > James Mitchell
> > > > Software Engineer\Struts Evangelist
> > > > Struts-Atlanta, the "Open Minded Developer Network"
> > > > http://struts-atlanta.open-tools.org
> > > >
> > > > > -----Original Message-----
> > > > > From: Cheng, Sophia [mailto:SCheng@arqule.com]
> > > > > Sent: Wednesday, June 19, 2002 2:20 PM
> > > > > To: 'struts-user@jakarta.apache.org'
> > > > > Subject: tag for the blank string to " "
> > > > >
> > > > >
> > > > > Hi,
> > > > > Is there any tag which will write the blank string(null
> > > String or
> > > > > String with length 0) to " " for a form property?
> > > > >
> > > > > Currently I am using logic:notPresent(see below), but I
> > > > > need to do it
> > > > > for many properties. Is there some other way to handle it?
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Thanks in advance.
> > > > >
> > > > > Sophia
> > > > >
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> > > > >
> > > > > For additional commands, e-mail:
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > >
> > > For additional commands, e-mail:
> > >
> > >
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > For additional commands, e-mail:
> >
> >
> >
> > ---------------------------------
> > Yahoo! Mail -- Une adresse @yahoo.fr gratuite et en français !
> >
>
>
> --
> To unsubscribe, e-mail:
> For additional commands, e-mail:
>
>
>
> ---------------------------------
> Yahoo! Mail -- Une adresse @yahoo.fr gratuite et en français !
>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message