Newbie Question about populating form values

2010-04-14 Thread David Hamilton

I'm a new Wicket using trying to figure out how to populate a form's
initial value with data from a bean (that is in the session already).
I've actually got it working, but I don't think I'm doing the best way.
public final class EmployeeMain extends BasePage {
public EmployeeMain() {
super ();
Form employeeForm=new Form(employeeContactForm);
Contact contact=getEmployeeSession().getEmployee().getEmpInfo();
employeeForm.setModel(new CompoundPropertyModel(contact));
add(new TextField(firstName,new
Model(contact.getFirstName(;
add(new TextField(lastName));

}

My issue is with this line:
add(new TextField(firstName,new Model(contact.getFirstName(;
Should I have to set the model even though I'm binding the form to a
bean has this property?
What is the correct way to handle setting the initial form value from a
bean?

Thanks,

David


Keep it Green! To help protect the environment, please
only print this email if necessary. 
Printing email can cost more than you think. 
Learn more on our website: http://www.hermitagelighting.com/printing_email.php

The information transmitted in this email is 
intended solely for the individual or entity 
to which it is addressed and may contain 
confidential and/or privileged material. 
Any review, retransmission, dissemination or
other use of or taking action in reliance 
upon this information by persons or entities 
other than the intended recipient is prohibited. 
If you have received this email in error please 
immediately notify us by reply email to the sender. 
You must destroy the original material and its contents from any computer. 
 


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Newbie Question about populating form values

2010-04-14 Thread Nikita Tovstoles
If you're using a CPM there's no need to explicitly set models  for child
components. Also think about what you want to happen on page reload.
Generally I'd imagine you want current data, so set CPM's object on
Page.onBeforeRender():

public class EmployeeMain extends BasePage{

final private FormContact employeeForm;

public EmployeeMain()
{
//super(); //no need - call implied
employeeForm = new FormContact(employeeContactForm, new
CompoundpropertyModel(null)); //we'll set model object @ page render time
add(employeeForm);
employeeForm.add(new TextFieldString(firstName)); //assuming existence
of String contact.getFirstName()  method
employeeForm.add(new TextFieldString(lastName));
}

@Override
public void onBeforeRender()
{
employeeForm.setDefaultModelObject(getEmployeeSession().getEmployee().getEmpInfo());
//get up-to-date Contact and set as CPM's object
super.onBeforeRender(); //have to call to allow page children to render
themselves
}

that's it. Note that if you set CPM's object in page constructor, then on
page refresh, Contact won't be updated (because constructor won't run, but
onBeforeRender() will).



On Wed, Apr 14, 2010 at 8:39 AM, David Hamilton 
dhamil...@hermitagelighting.com wrote:


 I'm a new Wicket using trying to figure out how to populate a form's
 initial value with data from a bean (that is in the session already).
 I've actually got it working, but I don't think I'm doing the best way.
 public final class EmployeeMain extends BasePage {
public EmployeeMain() {
super ();
Form employeeForm=new Form(employeeContactForm);
Contact contact=getEmployeeSession().getEmployee().getEmpInfo();
 employeeForm.setModel(new CompoundPropertyModel(contact));
add(new TextField(firstName,new
 Model(contact.getFirstName(;
add(new TextField(lastName));

}

 My issue is with this line:
add(new TextField(firstName,new Model(contact.getFirstName(;
 Should I have to set the model even though I'm binding the form to a
 bean has this property?
 What is the correct way to handle setting the initial form value from a
 bean?

 Thanks,

 David

 
 Keep it Green! To help protect the environment, please
 only print this email if necessary.
 Printing email can cost more than you think.
 Learn more on our website:
 http://www.hermitagelighting.com/printing_email.php

 The information transmitted in this email is
 intended solely for the individual or entity
 to which it is addressed and may contain
 confidential and/or privileged material.
 Any review, retransmission, dissemination or
 other use of or taking action in reliance
 upon this information by persons or entities
 other than the intended recipient is prohibited.
 If you have received this email in error please
 immediately notify us by reply email to the sender.
 You must destroy the original material and its contents from any computer.
 


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Newbie Question about populating form values

2010-04-14 Thread James Carman
Why not use a LoadableDetachableModel instead of setting on onBeforeRender()?

On Wed, Apr 14, 2010 at 12:10 PM, Nikita Tovstoles
nikita.tovsto...@gmail.com wrote:
 If you're using a CPM there's no need to explicitly set models  for child
 components. Also think about what you want to happen on page reload.
 Generally I'd imagine you want current data, so set CPM's object on
 Page.onBeforeRender():

 public class EmployeeMain extends BasePage{

 final private FormContact employeeForm;

 public EmployeeMain()
 {
 //super(); //no need - call implied
 employeeForm = new FormContact(employeeContactForm, new
 CompoundpropertyModel(null)); //we'll set model object @ page render time
 add(employeeForm);
 employeeForm.add(new TextFieldString(firstName)); //assuming existence
 of String contact.getFirstName()  method
 employeeForm.add(new TextFieldString(lastName));
 }

 @Override
 public void onBeforeRender()
 {
 employeeForm.setDefaultModelObject(getEmployeeSession().getEmployee().getEmpInfo());
 //get up-to-date Contact and set as CPM's object
 super.onBeforeRender(); //have to call to allow page children to render
 themselves
 }

 that's it. Note that if you set CPM's object in page constructor, then on
 page refresh, Contact won't be updated (because constructor won't run, but
 onBeforeRender() will).



 On Wed, Apr 14, 2010 at 8:39 AM, David Hamilton 
 dhamil...@hermitagelighting.com wrote:


 I'm a new Wicket using trying to figure out how to populate a form's
 initial value with data from a bean (that is in the session already).
 I've actually got it working, but I don't think I'm doing the best way.
 public final class EmployeeMain extends BasePage {
    public EmployeeMain() {
        super ();
        Form employeeForm=new Form(employeeContactForm);
        Contact contact=getEmployeeSession().getEmployee().getEmpInfo();
 employeeForm.setModel(new CompoundPropertyModel(contact));
        add(new TextField(firstName,new
 Model(contact.getFirstName(;
        add(new TextField(lastName));

    }

 My issue is with this line:
    add(new TextField(firstName,new Model(contact.getFirstName(;
 Should I have to set the model even though I'm binding the form to a
 bean has this property?
 What is the correct way to handle setting the initial form value from a
 bean?

 Thanks,

 David

 
 Keep it Green! To help protect the environment, please
 only print this email if necessary.
 Printing email can cost more than you think.
 Learn more on our website:
 http://www.hermitagelighting.com/printing_email.php

 The information transmitted in this email is
 intended solely for the individual or entity
 to which it is addressed and may contain
 confidential and/or privileged material.
 Any review, retransmission, dissemination or
 other use of or taking action in reliance
 upon this information by persons or entities
 other than the intended recipient is prohibited.
 If you have received this email in error please
 immediately notify us by reply email to the sender.
 You must destroy the original material and its contents from any computer.
 


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Newbie Question about populating form values

2010-04-14 Thread Nikita Tovstoles
Yeah, guess you could do that too, but then you'd have to wrap one model
into another (since LDM does not do property matching like CPM) + you've to
extend LDM.

On Wed, Apr 14, 2010 at 9:24 AM, James Carman
jcar...@carmanconsulting.comwrote:

 Why not use a LoadableDetachableModel instead of setting on
 onBeforeRender()?

 On Wed, Apr 14, 2010 at 12:10 PM, Nikita Tovstoles
 nikita.tovsto...@gmail.com wrote:
  If you're using a CPM there's no need to explicitly set models  for child
  components. Also think about what you want to happen on page reload.
  Generally I'd imagine you want current data, so set CPM's object on
  Page.onBeforeRender():
 
  public class EmployeeMain extends BasePage{
 
  final private FormContact employeeForm;
 
  public EmployeeMain()
  {
  //super(); //no need - call implied
  employeeForm = new FormContact(employeeContactForm, new
  CompoundpropertyModel(null)); //we'll set model object @ page render time
  add(employeeForm);
  employeeForm.add(new TextFieldString(firstName)); //assuming
 existence
  of String contact.getFirstName()  method
  employeeForm.add(new TextFieldString(lastName));
  }
 
  @Override
  public void onBeforeRender()
  {
 
 employeeForm.setDefaultModelObject(getEmployeeSession().getEmployee().getEmpInfo());
  //get up-to-date Contact and set as CPM's object
  super.onBeforeRender(); //have to call to allow page children to render
  themselves
  }
 
  that's it. Note that if you set CPM's object in page constructor, then on
  page refresh, Contact won't be updated (because constructor won't run,
 but
  onBeforeRender() will).
 
 
 
  On Wed, Apr 14, 2010 at 8:39 AM, David Hamilton 
  dhamil...@hermitagelighting.com wrote:
 
 
  I'm a new Wicket using trying to figure out how to populate a form's
  initial value with data from a bean (that is in the session already).
  I've actually got it working, but I don't think I'm doing the best way.
  public final class EmployeeMain extends BasePage {
 public EmployeeMain() {
 super ();
 Form employeeForm=new Form(employeeContactForm);
 Contact contact=getEmployeeSession().getEmployee().getEmpInfo();
  employeeForm.setModel(new CompoundPropertyModel(contact));
 add(new TextField(firstName,new
  Model(contact.getFirstName(;
 add(new TextField(lastName));
 
 }
 
  My issue is with this line:
 add(new TextField(firstName,new Model(contact.getFirstName(;
  Should I have to set the model even though I'm binding the form to a
  bean has this property?
  What is the correct way to handle setting the initial form value from a
  bean?
 
  Thanks,
 
  David
 
  
  Keep it Green! To help protect the environment, please
  only print this email if necessary.
  Printing email can cost more than you think.
  Learn more on our website:
  http://www.hermitagelighting.com/printing_email.php
 
  The information transmitted in this email is
  intended solely for the individual or entity
  to which it is addressed and may contain
  confidential and/or privileged material.
  Any review, retransmission, dissemination or
  other use of or taking action in reliance
  upon this information by persons or entities
  other than the intended recipient is prohibited.
  If you have received this email in error please
  immediately notify us by reply email to the sender.
  You must destroy the original material and its contents from any
 computer.
  
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Newbie Question about populating form values

2010-04-14 Thread James Carman
That's one of the key concepts of Wicket models.

On Wed, Apr 14, 2010 at 2:04 PM, Nikita Tovstoles
nikita.tovsto...@gmail.com wrote:
 Yeah, guess you could do that too, but then you'd have to wrap one model
 into another (since LDM does not do property matching like CPM) + you've to
 extend LDM.

 On Wed, Apr 14, 2010 at 9:24 AM, James Carman
 jcar...@carmanconsulting.comwrote:

 Why not use a LoadableDetachableModel instead of setting on
 onBeforeRender()?

 On Wed, Apr 14, 2010 at 12:10 PM, Nikita Tovstoles
 nikita.tovsto...@gmail.com wrote:
  If you're using a CPM there's no need to explicitly set models  for child
  components. Also think about what you want to happen on page reload.
  Generally I'd imagine you want current data, so set CPM's object on
  Page.onBeforeRender():
 
  public class EmployeeMain extends BasePage{
 
  final private FormContact employeeForm;
 
  public EmployeeMain()
  {
  //super(); //no need - call implied
  employeeForm = new FormContact(employeeContactForm, new
  CompoundpropertyModel(null)); //we'll set model object @ page render time
  add(employeeForm);
  employeeForm.add(new TextFieldString(firstName)); //assuming
 existence
  of String contact.getFirstName()  method
  employeeForm.add(new TextFieldString(lastName));
  }
 
  @Override
  public void onBeforeRender()
  {
 
 employeeForm.setDefaultModelObject(getEmployeeSession().getEmployee().getEmpInfo());
  //get up-to-date Contact and set as CPM's object
  super.onBeforeRender(); //have to call to allow page children to render
  themselves
  }
 
  that's it. Note that if you set CPM's object in page constructor, then on
  page refresh, Contact won't be updated (because constructor won't run,
 but
  onBeforeRender() will).
 
 
 
  On Wed, Apr 14, 2010 at 8:39 AM, David Hamilton 
  dhamil...@hermitagelighting.com wrote:
 
 
  I'm a new Wicket using trying to figure out how to populate a form's
  initial value with data from a bean (that is in the session already).
  I've actually got it working, but I don't think I'm doing the best way.
  public final class EmployeeMain extends BasePage {
     public EmployeeMain() {
         super ();
         Form employeeForm=new Form(employeeContactForm);
         Contact contact=getEmployeeSession().getEmployee().getEmpInfo();
  employeeForm.setModel(new CompoundPropertyModel(contact));
         add(new TextField(firstName,new
  Model(contact.getFirstName(;
         add(new TextField(lastName));
 
     }
 
  My issue is with this line:
     add(new TextField(firstName,new Model(contact.getFirstName(;
  Should I have to set the model even though I'm binding the form to a
  bean has this property?
  What is the correct way to handle setting the initial form value from a
  bean?
 
  Thanks,
 
  David
 
  
  Keep it Green! To help protect the environment, please
  only print this email if necessary.
  Printing email can cost more than you think.
  Learn more on our website:
  http://www.hermitagelighting.com/printing_email.php
 
  The information transmitted in this email is
  intended solely for the individual or entity
  to which it is addressed and may contain
  confidential and/or privileged material.
  Any review, retransmission, dissemination or
  other use of or taking action in reliance
  upon this information by persons or entities
  other than the intended recipient is prohibited.
  If you have received this email in error please
  immediately notify us by reply email to the sender.
  You must destroy the original material and its contents from any
 computer.
  
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org