Revision history [back]

click to hide/show revision 1
initial version

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

Eustas gravatar image Eustas

Relationship between pages and view models

**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.


Relationship between pages and view models

**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.

Relationship between pages and view models

**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') viewModel="@id('vm')  @init('MyViewModel')">
.....
<textbox value="myValue"/>
and page2.zull

page2.zull <window viewmodel="@id('vm') 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.

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