Thanks, Ajay!

-----Original Message-----
From: Ajay Chitre [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, May 01, 2002 10:43 PM
To: Struts Users Mailing List
Subject: RE: How to access nested properties which may be null?

David,

Here's a trick I learned by looking at one of Craig's sample JSPs.

In the getAuthorityLevel() method in User bean check if authorityLevel is
null.  If it is, return a new instance of it.  This should fix the problem
- I think.

For example;

In User.java:

    public AuthorityLevel getAuthorityLevel () {
        
        if (authorityLevel == null) {
            authorityLevel = new AuthorityLevel();
        }
        
        return authorityLevel ;
    }


Just an idea.  I am curious to find out how others are dealing with this
problem.

HTH!

>-- Original Message --
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>From: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Subject: RE: How to access nested properties which may be null?
>Date: Wed, 1 May 2002 16:41:02 -0700 
>
>
>That's sound design advice, and I certainly may end up doing that.  I guess
>right now I'm more interested in finding out if there's a Struts way to
do
>this, in order to understand all the facets of Struts better.
>
>Cheers,
>David
>
>-----Original Message-----
>From: Struts Newsgroup [mailto:[EMAIL PROTECTED]] 
>Sent: Wednesday, May 01, 2002 3:55 PM
>To: [EMAIL PROTECTED]
>Subject: Re: How to access nested properties which may be null?
>
>Subject: Re: How to access nested properties which may be null?
>From: Vic Cekvenich <[EMAIL PROTECTED]>
> ===
>It might be that you are doing a bit more in JSP than you should.
>More should be done in the model. In action, you should check conditions.
>Vic
>
>[EMAIL PROTECTED] wrote:
>> Hello,
>> 
>>  
>> 
>> How do I use, say, the <bean:write> tag to print out the value of a
nested
>> property, if there's a possibility that the parent of the nested property
>> may be Null?
>> 
>>  
>> 
>> I have a User bean with method getAuthorityLevel which returns an
instance
>> of the AuthorityLevel bean.  The AuthorityLevel bean then has a method
>> getName, which returns a string.  I have something like this in my JSP:
>> 
>>  
>> 
>> <bean:write name="myUser" property="authorityLevel.name"/>
>> 
>>  
>> 
>> This works fine if the User bean in the "myUser" variable has an
>> AuthorityLevel, but if it does not then getAuthorityLevel returns Null,
>and
>> Struts then throws a NullPointerException.  Is there a simple way around
>> this?
>> 
>>  
>> 
>> Do the "Nested Tags" address this situation?
>> 
>>  
>> 
>> Thanks!
>> 
>> David
>> 
>>  
>> 
>> David A. Ventimiglia
>> 
>> Wells Fargo Private Client Services
>> 
>> (415) 396-0414 (work)
>> 
>>  
>> 
>> 
>
>
>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>--
>To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to