Why this code show null ? i write according to documentantion
public class OfferGui extends Div implements BeforeEnterObserver {
private String id;
@Override
public void beforeEnter(BeforeEnterEvent beforeEnterEvent) {
id = beforeEnterEvent.getRouteParameters().get("id").get();
}
public OfferGui(){
Text text =new Text("heelo"+id);
add(text);
}
}```
beforeEnter is called after the constructor.
Because constructor are always called first in Java
You have to structure your code that it either is completely build in those beforeMethods or build the layout that it can take parameters and be refreshed depending on the given value
i think implementetion BeforeEnterObserver and method beforeEnter is enough
It’s enough, but you have to build your view that it can take those arguments. Good practice is to create a other layout on e.g, constructor or post construct and add the information that depend on external arguments in the before enter, after enter or onAttach methods. Using only the constructor to build your views won’t get you really far.
but I cant find method aftermethod
I found only AfteNavigation
After navigation… is correct
ok thanks, and You dont recommend me use constructor to make view ?
I would only recommend building views in the constructor if they are kinda static and don’t involve parameter from other sources