You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jerzy Kalat <jk...@home.com> on 2001/06/08 17:09:39 UTC

Nested property error ?!?

Hi,

I am new to Struts technology, so forgive me if I not see something obvious here.

Based on e-Commerece example from Wrox book, I have created form to maintain organization, which suppose to behave like SQL Form. So I have browsing keys, Update, Insert, Delete and other keys. Right now I have no access to database, so I used Struts database utility and store collection of records. 

Everything is working fine, I can see and navigate between records, I can update or delete them.

The problem starts when I try to simulate retrieving of not all records but records based on some criteria entered in the form. In Action servlet I wrote:

 OrganizationForm orgForm = (OrganizationForm)form;
 Organization orgFromForm = orgForm.getOrganization();
......
 HashMap orgTable = 
         (HashMap) servletContext.getAttribute(Constants.ORGANIZATION_TABLE_KEY);

 if(orgTable == null) {
         errors.add(ActionErrors.GLOBAL_ERROR,
            new ActionError("error.orgTable.missing"));
 } else {
        int size = orgTable.size();
   
orgForm.setTotal(size);
    
 if(size > 0) {
    int i = 1;
    Iterator iterator = orgTable.values().iterator();
    Organization[] orgArray = new Organization[size+1];
    Organization anOrg = null;
    while(iterator.hasNext()) {
             anOrg = (Organization)iterator.next();
             if( "Query".equals(mode) && "Retrieve".equals(action)) {
             if( orgForm.matches(anOrg))
                orgArray[i++] = anOrg;
             } else {
                orgArray[i++] = anOrg;
    }
}

So, for every record from otgArray, I want to compare city of address of organization with
city field from the form.

In OrganizationForm.java I create method:


public boolean matches( Organization org )
{

System.out.println("FORM=" + this.organization );
System.out.println("COLL=" + org );

  if ( this.organization != null && this.organization.getAddress() != null && 
       this.organization.getAddress().getCity() != null ) {
          String cityFromForm = this.organization.getAddress().getCity();
       if ( org != null && org.getAddress() != null && org.getAddress().getCity() != null ) {
         String cityFromCollection = org.getAddress().getCity();
         System.out.println("COMPARE " + cityFromCollection + " WITH " + cityFromForm );
         if( cityFromCollection.equals( cityFromForm )) 
           return true;
         else 
           return false;  
       }
       return false;  
  }
  return true;  // no selection provided
}     


If I call this method I have error:
javax.servlet.ServletException: Null property value for 'organization'
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459) 
...

Root cause: 
java.lang.IllegalArgumentException: Null property value for 'organization'
	at org.apache.struts.util.PropertyUtils.getNestedProperty(PropertyUtils.java:347)
If I comment out if statements from this method, I can see BOTH records: FORM=... and COLL=...  with proper atribute values. So WHY I CANNOT COMPARE THEM?Can anybody help me with what I do wrong?    Thanks in advance,    Jerzy Kalat


Re: Nested property error - resolved

Posted by Jerzy Kalat <jk...@home.com>.
Hi,

It was something obvious :-)

    JK
  ----- Original Message ----- 
  From: Jerzy Kalat 
  To: struts-user@jakarta.apache.org 
  Sent: Friday, June 08, 2001 11:09 AM
  Subject: Nested property error ?!?


  Hi,

  I am new to Struts technology, so forgive me if I not see something obvious here.

  Based on e-Commerece example from Wrox book, I have created form to maintain organization, which suppose to behave like SQL Form. So I have browsing keys, Update, Insert, Delete and other keys. Right now I have no access to database, so I used Struts database utility and store collection of records. 

  Everything is working fine, I can see and navigate between records, I can update or delete them.

  The problem starts when I try to simulate retrieving of not all records but records based on some criteria entered in the form. In Action servlet I wrote:

   OrganizationForm orgForm = (OrganizationForm)form;
   Organization orgFromForm = orgForm.getOrganization();
  ......
   HashMap orgTable = 
           (HashMap) servletContext.getAttribute(Constants.ORGANIZATION_TABLE_KEY);

   if(orgTable == null) {
           errors.add(ActionErrors.GLOBAL_ERROR,
              new ActionError("error.orgTable.missing"));
   } else {
          int size = orgTable.size();
     
  orgForm.setTotal(size);
      
  if(size > 0) {
      int i = 1;
      Iterator iterator = orgTable.values().iterator();
      Organization[] orgArray = new Organization[size+1];
      Organization anOrg = null;
      while(iterator.hasNext()) {
               anOrg = (Organization)iterator.next();
               if( "Query".equals(mode) && "Retrieve".equals(action)) {
               if( orgForm.matches(anOrg))
                  orgArray[i++] = anOrg;
               } else {
                  orgArray[i++] = anOrg;
      }
  }

  So, for every record from otgArray, I want to compare city of address of organization with
  city field from the form.

  In OrganizationForm.java I create method:


  public boolean matches( Organization org )
  {

  System.out.println("FORM=" + this.organization );
  System.out.println("COLL=" + org );

    if ( this.organization != null && this.organization.getAddress() != null && 
         this.organization.getAddress().getCity() != null ) {
            String cityFromForm = this.organization.getAddress().getCity();
         if ( org != null && org.getAddress() != null && org.getAddress().getCity() != null ) {
           String cityFromCollection = org.getAddress().getCity();
           System.out.println("COMPARE " + cityFromCollection + " WITH " + cityFromForm );
           if( cityFromCollection.equals( cityFromForm )) 
             return true;
           else 
             return false;  
         }
         return false;  
    }
    return true;  // no selection provided
  }     


  If I call this method I have error:
  javax.servlet.ServletException: Null property value for 'organization'
  at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459) 
  ...

  Root cause: 
java.lang.IllegalArgumentException: Null property value for 'organization'
	at org.apache.struts.util.PropertyUtils.getNestedProperty(PropertyUtils.java:347)
If I comment out if statements from this method, I can see BOTH records: FORM=... and COLL=...  with proper atribute values. So WHY I CANNOT COMPARE THEM? Can anybody help me with what I do wrong?     Thanks in advance,     Jerzy Kalat