This might not be the best solutions (new to wicket/java) but I posted if it might help: This way, I was able to copy the fields and save correctly to my Hibernate POJO.

package com.myapp.wicket;

import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

/**
 *
 * @author hill180
 */
public final class HomePage extends WebPage {
    @SuppressWarnings("unchecked")
    public HomePage() {
        super ();
        Model firstAddress = new Model("test");//Simulated info from DB

        Model secondAddress = new Model("");
        Form form = new Form("form"){

            @Override
            protected void onSubmit() {
                super.onSubmit();//TODO
            }

        };
        form.setOutputMarkupId(true);
TextField textFirstAddress = new TextField("firstAddress", firstAddress);
        textFirstAddress.setOutputMarkupId(true);
TextField textSecondAddress = new TextField("secondAddress", secondAddress);
        textSecondAddress.setOutputMarkupId(true);
        add(form);
        form.add(textFirstAddress);
        form.add(textSecondAddress);
        Label label = new Label("copyAddress", "click here");
        String ajaxFirstAddressName = textFirstAddress.getMarkupId();
        String ajaxSecondAddressName = textSecondAddress.getMarkupId();
        String ajaxFormName = form.getMarkupId();
        label.add(new AttributeAppender("onclick", new Model(
ajaxFormName + "." + ajaxSecondAddressName + ".value = " + ajaxFormName + "." + ajaxFirstAddressName + ".value;"), ";"));
        form.add(label);

    }


}



On Jun 4, 2009, at 5:26 AM, Eyal Golan wrote:

hhhmm...
I'm not a Hibernate expert, but what if your POJO will be detached?

Eyal Golan
[email protected]

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P Save a tree. Please don't print this e-mail unless it's really necessary


On Wed, Jun 3, 2009 at 11:02 PM, hill180 <[email protected]> wrote:

apparently no.

it may just be my understanding.

Because the modal is from a compoundproperty that is a hibernate POJO, this will copy what is in the "database" over, not what is in the field over.

I hope I am explaining myself.

-jose


On Jun 1, 2009, at 8:25 AM, Eyal Golan wrote:

I though more something like this:
AjaxLink link = new AjaxLink("copyAddress"){
            @Override
            public void onClick(AjaxRequestTarget target) {
                this.address2 = this.address1;
               target.addComponent(myAddress2);
            }
        };//end of Link

wouldn't that work?

Eyal Golan
[email protected]

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really
necessary


On Mon, Jun 1, 2009 at 5:31 PM, hill180 <[email protected]> wrote:

AjaxLink link = new AjaxLink("copyAddress"){


            @Override
            public void onClick(AjaxRequestTarget target) {
                myAddress2.setModelObject(myAddress1.getValue());
               target.addComponent(myAddress2);
            }
        };//end of Link


This kinda works. It does update the MyAddress2 Field, but if I change myAddress1 and click on the click, it will get the original value of
myAddress1, not the value inside of the forms textfield.


-jose


On Jun 1, 2009, at 1:48 AM, Eyal Golan wrote:

I'm not sure, but give it a try:

In the onClick, set the property address2 to be the same as property
address1.
Add myAddress2 to the target.

If you use compoundpropertymodel, it should work.

Eyal Golan
[email protected]

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really
necessary


On Mon, Jun 1, 2009 at 12:55 AM, hill180 <[email protected]> wrote:

I have looked through the archives and there were a couple references to

this question but no examples and I was hoping for some help.

I have a form with Address One and Address Two,

I have a link that I just want to copy the data over. I am thinking it
should use Javascript, but I am new to wicket and not sure how to
implement.

The textfields are a compound property model which is hitting a
hibernate
POJO.


private static class AddressPanel extends Panel
    {

      public AddressPanel(String id, Form f,final AssociateDB a)
      {
        super(id);
final TextField myAddress1 = new TextField("Address1"); //
First Address
        add(myAddress1);
final TextField myAddress2 = new TextField("Address2"); //
First Address
           myAddress2.setOutputMarkupId(true);
          add(myAddress2);


      Link link = new Link("copyAddress"){
      @Override
//TODO ADD JAVASCRIPT COPY, FAILS TO SAVE BEFORE COPY OF DATA
      public void onClick() {

      }

      };



  add(link);
      }

    };

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to