1

I have a Vaadin view that needs a parameter for its construction (e.g. number of weeks to show). However, commonly construction of a view is done in the constructor, while parameters are set in the setParameter method, which is called after the constructor.

Is there a way to build the view after the setParameter is called?

1 Answer 1

2

You can simply skip implementing the constructor and instead set up the whole view in setParameter or beforeEnter.

Depending on the case, you might have to be careful to avoid problems if the user can navigate directly to the same view but with another parameter value since in that case setParameter (or beforeEnter) would be called again for the same instance which means that you might end up setting up everything again and thus end up with duplicates in the view.

Sign up to request clarification or add additional context in comments.

2 Comments

There may be more parameters. I could kludge it by counting those, but if any are optional I have a problem. I could use query parameters, then all are present at once. Seems like the beforeEnter event method is called after setParameter, and may be just as suited?
Yes. beforeEnter is also a valid choice. I'll update my response to also mention that possibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.