Hi,

Re-attached the file as a .txt file. My apologies. I will read up again on
the link for Models and re-visit it. .

Thanks for the time
Niv


On Wed, Aug 4, 2010 at 5:43 PM, Nivedan Nadaraj <shravann...@gmail.com>wrote:

> Hi
>
> I did read the link and from which i went about modifying the Model. I have
> limited usage of generics in the code. Would be great to utilise it the way
> it is supposed to be.
> I am using 1.4.x version of wicket.
>
> Did u want me to send you the code to your email id if the attachment are
> not good?
>
> Thanks
> Niv
>
>
> On Wed, Aug 4, 2010 at 5:21 PM, avrahamr <avrah...@gmail.com> wrote:
>
>>
>> I think attachments are not good in the list, so we didn't get your code.
>>
>> I'm not following the way you are mixing Model with the Object and I
>> recommend reading:
>> https://cwiki.apache.org/WICKET/working-with-wicket-models.html
>>
>> The StudyModel should be something like this:
>> public class StudyModel implements IModel {
>>
>> private Study study;
>>  public Object getObject() {
>> return study;
>>  }
>>
>> public void setObject(Object object) {
>> this.study =  (Study)study;
>>  }
>>       ...
>>
>> But if that's the case, I don't see a reason not to use the concrete Model
>> class: new Model(study)
>>
>> Also, I see from your examples you are using Wicket 1.3.x, is that right?
>>
>> With Wicket 1.4.x and generics it all becomes much more clear.
>>
>> On Wed, Aug 4, 2010 at 11:38 AM, nivs [via Apache Wicket] <
>> ml-node+2313107-368287748-293...@n4.nabble.com<ml-node%2b2313107-368287748-293...@n4.nabble.com>
>> <ml-node%2b2313107-368287748-293...@n4.nabble.com<ml-node%252b2313107-368287748-293...@n4.nabble.com>
>> >
>> > wrote:
>>
>> > After a long battle..i have progressed an inch forward!
>> >
>> > The StudyModel that implements IModel seemed to have the problem.
>> > I did not set the object in setObject...after modifying it in the
>> following
>> >
>> > way..the Refresh button works.
>> >
>> >
>> >     public Object getObject() {
>> >         return this;
>> >     }
>> >
>> >     public void setObject(Object object) {
>> >         StudyModel model = (StudyModel)object;
>> >         this.studyVO = model.getStudyVO();
>> >
>> >     }
>> >
>> > But I am not there as yet...now when I lookup and then click on an item
>> > from
>> > the list, the form again is empty..meaning the model is not being
>> updated.
>> >
>> > So basically.
>> > 1.Search  Panel - Search items
>> > 2.SearchResults - onClick
>> > 3.Details- displayed correctly..., now I click cancel, tht hides the
>> > details
>> > panel
>> > 4. I click on New/Refresh button on Search Panel
>> > 5. A new details page is loaded - the effect of modifying setObject() in
>> > the
>> > Model
>> > 6.I click on cancel on details panel
>> > 7. And perform steps 1 to 2
>> > 8. An empty details panel is displayed...
>> >
>> > If i can get a single thread of clue..will fix this and cement it !!!!
>> > Obviously I dont have a grip over Models..
>> >
>> > Cheers
>> > niv
>> >
>> >
>> >
>> >
>> > On Wed, Aug 4, 2010 at 11:12 AM, Nivedan Nadaraj <[hidden email]<
>> http://user/SendEmail.jtp?type=node&node=2313107&i=0>>wrote:
>> >
>> >
>> > > Hi
>> > >
>> > >
>> > > After I added setOutputMarkupPlaceHolderTag(true) to the details
>> panel,
>> > the
>> > > Ajax function works and I can see the details panel. (Which I could
>> not
>> > > earlier)
>> > > However, the problem still remains as in the model has not been
>> updated
>> > and
>> > > still refers to the stale/old one.
>> > >
>> > > @avrahmr
>> > > I used the setModel but I get a wicket runtime exception.
>> > >
>> > > Thanks for your thoughts.
>> > > Niv
>> > >
>> > >
>> > > On Wed, Aug 4, 2010 at 10:25 AM, Nivedan Nadaraj <[hidden email]<
>> http://user/SendEmail.jtp?type=node&node=2313107&i=1>>wrote:
>> >
>> > >
>> > >> Hi,
>> > >>
>> > >> I have attached the code as a text file. I have removed lines that
>> don't
>> >
>> > >> really make any contribution to the problem at hand after carefully
>> > >> examining it.
>> > >>
>> > >> Appreciate your time if you could see any issues please let me know.
>> > >>
>> > >> Basically the code has the Form objects I used, and the different
>> panels
>> >
>> > >> involved with it.
>> > >>
>> > >> Many thanks
>> > >> Niv
>> > >>
>> > >>
>> > >> On Tue, Aug 3, 2010 at 10:30 PM, Nivedan Nadaraj <[hidden email]<
>> http://user/SendEmail.jtp?type=node&node=2313107&i=2>>wrote:
>> >
>> > >>
>> > >>> Avraham and Matt,
>> > >>>
>> > >>> Thanks for the points. I will have a look at it tomorrow and post
>> the
>> > >>> code if I still haven't resolved. I don't have the code on me at the
>> > moment.
>> > >>> Reg
>> > >>> Niv
>> > >>>
>> > >>>
>> > >>>
>> > >>>
>> > >>> On Tue, Aug 3, 2010 at 9:41 PM, mwilber <[hidden email]<
>> http://user/SendEmail.jtp?type=node&node=2313107&i=3>>
>> > wrote:
>> > >>>
>> > >>>>
>> > >>>> Again without seeing more of the code some of this is guessing.
>> > >>>>
>> > >>>> If the component that you are trying to "update" is not part of the
>> > >>>> original
>> > >>>> HTML it will not be updated in the ajax response. I see that you
>> are
>> > >>>> marking
>> > >>>> the component as visible and enabled. If it isn't visible during
>> the
>> > >>>> initial
>> > >>>> rendering then it won't be placed in the HTML. If you mark the
>> > component
>> > >>>> with
>> > >>>>
>> > >>>>
>> >
>> http://wicket.apache.org/apidocs/1.4/org/apache/wicket/Component.html#setOutputMarkupPlaceholderTag(boolean<http://wicket.apache.org/apidocs/1.4/org/apache/wicket/Component.html#setOutputMarkupPlaceholderTag%28boolean>
>> > )<
>> >
>> http://wicket.apache.org/apidocs/1.4/org/apache/wicket/Component.html#setOutputMarkupPlaceholderTag%28boolean%29
>> >
>> >
>> > >>>> setOutputMarkupPlaceholderTag(true)  then the invisible component
>> will
>> >
>> > >>>> have
>> > >>>> a placeholder to be updated during the ajax response.
>> > >>>> --
>> > >>>> View this message in context:
>> > >>>>
>> >
>> http://apache-wicket.1842946.n4.nabble.com/Model-Is-Not-being-Refreshed-tp2311457p2311876.html
>> <
>> http://apache-wicket.1842946.n4.nabble.com/Model-Is-Not-being-Refreshed-tp2311457p2311876.html?by-user=t
>> >
>> > >>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> > >>>>
>> > >>>>
>> ---------------------------------------------------------------------
>> > >>>> To unsubscribe, e-mail: [hidden email]<
>> http://user/SendEmail.jtp?type=node&node=2313107&i=4>
>> > >>>> For additional commands, e-mail: [hidden email]<
>> http://user/SendEmail.jtp?type=node&node=2313107&i=5>
>> > >>>>
>> > >>>>
>> > >>>
>> > >>
>> > >
>> >
>> >
>> > ------------------------------
>> >  View message @
>> >
>> http://apache-wicket.1842946.n4.nabble.com/Model-Is-Not-being-Refreshed-tp2311457p2313107.html
>> > To start a new topic under Wicket - User, email
>> > ml-node+1842947-1647783149-293...@n4.nabble.com<ml-node%2b1842947-1647783149-293...@n4.nabble.com>
>> <ml-node%2b1842947-1647783149-293...@n4.nabble.com<ml-node%252b1842947-1647783149-293...@n4.nabble.com>
>> >
>> > To unsubscribe from Wicket - User, click here<
>> http://apache-wicket.1842946.n4.nabble.com/subscriptions/Unsubscribe.jtp?code=YXZyYWhhbXJAZ21haWwuY29tfDE4NDI5NDd8LTEwNzY0NzQ1ODc=
>> >.
>> >
>> >
>> >
>>
>>
>> --
>> []'s
>> Avraham Rosenzweig
>> avrah...@gmail.com
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/Model-Is-Not-being-Refreshed-tp2311457p2313148.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>
>
/*

 The Form object that is used to capture input from the Search panel and the 
events such as New, Reset and Search.
 Added the Refresh button which is the same as new only thatI am using it to 
test with Ajax to resolve the problem*/ 

public class SearchStudyForm extends Form<Study>{
        
        TextField<String> studyIdTxtFld =new 
TextField<String>(Constants.STUDY_SEARCH_KEY);
        //....rest of the fields
        Button searchButton;
        Button resetButton;
        List<StudyStatus>  studyStatusList;

        /* The new and Refresh button*/
        Button newButton;
        AjaxButton refresh;

        /* Constructor */
        public SearchStudyForm(String id, Study study, String panelId, 
List<StudyStatus>  studyStatusList, final Details detailsPanel ){

                super(id, new CompoundPropertyModel<Study>(study));

                this.studyStatusList = studyStatusList;

                refresh = new AjaxButton("refresh") {
                        
                        @Override
                        protected void onSubmit(AjaxRequestTarget target, 
Form<?> form) {
                                detailsPanel.getStudyForm().setModelObject(new 
StudyModel());
                                detailsPanel.setVisible(true);
                                onNew(new Study());
                                target.addComponent(detailsPanel);
                        }
                };
                
                
                searchButton  = new Button(Constants.SEARCH, new 
StringResourceModel("page.search", this, null))
                {
                        public void onSubmit()
                        {
                                
                                onSearch((Study) getForm().getModelObject());
                        }
                };

                newButton =  new Button(Constants.NEW, new 
StringResourceModel("page.new", this, null))
                {
                        public void onSubmit()
                        {
                                
                                onNew(new Study());
                        }
                };
                
                resetButton = new Button("reset", new 
StringResourceModel("page.form.reset.button", this, null) ){
                        public void onSubmit(){
                                clearInput();
                                updateFormComponentModels();
                        }
                };
                
                addComponentsToForm();
        }
        
        protected void onSearch(Study Study){
        }
        
        protected void onNew(Study study){}
        
        protected void onReset(){}
}

/* The Model that will be used by Details */

@SuppressWarnings("serial")
public class StudyModel implements IModel{

        private Study study;
        private Set<String> lmcAvailableApps = new HashSet<String>();
        private Set<String> lmcSelectedApps = new HashSet<String>();
        
        public StudyModel(){
                study = new Study();
        }
        public Study getStudy() {
                return study;
        }

        public void setStudy(Study study) {
                this.study = study;
        }

        public Set<String> getLmcAvailableApps() {
                return lmcAvailableApps;
        }
        public void setLmcAvailableApps(Set<String> lmcAvailableApps) {
                this.lmcAvailableApps = lmcAvailableApps;
        }
        public Set<String> getLmcSelectedApps() {
                return lmcSelectedApps;
        }
        public void setLmcSelectedApps(Set<String> lmcSelectedApps) {
                this.lmcSelectedApps = lmcSelectedApps;
        }
        

        public Object getObject() {
                return this;
        }

        public void setObject(Object object) {
                this.study = ((StudyModel)object).getStudy();
        }

        public void detach() {
        //set the members to null
        }
        
}



/*Container that has the Search panel. In the turn the Search will have the 
Results and Details panel.
  
 */


public class StudyContainerPanel extends Panel{

        //Child Components
        private Search searchStudyPanel;
        
        public StudyContainerPanel(String id) {
                super(id);
                searchStudyPanel = new Search("searchStudyPanel");
                searchStudyPanel.process("searchStudyPanel");
                add(searchStudyPanel);
        }
}


/* Search Panel: This will contain the SearchResultList panel and the Details 
panel.  */

public class Search extends Panel {
        

        private SearchResultList searchResults;//Contains the results of the 
Search
        private Details detailsPanel; //The detail panel that will contain the 
details of the selected item
        
        public SearchResultList getSearchResults() {
                return searchResults;
        }

        public void setSearchResults(SearchResultList searchResults) {
                this.searchResults = searchResults;
        }
        
        public void setDetailsPanelVisible(boolean isVisible){
                detailsPanel.setVisible(isVisible);
        }
        
        @SpringBean( name = Constants.STUDY_SERVICE)
        private IStudyService studyService;
        
        /*Constructor */
        public Search(String id) {
                super(id);
        }
        
        public void process(String id){
                
                //Create a new instance of the details panel
                StudyModel studyModel = new StudyModel();
                studyModel.setStudy(new Study());
                detailsPanel = new Details("detailsPanel", 
this,Constants.MODE_NEW);
                detailsPanel.setOutputMarkupId(true);
                detailsPanel.initialiseForm(studyModel);
                //Hide it since we have not looked up as yet
                setDetailsPanelVisible(false);

                
                // Uses an entirely new VO for the search so each time the 
search panel is loaded. The values provided will be refreshed.
                SearchStudyForm searchForm = new 
SearchStudyForm(Constants.SEARCH_FORM, new Study(), 
id,studyService.getListOfStudyStatus(), detailsPanel){
                        
                        /*When user has clicked on the Search Button*/
                        protected  void onSearch(Study study){
                                setDetailsPanelVisible(false);//Set the User 
Details panel to false/hide it
                                List<Study> resultList = 
studyService.getStudy(study);
                                if(resultList != null && resultList.size() == 
0){
                                        this.info("Study with the specified 
criteria does not exist in the system.");   
                                }
                                remove(searchResults);
                                searchResults = new 
SearchResultList("searchResults", resultList,detailsPanel);
                                add(searchResults);
                        }
                         
                        /* When used clicked on New, refresh the form model for 
Details panel and make it visible */
                        protected void onNew(Study study){
                                detailsPanel.getStudyForm().setModelObject(new 
StudyModel());
                                detailsPanel.setVisible(true);
                                searchResults.setVisible(false);//Hide the 
search results
                        }
                
                };

                //Add the Form to the Panel. The Form object that will contain 
the child or UI components that will be part of the search or be affected by 
the search.
                add(searchForm);
                searchForm.add(detailsPanel);
                
                //Just an empty list to initialise the resultsList
                List<Study> studyList = new ArrayList<Study>();
                Study study = new Study();
                studyList.add(study);
                searchResults = new 
SearchResultList("searchResults",studyList,detailsPanel);
                searchForm.add(searchResults);
        }

}


/* The Search ResultList panel that loads the list and onClick
  renders or makes the detailsPanel visible with the selecte data */

public class SearchResultList extends Panel{
        
        @SpringBean( name = Constants.STUDY_SERVICE)
        private IStudyService studyService;
        
        @SpringBean( name = "userService")
        private IUserService userService;
        
        private List<Study> studyList;
        private Details detailsPanel;

        /*Constructor */
        public SearchResultList(String id, List<Study> studyList, Component 
component) {
                
                super(id);
                this.studyList = studyList;
                this.detailsPanel = (Details)component;
                PageableListView pageableListView = 
buildPageableListView(studyList, 10);//Rows per page to be in properties file
                PagingNavigator pageNavigator = new 
PagingNavigator("navigator", pageableListView);
                add(pageNavigator);
                add(pageableListView);
        }
        
        @SuppressWarnings({ "unchecked", "serial" })
        private PageableListView buildPageableListView(List<Study> list, int 
rowsPerPage){
                
                PageableListView  pageableListView = new 
PageableListView("studyList", studyList, rowsPerPage){

                        @Override
                        protected void populateItem(final ListItem item) {
                                
                                Study study = (Study) item.getModelObject();

                                Link studyNameLink = buildLink(item, 
detailsPanel, study);//where the onClick event will be defined
                                /* Build the caption for the Link*/
                                Label studyNameLinkLabel = new 
Label("studyNameLink", study.getName());
                                studyNameLink.add(studyNameLinkLabel);
                                item.add(studyNameLink);
                                
                                }));
                                
                        }
                
                };
                return pageableListView;
        }
        
        @SuppressWarnings({ "unchecked", "serial" })
        private Link buildLink(final ListItem item, final Component 
detailsPanel, final Study study) {
                

                return new Link("studyName", item.getModel()) {
                        @Override
                        public void onClick() {
                                
                                Details studyDetails = (Details)detailsPanel;
                                
                                StudyForm studyForm = 
studyDetails.getStudyForm();
                                StudyModel studyModel = (StudyModel) 
studyForm.getModelObject();//The Model for details panel
                                Set<String> selectedApps = new 
HashSet<String>();
                                try {
                                        

                                        studyModel.setStudy(study);//Set the 
model with the study from the list
                                        
studyModel.setLmcSelectedApps(selectedApps);
                                        studyForm.setModelObject(studyModel);

                                        /* Make the details panel visible */
                                        studyDetails.setVisible(true);
                                        
                                } catch (SomeSystemException e) {
                                        //....
                                }
                        }
                };
                
        }
}




/* The form object that the Details Panel will use to capture input */
@SuppressWarnings("serial")
public class StudyForm extends Form<StudyModel>{
        
        @SpringBean( name = Constants.STUDY_SERVICE)
        private IStudyService studyService;
        private int mode;
        
        public int getMode() {
                return mode;
        }

        public void setMode(int mode) {
                this.mode = mode;
        }
        /*Constructor*/
        public StudyForm(String id, StudyModel studyModel) {
                
                super(id, new CompoundPropertyModel<StudyModel>(studyModel));
                
                try{

                        initFormFields(studyModel);
                        decorateComponents();
                        addComponents();
                
                }catch(SomeSystemException ase){
                        //....  
                }
        }

        TextField<String> studyIdTxtFld =new 
TextField<String>(Constants.STUDY_KEY);
        //....

        Button cancelButton;
        Button deleteButton;
        
        List<ModuleVO> modules;

        public TextField<String> getStudyIdTxtFld() {
                return studyIdTxtFld;
        }
        
        public TextField<String> getStudyNameTxtFld() {
                return studyNameTxtFld;
        }
        
        
        
        protected  void onSave(StudyModel studyModel){}
        protected  void onCancel(StudyModel studyModel){}
        protected void  onDelete(StudyModel studyModel){}
        
        private void initFormFields(StudyModel studyModel) throws 
SomeSystemException{
                
                saveButton = new Button(Constants.SAVE, new 
StringResourceModel("saveKey", this, null))
                {
                        public void onSubmit()
                        {
                                StudyModel studyModel = (StudyModel) 
getForm().getModelObject();
                                onSave(studyModel);
                        }
                }; 
                /* Hide the detail */
                cancelButton = new Button(Constants.CANCEL,  new 
StringResourceModel("cancelKey", this, null))
                {
                        public void onSubmit()
                        {
                                StudyModel studyModel = (StudyModel) 
getForm().getModelObject();
                                onCancel(studyModel);
                        }
                        
                };
                
                deleteButton = new Button(Constants.DELETE, new 
StringResourceModel("deleteKey", this, null))
                {
                        public void onSubmit()
                        {
                                //Go to Search users page
                                onDelete((StudyModel) 
getForm().getModelObject());
                        }
                        
                };
                
        }

}


/* The Details Panel */

@SuppressWarnings("serial")
public class Details extends Panel{

        @SpringBean( name = Constants.STUDY_SERVICE)
        private IStudyService service;
        
        @SpringBean( name = "userService")
        private IUserService userService;
        
        
        private StudyForm studyForm;
        private Search searchPanel;
        
        public Search getSearchPanel() {
                return searchPanel;
        }

        public void setSearchPanel(Search searchPanel) {
                this.searchPanel = searchPanel;
        }

        public StudyForm getStudyForm() {
                return studyForm;
        }

        public void setStudyForm(StudyForm studyForm) {
                this.studyForm = studyForm;
        }
        private int mode;

        /**
         * Constructor
         * @param id
         * @param study
         * @param searchPanel
         */
        public Details(String id, final Search searchPanel, int mode) {
                super(id);
                setSearchPanel(searchPanel);
                this.mode = mode;
        }
        
        public void initialiseForm(StudyModel studyModel){
                
                studyForm = new StudyForm("studyForm", studyModel){
                        
                        protected void onSave(StudyModel studyModel){
                                
                                //.....
                        }
                
                        protected void onDelete(StudyModel studyModel){
                                //.....
                        }
                
                        protected void onCancel(StudyModel studyModel){
                                
searchPanel.setDetailsPanelVisible(false);//Hide the details panel
                        }
                };
                add(studyForm); //Add the form to the panel
        }

}








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

Reply via email to