# How to change Page Title Dynamically from java using MVVM [closed]

Senthilchettyin
2623 3 8
http://emrpms.blogspot.in...

How to change Page Title Dynamically from java using MVVM

delete retag edit

### The question has been closed for the following reason "the question is answered, right answer was accepted"by Senthilchettyin close date 2019-09-26 11:15:11

Sort by » oldest newest most voted

cor3000
5673 2 7

it's not wrong. In the end you are calling page.setTitle() you simply found a complicated way to do so.

Instead you can just use the features MVVM provides - to avoid this kind of long chain of method calls. (just as in my previous example)

  @AfterCompose
public void afterCompose(@ContextParam(ContextType.PAGE) Page page) {
page.setTitle("initial title");
}


http://zkfiddle.org/sample/31tj128/3-mvvm-set-page-title

cor3000
5673 2 7

I know this is not a pure MVVM since it requires direct access to the page object. But then this is most simple thing I could think of:

Simply call page.setTitle("updated title");

http://zkfiddle.org/sample/31tj128/1-mvvm-set-page-title

(you need to run this in a dedicated browser tab to see the title change http://temp.zkfiddle.org:1223/t862svt/31tj128/1/)

However this sounds too obvious and I assume you already tried that. In case you did: were there any difficulties on your side?

Senthilchettyin
2623 3 8
http://emrpms.blogspot.in...

I saw the example. It is explicit i,e on button click. I want to load automatically. So i added the following line in afterCompose method and it works.

Executions.getCurrent().getDesktop().getFirstPage().setTitle("Homecare");


is this correct ?