How to instantiate a RouteLayout class with arguments

Hi,

I would like to design a RouteLayout class with arguments, so that I can pass objects variables when instantiating the RouteLayout class. I couldn’t find examples of how to pass variables to the constructor of RouteLayout class. Please kindly advise.

Warm regards,
Joey

Without more details, it is hard to give a useful answer.

If you are using spring, you can define the RouterLayout object as a spring component, and then autowire your arguments to the constructor.

In the following example, StandardLayout is an abstract class implementing RouterLayout.

@SpringComponent
@UIScope
public class MyLayout extends StandardLayout {

	private final SiteService siteService;

	@Autowired
	public MyLayout(SiteService siteSelector) {
		this.siteService = siteSelector;
	}
	...
}

Another idea is to create a concrete class that passes a hard-coded argument to the base class. Something like:

public class MyLayout extends StandardLayout {

	public MyLayout() {
		super(new SiteService());
	}
	...
}

As far as I can tell, when one or more views define the exact same parentLayout class, then the same parentLayout instance is used by each class. In this case, each view would always have the same arguments.

I am using WildFly instead. My use case is that, when instantiating the class with Route annotation, the corresponding RouteLayout could receive variables passed from instantiator to properly layouting the nodes according user requests. I am wondering which class instantiating the RouteLayout object.

Best regards,
Joey