Re: AjaxFormLoop Implementation

2014-01-28 Thread George Christman
I wasn't aware you could fix the js error in chrome. I'm still using
firebug, perhaps it's time to make the switch.


On Fri, Jan 24, 2014 at 12:28 PM, Luke Wilson-Mawer 
lukewilsonma...@gmail.com wrote:

 I suspect it could be that it's just breaking javascript but I'm not using
 client side validation and my form updates a zone

 Why not just fix the error in your chrome browser tools and see if your
 validation woes go away?

 On Fri, Jan 24, 2014 at 3:38 PM, George Christman
 gchrist...@cardaddy.comwrote:

  You do make an interesting point, I do remember seeing that JS error when
  adding new rows. I'm wondering if that JS error is breaking clientside
  validation? I do believe there are still other bugs in this component
  unrelated to the JS error.
 
  Luke, since you appear to be using this component, would you mind telling
  me if my configuration is similar to yours? I'm not sure that I'm using
 the
  encoder properly etc. Thank you.
 
 
  On Fri, Jan 24, 2014 at 7:15 AM, Luke Wilson-Mawer 
  lukewilsonma...@gmail.com wrote:
 
   Yes, I noticed a bug in Tap 5.4-beta-2 but it may not be related to
  yours.
  
   The events.zone.didUpdate event isn't triggered when a row is added
  because
   of a javascript error.
  
   From memory the  click event for adding a new element returns
   something like newElement.trigger... when it should be
   $(newElement).trigger(
  
   On Thu, Jan 23, 2014 at 8:15 PM, George Christman
   gchrist...@cardaddy.comwrote:
  
Does anybody else use the AjaxFormLoop? Either I am using it
  incorrectly,
or it is very buggy. I'd like to point out I'm using Tap 5.4-beta-2.
   
Another interesting bug seems to happen when you add a new row and
   provide
a null toValue from the encoder. The row adds without issue, but if
 you
attempt to remove the row before saving, you get an exception. This
behavior worked without issue in 5.3.7. I can provide a temp id if
  that's
whats required to make it work properly.
   
Issue 2, when I have textfield number
 validate=min-length=10,required
   and
I submit the form on a new row with a validation error, the page
  reloads
with a serverside error without highlighting the field, clienside
validation on, the url ends in form rather than the original person
  id.
Now when I fixed the validation error and resubmit it, that's when I
discover the phone has somehow been persisted with a pk despite
  hibernate
save never being called. I am not sure how it's getting it's ID.
 When I
remove the cascade all, it does no persist the phone record. I
  discovered
this issue when I noticed my toValue was failing do to the fact it
 was
trying to do a query against the database for a record that does not
  yet
exist.
   
If the data is correct on a save, the save works perfectly and as
 long
  as
the data has a pk, the remove works perfectly.
   
   
On Wed, Jan 22, 2014 at 11:23 PM, George Christman
gchrist...@cardaddy.comwrote:
   
 Hello, I'm having some difficulties with the AjaxFormLoop component
  and
 I'm hoping one of you guys could help me out.


 For the most part, I've followed the following example

   
  
 
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.htmlhowever
   ,
my implementation needs to be slightly different from the
 example.

 I need to be able to instantiate a new Person() object and before
  ever
 persisting the object be able to add new Phone objects to the
  arraylist
 with the ajaxformloop. Once the user finishes inputting the data,
  then
save
 the changes by submitting the form and commit them all to the
  database.

 Now I'm aware you need to use a value encoder to do this, but I'm
   running
 into an issue where hibernate is trying to save the phone object
   before I
 ever call session.save() which is resulting exceptions.

 I'm hoping someone can provide me with a little help or an example
 of
   how
 to accomplish this task.

 Example code

 div t:type=ajaxformloop t:id=phones source=person.phones
value=phone encoder=encoder
 t:textfield t:id=number value=phone.number/
 t:removerowlinkremove/t:removerowlink
 /div

 public class Edit {

   @PageActivationContext
   @Property
   private Person person;

   @Property
   private Phone phone;

   @Inject
   private Session session;

   public void onPrepare() {
   if(person == null) {
   person = new Person();
   }
   }

   @CommitAfter
   public Object onSuccess() {
   session.saveOrUpdate(person);
   return Index.class;
   }

   Object onAddRowFromPhones() {
   return new Phone();
   }

   @CommitAfter
   void onRemoveRowFromPhones(Phone phone) {
   

Re: AjaxFormLoop Implementation

2014-01-24 Thread Luke Wilson-Mawer
Yes, I noticed a bug in Tap 5.4-beta-2 but it may not be related to yours.

The events.zone.didUpdate event isn't triggered when a row is added because
of a javascript error.

From memory the  click event for adding a new element returns
something like newElement.trigger... when it should be
$(newElement).trigger(

On Thu, Jan 23, 2014 at 8:15 PM, George Christman
gchrist...@cardaddy.comwrote:

 Does anybody else use the AjaxFormLoop? Either I am using it incorrectly,
 or it is very buggy. I'd like to point out I'm using Tap 5.4-beta-2.

 Another interesting bug seems to happen when you add a new row and provide
 a null toValue from the encoder. The row adds without issue, but if you
 attempt to remove the row before saving, you get an exception. This
 behavior worked without issue in 5.3.7. I can provide a temp id if that's
 whats required to make it work properly.

 Issue 2, when I have textfield number validate=min-length=10,required and
 I submit the form on a new row with a validation error, the page reloads
 with a serverside error without highlighting the field, clienside
 validation on, the url ends in form rather than the original person id.
 Now when I fixed the validation error and resubmit it, that's when I
 discover the phone has somehow been persisted with a pk despite hibernate
 save never being called. I am not sure how it's getting it's ID. When I
 remove the cascade all, it does no persist the phone record. I discovered
 this issue when I noticed my toValue was failing do to the fact it was
 trying to do a query against the database for a record that does not yet
 exist.

 If the data is correct on a save, the save works perfectly and as long as
 the data has a pk, the remove works perfectly.


 On Wed, Jan 22, 2014 at 11:23 PM, George Christman
 gchrist...@cardaddy.comwrote:

  Hello, I'm having some difficulties with the AjaxFormLoop component and
  I'm hoping one of you guys could help me out.
 
 
  For the most part, I've followed the following example
 
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.htmlhowever,
 my implementation needs to be slightly different from the
  example.
 
  I need to be able to instantiate a new Person() object and before ever
  persisting the object be able to add new Phone objects to the arraylist
  with the ajaxformloop. Once the user finishes inputting the data, then
 save
  the changes by submitting the form and commit them all to the database.
 
  Now I'm aware you need to use a value encoder to do this, but I'm running
  into an issue where hibernate is trying to save the phone object before I
  ever call session.save() which is resulting exceptions.
 
  I'm hoping someone can provide me with a little help or an example of how
  to accomplish this task.
 
  Example code
 
  div t:type=ajaxformloop t:id=phones source=person.phones
 value=phone encoder=encoder
  t:textfield t:id=number value=phone.number/
  t:removerowlinkremove/t:removerowlink
  /div
 
  public class Edit {
 
@PageActivationContext
@Property
private Person person;
 
@Property
private Phone phone;
 
@Inject
private Session session;
 
public void onPrepare() {
if(person == null) {
person = new Person();
}
}
 
@CommitAfter
public Object onSuccess() {
session.saveOrUpdate(person);
return Index.class;
}
 
Object onAddRowFromPhones() {
return new Phone();
}
 
@CommitAfter
void onRemoveRowFromPhones(Phone phone) {
if(phone.getId() != null) {
session.delete(phone);
}
}
 
@SuppressWarnings(unchecked)
public ValueEncoder getEncoder() {
 
   return new ValueEncoderAccessPoint() {
 
  @Override
  public String toClient(Phone value) {
  Long id = value.getId();
  return id != null ? id.toString() : null;
 
  }
 
  @Override
  public Phone toValue(String toValue) {
  if(toValue != null) {
  System.out.println(toValue);
  Long id = Long.parseLong(toValue);
 
  phone = session.createCritera(Phone.class, id);
  } else {
  person.getPhones().add(phone);
  phone = new Phone(person);
 
  }
  return phone;
  }
  };
  }
  }
 
  @Entity
  public class Person {
 
  @Id
  @GeneratedValue(strategy = GenerationType.auto)
  @NonVisual
  private long id;
 
  @OneToMany(mappedBy = person, cascade = CascadeType.ALL,
 orphanRemoval = true)
  private ListPhone phones;
 
  public ListPhone getPhones() {
  if(phones == null) {
  phones = new ArrayList();
  }
  return phones;
  }
 
  public void setPhones(ListPhone phones) {
  this.phones = 

Re: AjaxFormLoop Implementation

2014-01-24 Thread George Christman
You do make an interesting point, I do remember seeing that JS error when
adding new rows. I'm wondering if that JS error is breaking clientside
validation? I do believe there are still other bugs in this component
unrelated to the JS error.

Luke, since you appear to be using this component, would you mind telling
me if my configuration is similar to yours? I'm not sure that I'm using the
encoder properly etc. Thank you.


On Fri, Jan 24, 2014 at 7:15 AM, Luke Wilson-Mawer 
lukewilsonma...@gmail.com wrote:

 Yes, I noticed a bug in Tap 5.4-beta-2 but it may not be related to yours.

 The events.zone.didUpdate event isn't triggered when a row is added because
 of a javascript error.

 From memory the  click event for adding a new element returns
 something like newElement.trigger... when it should be
 $(newElement).trigger(

 On Thu, Jan 23, 2014 at 8:15 PM, George Christman
 gchrist...@cardaddy.comwrote:

  Does anybody else use the AjaxFormLoop? Either I am using it incorrectly,
  or it is very buggy. I'd like to point out I'm using Tap 5.4-beta-2.
 
  Another interesting bug seems to happen when you add a new row and
 provide
  a null toValue from the encoder. The row adds without issue, but if you
  attempt to remove the row before saving, you get an exception. This
  behavior worked without issue in 5.3.7. I can provide a temp id if that's
  whats required to make it work properly.
 
  Issue 2, when I have textfield number validate=min-length=10,required
 and
  I submit the form on a new row with a validation error, the page reloads
  with a serverside error without highlighting the field, clienside
  validation on, the url ends in form rather than the original person id.
  Now when I fixed the validation error and resubmit it, that's when I
  discover the phone has somehow been persisted with a pk despite hibernate
  save never being called. I am not sure how it's getting it's ID. When I
  remove the cascade all, it does no persist the phone record. I discovered
  this issue when I noticed my toValue was failing do to the fact it was
  trying to do a query against the database for a record that does not yet
  exist.
 
  If the data is correct on a save, the save works perfectly and as long as
  the data has a pk, the remove works perfectly.
 
 
  On Wed, Jan 22, 2014 at 11:23 PM, George Christman
  gchrist...@cardaddy.comwrote:
 
   Hello, I'm having some difficulties with the AjaxFormLoop component and
   I'm hoping one of you guys could help me out.
  
  
   For the most part, I've followed the following example
  
 
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.htmlhowever
 ,
  my implementation needs to be slightly different from the
   example.
  
   I need to be able to instantiate a new Person() object and before ever
   persisting the object be able to add new Phone objects to the arraylist
   with the ajaxformloop. Once the user finishes inputting the data, then
  save
   the changes by submitting the form and commit them all to the database.
  
   Now I'm aware you need to use a value encoder to do this, but I'm
 running
   into an issue where hibernate is trying to save the phone object
 before I
   ever call session.save() which is resulting exceptions.
  
   I'm hoping someone can provide me with a little help or an example of
 how
   to accomplish this task.
  
   Example code
  
   div t:type=ajaxformloop t:id=phones source=person.phones
  value=phone encoder=encoder
   t:textfield t:id=number value=phone.number/
   t:removerowlinkremove/t:removerowlink
   /div
  
   public class Edit {
  
 @PageActivationContext
 @Property
 private Person person;
  
 @Property
 private Phone phone;
  
 @Inject
 private Session session;
  
 public void onPrepare() {
 if(person == null) {
 person = new Person();
 }
 }
  
 @CommitAfter
 public Object onSuccess() {
 session.saveOrUpdate(person);
 return Index.class;
 }
  
 Object onAddRowFromPhones() {
 return new Phone();
 }
  
 @CommitAfter
 void onRemoveRowFromPhones(Phone phone) {
 if(phone.getId() != null) {
 session.delete(phone);
 }
 }
  
 @SuppressWarnings(unchecked)
 public ValueEncoder getEncoder() {
  
return new ValueEncoderAccessPoint() {
  
   @Override
   public String toClient(Phone value) {
   Long id = value.getId();
   return id != null ? id.toString() : null;
  
   }
  
   @Override
   public Phone toValue(String toValue) {
   if(toValue != null) {
   System.out.println(toValue);
   Long id = Long.parseLong(toValue);
  
   phone = session.createCritera(Phone.class, id);
   } else {
   

Re: AjaxFormLoop Implementation

2014-01-24 Thread Luke Wilson-Mawer
I suspect it could be that it's just breaking javascript but I'm not using
client side validation and my form updates a zone

Why not just fix the error in your chrome browser tools and see if your
validation woes go away?

On Fri, Jan 24, 2014 at 3:38 PM, George Christman
gchrist...@cardaddy.comwrote:

 You do make an interesting point, I do remember seeing that JS error when
 adding new rows. I'm wondering if that JS error is breaking clientside
 validation? I do believe there are still other bugs in this component
 unrelated to the JS error.

 Luke, since you appear to be using this component, would you mind telling
 me if my configuration is similar to yours? I'm not sure that I'm using the
 encoder properly etc. Thank you.


 On Fri, Jan 24, 2014 at 7:15 AM, Luke Wilson-Mawer 
 lukewilsonma...@gmail.com wrote:

  Yes, I noticed a bug in Tap 5.4-beta-2 but it may not be related to
 yours.
 
  The events.zone.didUpdate event isn't triggered when a row is added
 because
  of a javascript error.
 
  From memory the  click event for adding a new element returns
  something like newElement.trigger... when it should be
  $(newElement).trigger(
 
  On Thu, Jan 23, 2014 at 8:15 PM, George Christman
  gchrist...@cardaddy.comwrote:
 
   Does anybody else use the AjaxFormLoop? Either I am using it
 incorrectly,
   or it is very buggy. I'd like to point out I'm using Tap 5.4-beta-2.
  
   Another interesting bug seems to happen when you add a new row and
  provide
   a null toValue from the encoder. The row adds without issue, but if you
   attempt to remove the row before saving, you get an exception. This
   behavior worked without issue in 5.3.7. I can provide a temp id if
 that's
   whats required to make it work properly.
  
   Issue 2, when I have textfield number validate=min-length=10,required
  and
   I submit the form on a new row with a validation error, the page
 reloads
   with a serverside error without highlighting the field, clienside
   validation on, the url ends in form rather than the original person
 id.
   Now when I fixed the validation error and resubmit it, that's when I
   discover the phone has somehow been persisted with a pk despite
 hibernate
   save never being called. I am not sure how it's getting it's ID. When I
   remove the cascade all, it does no persist the phone record. I
 discovered
   this issue when I noticed my toValue was failing do to the fact it was
   trying to do a query against the database for a record that does not
 yet
   exist.
  
   If the data is correct on a save, the save works perfectly and as long
 as
   the data has a pk, the remove works perfectly.
  
  
   On Wed, Jan 22, 2014 at 11:23 PM, George Christman
   gchrist...@cardaddy.comwrote:
  
Hello, I'm having some difficulties with the AjaxFormLoop component
 and
I'm hoping one of you guys could help me out.
   
   
For the most part, I've followed the following example
   
  
 
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.htmlhowever
  ,
   my implementation needs to be slightly different from the
example.
   
I need to be able to instantiate a new Person() object and before
 ever
persisting the object be able to add new Phone objects to the
 arraylist
with the ajaxformloop. Once the user finishes inputting the data,
 then
   save
the changes by submitting the form and commit them all to the
 database.
   
Now I'm aware you need to use a value encoder to do this, but I'm
  running
into an issue where hibernate is trying to save the phone object
  before I
ever call session.save() which is resulting exceptions.
   
I'm hoping someone can provide me with a little help or an example of
  how
to accomplish this task.
   
Example code
   
div t:type=ajaxformloop t:id=phones source=person.phones
   value=phone encoder=encoder
t:textfield t:id=number value=phone.number/
t:removerowlinkremove/t:removerowlink
/div
   
public class Edit {
   
  @PageActivationContext
  @Property
  private Person person;
   
  @Property
  private Phone phone;
   
  @Inject
  private Session session;
   
  public void onPrepare() {
  if(person == null) {
  person = new Person();
  }
  }
   
  @CommitAfter
  public Object onSuccess() {
  session.saveOrUpdate(person);
  return Index.class;
  }
   
  Object onAddRowFromPhones() {
  return new Phone();
  }
   
  @CommitAfter
  void onRemoveRowFromPhones(Phone phone) {
  if(phone.getId() != null) {
  session.delete(phone);
  }
  }
   
  @SuppressWarnings(unchecked)
  public ValueEncoder getEncoder() {
   
 return new ValueEncoderAccessPoint() {
   
@Override
public String toClient(Phone value) {
Long id = value.getId();

Re: AjaxFormLoop Implementation

2014-01-23 Thread George Christman
Does anybody else use the AjaxFormLoop? Either I am using it incorrectly,
or it is very buggy. I'd like to point out I'm using Tap 5.4-beta-2.

Another interesting bug seems to happen when you add a new row and provide
a null toValue from the encoder. The row adds without issue, but if you
attempt to remove the row before saving, you get an exception. This
behavior worked without issue in 5.3.7. I can provide a temp id if that's
whats required to make it work properly.

Issue 2, when I have textfield number validate=min-length=10,required and
I submit the form on a new row with a validation error, the page reloads
with a serverside error without highlighting the field, clienside
validation on, the url ends in form rather than the original person id.
Now when I fixed the validation error and resubmit it, that's when I
discover the phone has somehow been persisted with a pk despite hibernate
save never being called. I am not sure how it's getting it's ID. When I
remove the cascade all, it does no persist the phone record. I discovered
this issue when I noticed my toValue was failing do to the fact it was
trying to do a query against the database for a record that does not yet
exist.

If the data is correct on a save, the save works perfectly and as long as
the data has a pk, the remove works perfectly.


On Wed, Jan 22, 2014 at 11:23 PM, George Christman
gchrist...@cardaddy.comwrote:

 Hello, I'm having some difficulties with the AjaxFormLoop component and
 I'm hoping one of you guys could help me out.


 For the most part, I've followed the following example
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.htmlhowever,
  my implementation needs to be slightly different from the
 example.

 I need to be able to instantiate a new Person() object and before ever
 persisting the object be able to add new Phone objects to the arraylist
 with the ajaxformloop. Once the user finishes inputting the data, then save
 the changes by submitting the form and commit them all to the database.

 Now I'm aware you need to use a value encoder to do this, but I'm running
 into an issue where hibernate is trying to save the phone object before I
 ever call session.save() which is resulting exceptions.

 I'm hoping someone can provide me with a little help or an example of how
 to accomplish this task.

 Example code

 div t:type=ajaxformloop t:id=phones source=person.phones value=phone 
 encoder=encoder
 t:textfield t:id=number value=phone.number/
 t:removerowlinkremove/t:removerowlink
 /div

 public class Edit {

   @PageActivationContext
   @Property
   private Person person;

   @Property
   private Phone phone;

   @Inject
   private Session session;

   public void onPrepare() {
   if(person == null) {
   person = new Person();
   }
   }

   @CommitAfter
   public Object onSuccess() {
   session.saveOrUpdate(person);
   return Index.class;
   }

   Object onAddRowFromPhones() {
   return new Phone();
   }

   @CommitAfter
   void onRemoveRowFromPhones(Phone phone) {
   if(phone.getId() != null) {
   session.delete(phone);
   }
   }

   @SuppressWarnings(unchecked)
   public ValueEncoder getEncoder() {

  return new ValueEncoderAccessPoint() {

 @Override
 public String toClient(Phone value) {
 Long id = value.getId();
 return id != null ? id.toString() : null;

 }

 @Override
 public Phone toValue(String toValue) {
 if(toValue != null) {
 System.out.println(toValue);
 Long id = Long.parseLong(toValue);

 phone = session.createCritera(Phone.class, id);
 } else {
 person.getPhones().add(phone);
 phone = new Phone(person);

 }
 return phone;
 }
 };
 }
 }

 @Entity
 public class Person {

 @Id
 @GeneratedValue(strategy = GenerationType.auto)
 @NonVisual
 private long id;

 @OneToMany(mappedBy = person, cascade = CascadeType.ALL, orphanRemoval 
 = true)
 private ListPhone phones;

 public ListPhone getPhones() {
 if(phones == null) {
 phones = new ArrayList();
 }
 return phones;
 }

 public void setPhones(ListPhone phones) {
 this.phones = phones;
 }

 }

 @Entity
 public class Phone {

 @Id
 @GeneratedValue(strategy = GenerationType.auto)
 @NonVisual
 private long id;

 @ManyToOne(optional = false)
 private Person person;

 @Column(nullable = true, length = 20)
 @Width(20)
 @Validate(required,maxlength=20)
 private String number;

 public Phone(Person person) {
 this.person = person;
 }

 //getters and setters

 }

 Thanks in advance.




-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New