You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matthew O'Haire <MO...@Trysoft.com> on 2001/03/21 01:17:24 UTC

REPOST: HOW TO: check for null property value

How do I use the logic tags to check for a null property value on a bean and
include/exclude HTML segment on that basis?

I have a bean in the session that holds references to other beans.  If the
references are not-null then I need to display some info about them.  I've
tried using <logic:notEqual property="myBean.item1" value="null"> and
<logic:present name="myBean.item1> but to no avail.

Can anyone help me out here.
Thanks.


Matthew O'Haire
Technical Manager 
email: mohaire@trysoft.com 

IT Project Services & Solutions 
· Development · Integration · Support · People · 
44 Benson Street, Toowong, Queensland, Australia. 4066 
ph: +61-7-3870 7070 
fx: +61-7-3870 3480 
www: http://www.trysoft.com/ 
e-mail: trysoft@trysoft.com 

Please Note:
This document (including attachments) is only intended for the addressee/s
and may contain privileged or confidential information. Unauthorised use,
copying or distribution of the document or any part of its contents, is
prohibited. If you receive this e-mail in error please notify us by return
e-mail or telephone. 
Any views expressed in this Communication are those of the individual
sender, except where the sender specifically states them to be the views of
Trysoft Corporation Limited. 
Except as required at law, Trysoft Corporation Limited does not represent,
warrant and/or guarantee that the integrity of this communication has been
maintained nor that the communication is free of errors, virus, interception
or interference.




Re: 2 newbie questions..

Posted by Jim Richards <gr...@cyber4.org>.
The mapping that is sent to your object has the global mappings,
and the local ones as well.

As for your second question, I'm not sure but the example application
was done very early and it wouldn't surprise me if the class is not
used at all. Have you tried a global search? If it's not used anywhere
then it might be a hang over from earlier iterations of the code.

>    Quick questions from a newbie.. When the mapping is local to a
>particular action, the Action class should call findForward on the mapping
>that's passed in.  But if the mapping is a global one, it should call
>findForward on the instance of ActionServlet (called servlet) that is passed
>down from the parent Action class.  Is this correct?  Or does the
>ActionMapping that's passed in to the perform() method already contain the
>global mappings?  The reason I ask if because I really don't like the idea
>of having access (and having to use) member variables of a parent class.  It
>makes my OO alarms go off.  The example Struts application uses the
>"servlet" object, instead of the ActionMapping instance.

--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html

Re: 2 newbie questions..

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 12 May 2001, Roy Truelove wrote:

> Hey guys,
> 
>     Quick questions from a newbie.. When the mapping is local to a
> particular action, the Action class should call findForward on the mapping
> that's passed in.  But if the mapping is a global one, it should call
> findForward on the instance of ActionServlet (called servlet) that is passed
> down from the parent Action class.  Is this correct?  Or does the
> ActionMapping that's passed in to the perform() method already contain the
> global mappings?  The reason I ask if because I really don't like the idea
> of having access (and having to use) member variables of a parent class.  It
> makes my OO alarms go off.  The example Struts application uses the
> "servlet" object, instead of the ActionMapping instance.
> 

If you call findForward() on the mapping, the implementation will search
first in the local definitions, and then in the global definitions,
without you having to worry about it.  Thus, your Action can always call
mapping.findForward() and not worry about where it's defined.

> Second question has to do with subclassing an ActionMapping class.  As I
> understand it right now, the default ActionMapping class that is passed into
> the perform() method is created using the configuration XML file.  It
> contains the local mappings that are defined in the <action> tag for this
> path (as well as the global mappings?)  This seems to make sense, but in the
> example application, there is a subclass of ActionMapping calling
> ApplicationMapping, with some get / set methods. I can't find where this
> class is used in the application, nor an explaination of it in the
> walk-through or the user-guide.

This class isn't used any more because the standard ActionMapping has
everything that the example app needed.  (I should remove that class to
avoid confusion).  However, earlier this evening I wrote a fairly length
HOWTO response on how to customize ActionMappings to add parameters that
are configured in the struts-config.xml file.  This is a very convenient
way to pass configuration information to an Action.

> 
> Thanks in advance for your help.  I'm trying to fully understand the example
> app before trying struts on my own, and these are a few of my hangups.
> 
> Take it easy,
> Roy
> 
> 
Craig



2 newbie questions..

Posted by Roy Truelove <ro...@pulver.com>.
Hey guys,

    Quick questions from a newbie.. When the mapping is local to a
particular action, the Action class should call findForward on the mapping
that's passed in.  But if the mapping is a global one, it should call
findForward on the instance of ActionServlet (called servlet) that is passed
down from the parent Action class.  Is this correct?  Or does the
ActionMapping that's passed in to the perform() method already contain the
global mappings?  The reason I ask if because I really don't like the idea
of having access (and having to use) member variables of a parent class.  It
makes my OO alarms go off.  The example Struts application uses the
"servlet" object, instead of the ActionMapping instance.

Second question has to do with subclassing an ActionMapping class.  As I
understand it right now, the default ActionMapping class that is passed into
the perform() method is created using the configuration XML file.  It
contains the local mappings that are defined in the <action> tag for this
path (as well as the global mappings?)  This seems to make sense, but in the
example application, there is a subclass of ActionMapping calling
ApplicationMapping, with some get / set methods. I can't find where this
class is used in the application, nor an explaination of it in the
walk-through or the user-guide.

Thanks in advance for your help.  I'm trying to fully understand the example
app before trying struts on my own, and these are a few of my hangups.

Take it easy,
Roy


Re: REPOST: HOW TO: check for null property value

Posted by Ted Husted <hu...@apache.org>.
Try <logic:present name="myBean" property="item1"> 

Matthew O'Haire wrote:
> 
> How do I use the logic tags to check for a null property value on a bean and
> include/exclude HTML segment on that basis?
> 
> I have a bean in the session that holds references to other beans.  If the
> references are not-null then I need to display some info about them.  I've
> tried using <logic:notEqual property="myBean.item1" value="null"> and
> <logic:present name="myBean.item1> but to no avail.
> 
> Can anyone help me out here.
> Thanks.
> 
> Matthew O'Haire
> Technical Manager
> email: mohaire@trysoft.com
> 
> IT Project Services & Solutions
> · Development · Integration · Support · People ·
> 44 Benson Street, Toowong, Queensland, Australia. 4066
> ph: +61-7-3870 7070
> fx: +61-7-3870 3480
> www: http://www.trysoft.com/
> e-mail: trysoft@trysoft.com
> 
> Please Note:
> This document (including attachments) is only intended for the addressee/s
> and may contain privileged or confidential information. Unauthorised use,
> copying or distribution of the document or any part of its contents, is
> prohibited. If you receive this e-mail in error please notify us by return
> e-mail or telephone.
> Any views expressed in this Communication are those of the individual
> sender, except where the sender specifically states them to be the views of
> Trysoft Corporation Limited.
> Except as required at law, Trysoft Corporation Limited does not represent,
> warrant and/or guarantee that the integrity of this communication has been
> maintained nor that the communication is free of errors, virus, interception
> or interference.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

Re: REPOST: HOW TO: check for null property value

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 21 Mar 2001, Matthew O'Haire wrote:

> How do I use the logic tags to check for a null property value on a bean and
> include/exclude HTML segment on that basis?
> 
> I have a bean in the session that holds references to other beans.  If the
> references are not-null then I need to display some info about them.  I've
> tried using <logic:notEqual property="myBean.item1" value="null"> and
> <logic:present name="myBean.item1> but to no avail.
> 

The first thing you tried would compare to the literal string "null",
which is not what you want.  The second test is invalid because the nested
property syntax works only on the "property" attribute, not "name".

If "item1" is the name of your bean property that might return a null
value, try this:

	<logic:present name="myBean" property="item1"/>
	  ... the value is not null ...
	</logic:present>

or

	<logic:notPresent name="myBean" property="item1"/>
	  ... the value is null ...
	</logic:notPresent>


> Can anyone help me out here.
> Thanks.
> 
> 
> Matthew O'Haire
> Technical Manager 
> email: mohaire@trysoft.com 
> 

Craig McClanahan