The page title, which currently has the page title and the menu slide out control…
how to customize it? speci\fically want to add a datePicker.
I found a workaround, but I am sure there is a better way.
I added the desired control to main-view.xml in the navbar with attribute visible=false.
Then modified MainView.java to keep a reference to this control:
public class MainView extends StandardMainView {
@ViewComponent
private Header header;
@ViewComponent
private TypedDatePicker<Comparable> datePicker1;
private static TypedDatePicker<Comparable> datePickerSave;
private static Header headerSave ;
@Subscribe
public void onInit(InitEvent event) {
datePickerSave = datePicker1;
headerSave = header;
}
public static Header getHeader() {
return headerSave;
}
public static TypedDatePicker<Comparable> getDatePicker() {
return datePickerSave;
}
Then I referenced this saved control in the desired view::onInit, making it visible.
TypedDatePicker<Comparable> dp = MainView.getDatePicker();
dp.setVisible(true);
Then I set it invisible again in the desired view::onAfterClose().
@Subscribe
public void onAfterClose(AfterCloseEvent event) {
TypedDatePicker dp = MainView.getDatePicker();
dp.setVisible(false);
}
Hi, Steve!
You can try to create a Spring-bean. Then pass your DatePicker to this bean in the MainView
's initialization method.
Next, you can create a custom view opening event like a Spring-Application-Event and fire it when the view you want opens.
It remains only to make the spring-bean a listener for this event.
Regards,
Dmitriy
Shouldn’t there be a way to access the MainView directly from my view? it is clearly part of the component hierarchy. Please add a way to access if not.
your workaround worked, and of course is preferred to my solution which doesn’t survive multiusers.
oops, sadly the workaround of using spring bean to record the controls of interest didnt work, because when two people were logged on at the same time we get “Cannot access state in VaadinSession or UI without locking the session.” and could find no workaround.
You can also access the navigation hierarchy via UI.getCurrent().getInternals().getActiveRouterTargetsChain()
.
Regards,
Dmitriy
THis was helpful! I was able to update the Title of the page with this code:
List<HasElement> listel = UI.getCurrent().getInternals().getActiveRouterTargetsChain();
for (HasElement he : listel) {
if (he instanceof MainView) {
MainView mv = (MainView) he;
H1 h1 = mv.getViewTitleH1();
h1.setText(getPageTitle());
break;
}
}