DBILITY

독거 가능성 100% 노후에 라면값이라도 하게 센스를 발휘합시다!😅
Please click on the ad so that I can pay for ramen in my old age!
点击一下广告,让老后吃个泡面钱吧!
老後にラーメン代だけでもするように広告を一回クリックしてください。

vaadin flow updating page title on navigation 본문

front-end & ui/vaadin flow

vaadin flow updating page title on navigation

DBILITY 2018. 9. 11. 08:07
반응형

공식 사이트 문서를 참조하여 작성하였다.

 

navigation이 이루어지는 동안 페이지 title을 업데이트하는 방법은 두 가지가 있다.

@PageTitle Annotation을 이용하는 방법과 HasDymamicTitle interface를 구현하는 방법이 있으며, 이 두 가지 접근법은 상호 배타적이라 동일 class에 구현 시 runtime exception이 발생한다.

 

@PageTitle Annotation은 가장 편리한 방법으로 Component class에 설정하게 되며, 실제 존재하는 navigation target에 대해서만 인식한다. 상위class나 상위 view는 고려되지 않는다.

@PageTitle("home")
class HomeView extends Div {

  HomeView(){
    setText("This is the home view");
  }
}

HasDynamicTitle interface를 구현하는 방법은 개발자가 runtime시 변경할 수 있게 허용한다.

@Route(value = "blog")
class BlogPost extends Component
        implements HasDynamicTitle, HasUrlParameter<Long> {
  private String title = "";

  @Override
  public String getPageTitle() {
    return title;
  }

  @Override
  public void setParameter(BeforeEvent event,
        @OptionalParameter Long parameter) {
    if (parameter != null) {
      title = "Blog Post #" + parameter;
    } else {
      title = "Blog Home";
    }
  }
}
반응형

'front-end & ui > vaadin flow' 카테고리의 다른 글

vaadin flow - grid  (0) 2018.09.11
vaadin flow - using vaadin components  (0) 2018.09.11
vaadin flow getting registered routes  (0) 2018.09.11
vaadin flow router exception handling  (0) 2018.09.10
vaadin flow navigating between routes  (0) 2018.09.10
Comments