RE: getChildren().iterator() problem
I usually prefer the while-loop for this kind of operation: Iterator kids = myComponent.getChildren().iterator(); while (kids.hasNext()) { UIComponent child = (UIComponent)kids.next(); ... } hth Alexander From: arti [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 12:25 PMTo: MyFaces DiscussionSubject: getChildren().iterator() problem Hi, I am facing a problem withgetChildren().iterator(). (using getChildren().listIterator()works perfect) Why? My custom table component has just one child column element in it. But still the iterator obtained as mentioned above,enters the following loop twice and second time throws NullPointerException Iterator kids = myComponent.getChildren().iterator(); if (kids.hasnext()) { do { UICompoment child = kids.next(); // this line throws NullPointerException when executed second time in loop /* some code here */ } while (kids.hasnext()); } Thanks Arti
Re: getChildren().iterator() problem
Better approach is to use for loop. for (Iterator kids = myComponent.getChildren().iterator(); kids.hasNext();) { UIComponent child = (UIComponent)kids.next(); ... } On 4/21/06, Jesse Alexander (KSFD 121) [EMAIL PROTECTED] wrote: I usually prefer the while-loop for this kind of operation: Iterator kids = myComponent.getChildren().iterator(); while (kids.hasNext()) { UIComponent child = (UIComponent)kids.next(); ... } hth Alexander From: arti [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 12:25 PM To: MyFaces Discussion Subject: getChildren().iterator() problem Hi, I am facing a problem with getChildren().iterator(). (using getChildren().listIterator() works perfect) Why? My custom table component has just one child column element in it. But still the iterator obtained as mentioned above, enters the following loop twice and second time throws NullPointerException Iterator kids = myComponent.getChildren().iterator(); if (kids.hasnext()) { do { UICompoment child = kids.next();// this line throws NullPointerException when executed second time in loop /* some code here */ } while (kids.hasnext()); } Thanks Arti
RE: getChildren().iterator() problem
No offense guys, but the for and while loop approach is identical. I use the for loop, but it gets compiled into the same jvm code. Looking at the original do/while code, it looks ok. I'd be surprised if the for approach works, but it's probably worth a shot since it will only take a couple of minutes to try... Frank Russo Senior Developer FX Alliance, LLC -Original Message- From: Raj Saini [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 8:03 AM To: MyFaces Discussion Subject: Re: getChildren().iterator() problem Better approach is to use for loop. for (Iterator kids = myComponent.getChildren().iterator(); kids.hasNext();) { UIComponent child = (UIComponent)kids.next(); ... } On 4/21/06, Jesse Alexander (KSFD 121) [EMAIL PROTECTED] wrote: I usually prefer the while-loop for this kind of operation: Iterator kids = myComponent.getChildren().iterator(); while (kids.hasNext()) { UIComponent child = (UIComponent)kids.next(); ... } hth Alexander From: arti [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 12:25 PM To: MyFaces Discussion Subject: getChildren().iterator() problem Hi, I am facing a problem with getChildren().iterator(). (using getChildren().listIterator() works perfect) Why? My custom table component has just one child column element in it. But still the iterator obtained as mentioned above, enters the following loop twice and second time throws NullPointerException Iterator kids = myComponent.getChildren().iterator(); if (kids.hasnext()) { do { UICompoment child = kids.next();// this line throws NullPointerException when executed second time in loop /* some code here */ } while (kids.hasnext()); } Thanks Arti
RE: getChildren().iterator() problem
Hi It did not work with both solutions suggested. I removed if statement and tried with both for loop and while loop as suggested, but iterator() method does not work. It still goes into the loop for second child and throws NullPointerException. Thanks Arti -Original Message- From: Raj Saini [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 2:03 PM To: MyFaces Discussion Subject: Re: getChildren().iterator() problem Better approach is to use for loop. for (Iterator kids = myComponent.getChildren().iterator(); kids.hasNext();) { UIComponent child = (UIComponent)kids.next(); ... } On 4/21/06, Jesse Alexander (KSFD 121) [EMAIL PROTECTED] wrote: I usually prefer the while-loop for this kind of operation: Iterator kids = myComponent.getChildren().iterator(); while (kids.hasNext()) { UIComponent child = (UIComponent)kids.next(); ... } hth Alexander From: arti [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 12:25 PM To: MyFaces Discussion Subject: getChildren().iterator() problem Hi, I am facing a problem with getChildren().iterator(). (using getChildren().listIterator() works perfect) Why? My custom table component has just one child column element in it. But still the iterator obtained as mentioned above, enters the following loop twice and second time throws NullPointerException Iterator kids = myComponent.getChildren().iterator(); if (kids.hasnext()) { do { UICompoment child = kids.next();// this line throws NullPointerException when executed second time in loop /* some code here */ } while (kids.hasnext()); } Thanks Arti