No idea? Anybody?

On Tue, 3 Jul 2012 22:50:04 +0200
Andre Schütz <[email protected]> wrote:

> Hello,
> 
> here is an abstract code example of my problem with my application.
> 
> ####################
> # StartPage
> ####################
> class StartPage extends WebPage {
>   public StartPage(PageParameters parameters) {
>     add(new SearchForm("searchForm", parameters));
>   }
> 
>   private class SearchForm extends StatelessForm {
>     public SearchForm(String id, final PageParameters params) {
>       super(id);
>       init();
>     }
> 
>     private void init() {
>       Button startButton = new Button("button_search") {
>         @Override
>         public void onSubmit() {
>           PageParamerters p = new PageParameters();
>           // some additional checks with the parameters
>           ....
>           setResponsePage(MyFormPage.class, p);
>         }
>       }
>     }
>   }
> }
> 
> #################
> # MyFormPage
> #################
> class MyFormPage extends WebPage {
>   public MyFormPage(PageParameters parameters) {
>     super(parameters);
>     Model<MySearchModel> model = new Model<MySearchModel>() {
>       MySearchModel msm = new MySearchModel();
> 
>       @Override
>       public MySearchModel getObject() {
>         return msm;
>       }
>   
>       @Override
>       public void setObject(MySearchModel newModel) {
>         this.msm = newModel;
>       }
>     }
> 
>     CompundPropertyModel<MySearchModel> cpm = new 
> CompoundPropertyModel<MySearchModel>(model);
>     add(new AdvancedSearchForm("asForm", cpm));
>   }
> 
>   private class AdvancedSearchForm extends StatelessForm<MySearchModel> {
>     private String name = null;
> 
>     public AdvancedSearchForm (String id, IModel<MySearchModel> model) {
>       super(id, model);
>       init(model);
>     }
> 
>     private void init(IModel<MySearchModel> model) {
>       IModel<List<String>> classes = new 
> LoadableDetachableModel<List<String>>() {
>         @Override
>         public List<String> load() {
>           List<String> classes = HelperClass.getClasses();
>           Collections.sort(classes);
>           return classes;
>         }
>       }
> 
>       IChoiceRenderer<Object> rendererClasses = new IChoiceRenderer<Object>() 
> {
>         public Object getDisplayValue(Object obj) {
>           return obj;
>         }
> 
>         public String getIdValue(Object obj, int index) {
>           return obj.toString();
>         }
>       };
>       CheckBoxMultipleChoice<String> classesChoice =
>                     new CheckBoxMultipleChoice<String>("classes",
>                             classes,
>                             rendererClasses);
>       add(classesChoice);
> 
>       TextField<String> tf = new TextField<String>("name", new 
> PropertyModel<String>(this, "name"));
>       add(tf);
> 
>       add(new Button("searchbutton_search") {
>         @Override
>         public void onSubmit() {
>           makeSubmit();
>         }
>       });
>     }
> 
>     /**
>      * Do the submit and got to the response page
>      */
>     private void makeSubmit() {
>       MySession s = (MySession)getSession();
>       MySearchModel modelObject = this.getModelObject();
> 
>       if (!s.mySearchModelExists(modelObject.hashCode())) {
>         s.setMySearchModel(modelObject);
>       }
> 
>       PageParameters p = new PageParameters();
>       // following method creates parameters from the model
>       p = MyParameterHelper.preparePageParameters(p, modelObject);
>       setResponsePage(MyFinalPage.class, p);
>     }
>   }
> }
> 
> ####################
> # MySearchModel
> ####################
> 
> public class SearchModel implements Serializable {
>   private String name = null;
>   private List<String> classes = null;
> 
>   public void setName(String newName) {
>     name = newName;
>   }
> 
>   public void setClasses(List<String> newClasses) {
>     classes = newClasses;
>   }
> 
>   public String getName() {
>     return name;
>   }
> 
>   public List<String> getClasses() {
>     return classes;
>   }
> }
> 
> The process:
> 
> (0) I open the Opera Browser.
> (1) I click on the button of the StatelessForm (SearchForm) in the StartPage 
> class.
> (2) The MyFormPage site is displayed.
> (3) I select some classes and click the button in the AdvancedSearchForm.
> (4) The MyFinalPage site is displayed.
> (5) I open the Firefox Browser.
> (6) I see the StartPage and click the button in the SearchForm.
> (7) The MyFormPage is displayed and the classes from step (3) are selected.
> (8) Additionally, I added a System.out.println(model.toString) before the 
> line:
> CompundPropertyModel<MySearchModel> cpm = new 
> CompoundPropertyModel<MySearchModel>(model);
> and looked into the Catalino.out logs. You can see that this is directly 
> after the
> initilization of the: Model<MySearchModel> model = new Model<MySearchModel>()
> -> the logs tell me that the classes from step (3) are in the model
> => You can see in the model above that the classes are initialized with null.
> 
> Puh.
> This is my problem. I hope that this code example gives a good imagination
> of my problem.
> I do not know why the classes from step 3 are in the model after a new 
> initialization.
> 
> I would be very thankful for a solution.
> 
> Thanks,
> Andre
> 
> 
> 
> 
> 
> On Tue, 3 Jul 2012 20:16:13 +0200
> Andre Schütz <[email protected]> wrote:
> 
> > There is one important information that I had forgotten to
> > mention. The link on my start page is not a link. It is a button
> > from within a form.
> > 
> > Andre
> > 
> > On Tue,  3 Jul 2012 11:41:36 +0200 (CEST)
> > [email protected] wrote:
> > 
> > > Hello,
> > > 
> > > thanks for the answers. At the moment I am not able to access my code but 
> > > let
> > > me explain the code in detail and give you some additional examples. I 
> > > think
> > > the idea with the stateful behavior could be right but I do not 
> > > understand the 
> > > reason.
> > > 
> > > In detail.
> > > 
> > > - I have a starting page where a Link is constructed that depending on 
> > > the available
> > > PageParameters links to the second page with or without PageParameters:
> > > 
> > > p.. PageParameters
> > > 
> > > setResponsePage(MyPage2.class, p) or setResponsePage(MyPage2.class) or 
> > > 
> > > - After clicking the link on the starting page, the MyPage2 will be 
> > > opened and 
> > > the constructor adds the elements to the page. A Form will be added and 
> > > gets 
> > > a Model that is created in the constructor:
> > > 
> > > MyModel model = new MyModel();
> > > 
> > > The MyModel has two fields. 
> > > class MyModel {
> > >   private String text;
> > >   private List<String> classes;
> > >   public void setText ..
> > >   public void setClasses...
> > >   public String getText ...
> > >   public List<String> getClasses...
> > > }
> > > 
> > > The "classes" field is pre-filled with 3 entries in the MyModel class.
> > > 
> > > Before the end of the constructor, my Form is added with:
> > > add(new MyForm("id", new CompoundPropertyModel(model)));
> > > 
> > > When I submit the form, the MyPage3 is opened and the values from
> > > the MyForm are used.
> > > 
> > > When I click back to my starting page and click on the link to MyPage2,
> > > the selected values from the first click to this page are filled in the
> > > MyModel. I printed the values of MyModel directly after the line:
> > > MyModel model = new MyModel()
> > > Normally, the pre-filled values should be in the classes variable. BUT 
> > > ... 
> > > I have the selected values from the first call of the MyPage2.
> > > That's my miracle :)
> > > 
> > > Thanks for any additional help
> > > Andre
> > > 
> > > ----- Original Message -----
> > > From: [email protected]
> > > To: [email protected]
> > > Date: 03.07.2012 07:44:54
> > > Subject: Re: Model is not created
> > > 
> > > 
> > > > On Mon, Jul 2, 2012 at 11:45 PM, Andre Schütz <[email protected]> wrote:
> > > >> Hello,
> > > >> 
> > > >> I have a problem with the creation of a model in one of my pages.
> > > >> It works as follows:
> > > >> 
> > > >> I have a link that uses setResponsePage(new MyPage(parameters)) on the 
> > > >> click
> > > > 
> > > > I'd recommend to use setResponsePage(MyPage.class, parameters) instead
> > > > in this case. This way you will have a nice looking url and the page
> > > > may stay stateless if there are no stateful components/behaviors in
> > > > it.
> > > > If you know the parameters earlier then you can even use
> > > > BookmarkablePageLink("id", MyPage.class, parameters) - this will save
> > > > you a http redirect.
> > > > 
> > > >> with parameters as PageParameters.
> > > >> At the MyPage site, the constructor creates a:
> > > >> IModel<MyModel> model = new IModel<MyModel>() {
> > > >>   public void setObject ..
> > > >>   public MyModel getObject..
> > > >> }
> > > >> 
> > > >> This variable is used to create a CompoundPropertyModel for a Form.
> > > >> 
> > > >> The first time when I click on my link to the MyPage site, everything
> > > >> is fine. At the second time, the MyModel variable is not empty. The
> > > >> variable is filled with the selected values from the first time when
> > > >> I clicked on the link to the MyPage site.
> > > >> 
> > > >> I do not understand this behavior. Normally, the MyModel variable
> > > >> should be empty and not filled with the last selection.
> > > >> 
> > > >> Has someone an idea?
> > > >> 
> > > >> Thanks,
> > > >> Andre
> > > >> 
> > > >> --
> > > >> Andre Schütz <[email protected]>
> > > >> 
> > > >> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: [email protected]
> > > >> For additional commands, e-mail: [email protected]
> > > >> 
> > > > 
> > > > 
> > > > 
> > > > -- 
> > > > Martin Grigorov
> > > > jWeekend
> > > > Training, Consulting, Development
> > > > http://jWeekend.com
> > > > 
> > > > ---------------------------------------------------------------------
> > > > 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]
> > 
> > 
> > -- 
> > Andre Schütz <[email protected]>
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> 
> 
> -- 
> Andre Schütz <[email protected]>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]


-- 
Andre Schütz <[email protected]>

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

Reply via email to