• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing single element from NSArray of objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing single element from NSArray of objects


  • Subject: Re: Accessing single element from NSArray of objects
  • From: Jonathan Rochkind <email@hidden>
  • Date: Tue, 13 Apr 2004 14:10:18 -0500

At 2:51 PM -0400 4/13/04, Randall Perry wrote:
Yeah, I tried using lower case but when I added the binding to ResultPage.wo
it made it upper.

I don't understand exactly what you mean, but that makes very little sense. I've never had WOBuilder do that to me---but even if WOBuilder is for some reason messing up horribly like that, so what, don't let it, create the variable/method by hand if you need to.


As for the other code that wouldn't compile, I do not know the overall structure of your code so probably got something wrong. I was just guessing really. Oh, I see, my code wasn't quite right:
EOEnterpriseObject eo = (EOEnterpriseObject) CustInfo.objectAtIndex(0);
   String value =  eo.cust();

Of course, EOEnterpriseObject is the superclass, which does not have a method cust() in it. If you really do have an attribute called 'cust' defined in your model, you _could_ do:
EOEnterpriseObject eo = (EOEnterpriseObject) custInfo.objectAtIndex(0);
String value = (String) eo.valueForKey("cust");


But assuming you are using custom classes for your entities (as is standard), better woudl be more like:
[EntityName] eo = (EntityName) custInfo.objectAtIndex(0);
String value = eo.cust();


Where "[EntityName]" is not what should be there, I'm just using that because I don't know the actual name of your entity.

So there's no shorthand to directly access an object property within an
array of objects? I can do it in one line in perl, php.

I'm not exactly sure what you want to do, but certainly you can directly access an object property within an array of objects within one or two lines of code.

There are a number of things you aren't understanding about Java, about object oriented programming, and about WO.

I again highly reccomend Apple's WO tutorial thing, at:
http://developer.apple.com/documentation/WebObjects/Web_Applications/index.html

--Jonathan

> that
 String value = eo.cust();

 You could provide a method that did that and returned the value, and
 bind to that method in your WOComponent.


Ok, created the following method in ResultPage.java:

public String getCust()
{
   EOEnterpriseObject eo = (EOEnterpriseObject) CustInfo.objectAtIndex(0);
   String value =  eo.cust();
   return value;
   }

When I compile I get the error "Cannot resolve symbol: method cust()"

I also tried:
    String value =  eo.cust;

And got similar error.

So there's no shorthand to directly access an object property within an
array of objects? I can do it in one line in perl, php.



 If you haven't yet, the Apple WO tutorial introduction called I
 think,  "Developing Web Applications", is pretty good and worth a
 read.

 --Jonathan

At 12:11 PM -0400 4/13/04, Randall Perry wrote:
 I've got an NSArray var, custInfo, which fetches an array of objects via a
 direct action:

   custInfo = ec.objectsWithFetchSpecification(fetchSpec);

 It then loads a component page passing the array:

   ResultPage nextPage = (ResultPage) pageWithName("ResultPage");
   nextPage.takeValueForKey(custInfo, "CustInfo");
   return nextPage;

 On ResultPage I can access a single element of all obj arrays by setting
 it's value to a property:
     CustInfo.cust

But, how do I access a property of a single row? I tried this, but it throws
an exception:
CustInfo[0].cust





-- Randall Perry sysTame

Xserve Web Hosting/Co-location
Website Development/Promotion
Mac Consulting/Sales

http://www.systame.com/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Accessing single element from NSArray of objects
      • From: Randall Perry <email@hidden>
References: 
 >Re: Accessing single element from NSArray of objects (From: Randall Perry <email@hidden>)

  • Prev by Date: Re: How can I stream blobs to/from entities?
  • Next by Date: Re: Accessing single element from NSArray of objects
  • Previous by thread: Re: Accessing single element from NSArray of objects
  • Next by thread: Re: Accessing single element from NSArray of objects
  • Index(es):
    • Date
    • Thread