0

Relationship between pages and view models

asked 2012-12-21 22:31:57 +0800

Eustas gravatar image Eustas
75 1

updated 2013-02-18 13:35:34 +0800

**How should be designed application in proper manner?Should I create separate view model for every page? For example I have pages like 'create-person.zul','list-persons.zul'. So have I create separatly CreatePersonViewModel.java, ListPersonsViewModel.java? At all is it possible to have one view model class for several pages that are connected by business logic? For example several pages for admin functionality have one AdminViewModel.


I have page1.zul

<window viewModel="@id('vm')  @init('MyViewModel')">
.....
<textbox value="myValue"/>
and page2.zull

<window viewModel="@id('vm')  @init('MyViewModel')">
.....
 <label value="myValue">**

I have MyViewModel

public class MyViewModel
{
   @WireVariable("myManager")
   private MyManager myManager;
   String getMyValue()
   {
     return myManager.getMyValue();  
   } 

   void setMyValue(String val)
   {
     myManager.setMyValue(val);
   }  

}

I have MyManager class - session scoped inside Spring container

@Component("myManager")
@Scope("session")
public class MyManager
{
 String myValue;
 public String getMyValuee(){}
 public void setMyValue(String val) {...}
}

Now I can set the value to myValue at page1.zul and the value at page2.zul will be updated. How can I make it with different ViewModel for every page? Moreover I cannot save the state of myValue inside og MyViewModel because it's new for every request for same page.

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2013-02-18 15:35:33 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Having same view modal for several zul files will be good if you have the same business logic. For example, in our project, we have some 35 master screens, where all the master screens are have the list and add/edit modal zul file. So we have only one zul and one viewmodel for listing and each zul/view for add/edit.

We have the macro for each list which contains only the domain object, and the columns to be displayed in the list and then it will be passed to common zul attached to one view model file to display the record.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-12-21 22:31:57 +0800

Seen: 71 times

Last updated: Feb 18 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More