You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alex Pine <al...@gmail.com> on 2007/08/09 22:21:11 UTC

DateTimeField w/ a CompoundPopertyModel

Hi all,
I am trying to use the DateTimeField from the
org.apache.wicket.extensions.yui.calendar package, and i have run into a
snafu that I can't figure out. When I submit the form, my feedback panel
reacts as if I had not filled it in when I have. I can't figure out why this
happens. Here is what my code looks like:

// package and import statments...

public class MyPage extends BasePage {

// some fields

public MyPage() {
        super();

       MyModelObj pojo = new MyModelObj();

        CompoundPropertyModel model = new CompoundPropertyModel(pojo);
        Form regForm = new RegisterForm("registerForm", model);
        FeedbackPanel feedback = new FeedbackPanel("feedback");

        TextField name = new TextField("name");
        name.setRequired(true);

        DateTimeField startTime = new DateTimeField("startTime");
        startTime.setRequired(true);

        regForm.add(name);
        regForm.add(startTime);

        add(regForm);
        add(feedback);
    }

    class RegisterForm extends Form {

        private static final long serialVersionUID = 1L;

        public ExperimentRegisterForm(String id, CompoundPropertyModel
model) {
            super(id, model);
        }

        @Override
        protected void onSubmit() {

            RecruitSession session = getRecruitSession();
            Experimenter experimenter = (Experimenter) session.getUser();
MyModelObj pojo = (MyModelObj) session.getPojo();
            Experiment experiment = (Experiment) getModelObject();
            experiment.setExperimenter(experimenter);
            experiment.setValid(true);
            experimenter.addExperiment(experiment);
            /**
             * make a detachable model so that the user can use the "back"
             * button without losing everything in the form.
             */
            expModel = new DetachableExperimentModel(experiment,
experimentDAO);

            log.info("Attempting to persist newly created experiment: " +
experiment);

            experimentDAO.persistExperiment(experiment);
            setResponsePage(new ExperimenterHome());
        }
    }



}

Re: DateTimeField w/ a CompoundPopertyModel

Posted by Eelco Hillenius <ee...@gmail.com>.
> So why doesn't the datetimefield bind to the Date obj in MyModelObj? Why
> does the feedback panel tell me it was never filled in?

Thanks for the report. I fixed it after Igor added a quick workaround
and TODO earlier this week.

See https://issues.apache.org/jira/browse/WICKET-839 and
https://issues.apache.org/jira/browse/WICKET-840

Eelco

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


Re: DateTimeField w/ a CompoundPopertyModel

Posted by Alex Pine <al...@gmail.com>.
Sorry, I accidently pressed send somehow before I finished writing down the
relevant code. Here is what I meant to write:

// package and import statments...

public class MyPage extends BasePage {

// some fields

public MyPage() {
        super();

       MyModelObj pojo = new MyModelObj();

        CompoundPropertyModel model = new CompoundPropertyModel(pojo);
        Form regForm = new RegisterForm("registerForm", model);
        FeedbackPanel feedback = new FeedbackPanel("feedback");

        TextField name = new TextField("name");
        name.setRequired(true);

        DateTimeField startTime = new DateTimeField("startTime");
        startTime.setRequired(true);

        regForm.add(name);
        regForm.add(startTime);

        add(regForm);
        add(feedback);
    }

    class RegisterForm extends Form {

        private static final long serialVersionUID = 1L;

        public ExperimentRegisterForm(String id, CompoundPropertyModel
model) {
            super(id, model);
        }

        @Override
        protected void onSubmit() {

            RecruitSession session = getRecruitSession();
            MyModelObj pojo = (MyModelObj) getModelObject();

           //Then persist the pojo object with a hibernate DAO etc etc...
        }
    }
}

Here is the model object code:

public class MyModelObj implements Serializable {

    private String name;

    private Date startTime;

    public Experiment() {

    }

    //The getters and setters
}

And then last but not least the html:

<wicket:extend>
    <span wicket:id="feedback"> Feedback messages go here </span>
    <form class="RegisterForm" wicket:id="registerForm" action="">
    <fieldset><legend>Registration</legend>
    <ol>
        <li>Name <input wicket:id="name" /></li>
        <li>Start Time <span wicket:id="startTime"/></li>
    </ol>
    <input type="submit" value="Register" /></fieldset>
    </form>
</wicket:extend>


So why doesn't the datetimefield bind to the Date obj in MyModelObj? Why
does the feedback panel tell me it was never filled in?

Thanks for any help you can give.

-Alex Pine
alpinesol@gmail.com


On 8/9/07, Alex Pine <al...@gmail.com> wrote:
>
> Hi all,
> I am trying to use the DateTimeField from the
> org.apache.wicket.extensions.yui.calendar package, and i have run into a
> snafu that I can't figure out. When I submit the form, my feedback panel
> reacts as if I had not filled it in when I have. I can't figure out why this
> happens. Here is what my code looks like:
>
> // package and import statments...
>
> public class MyPage extends BasePage {
>
> // some fields
>
> public MyPage() {
>         super();
>
>        MyModelObj pojo = new MyModelObj();
>
>         CompoundPropertyModel model = new CompoundPropertyModel(pojo);
>         Form regForm = new RegisterForm("registerForm", model);
>         FeedbackPanel feedback = new FeedbackPanel("feedback");
>
>         TextField name = new TextField("name");
>         name.setRequired(true);
>
>         DateTimeField startTime = new DateTimeField("startTime");
>         startTime.setRequired(true);
>
>         regForm.add(name);
>         regForm.add(startTime);
>
>         add(regForm);
>         add(feedback);
>     }
>
>     class RegisterForm extends Form {
>
>         private static final long serialVersionUID = 1L;
>
>         public ExperimentRegisterForm(String id, CompoundPropertyModel
> model) {
>             super(id, model);
>         }
>
>         @Override
>         protected void onSubmit() {
>
>             RecruitSession session = getRecruitSession();
>             Experimenter experimenter = (Experimenter) session.getUser();
> MyModelObj pojo = (MyModelObj) session.getPojo();
>             Experiment experiment = (Experiment) getModelObject();
>             experiment.setExperimenter(experimenter);
>             experiment.setValid (true);
>             experimenter.addExperiment(experiment);
>             /**
>              * make a detachable model so that the user can use the "back"
>              * button without losing everything in the form.
>              */
>             expModel = new DetachableExperimentModel(experiment,
> experimentDAO);
>
>             log.info("Attempting to persist newly created experiment: " +
> experiment);
>
>             experimentDAO.persistExperiment(experiment);
>             setResponsePage(new ExperimenterHome());
>         }
>     }
>
>
>
> }
>