-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Sorry for my ignorance, this must be quite straight forward but after googling a bit I didn't find a nice way of doing it.
So, I do have a class in springboot as @Controller with the following method
@GetMapping("/plainzul")
public String plainZULExample(Model model) {
model.addAttribute("attribute1", "ZkRocks!");
model.addAttribute("attribute2", randomObjectForThisExample);
anotherRandomObject = new AnotherRandomObject()
return "plainzul";
}
I do have a page called plainzul.zul with a SelectorComposer which basically is a plain:
@Override
public void doAfterCompose(Div comp) throws Exception {
super.doAfterCompose(comp);
System.out.println("Hello cor3000 !");
}
How can I access to the attribute1? Or basically, the real question is how can I have an object in the spring controller from the Composer? maybe using the model.setAttribute is subobtimal.
Any help or examples?
How do I get the anotherRandomObject for example?
Many thanks
I my local tests Spring just transforms the Model attributes into native request attributes.
This matches the somewhat vague Spring MVC 4.0.x documentation (didn't find the equivalent for Spring 5, just assuming it's the same):
The model Map is simply transformed into an appropriate format, such as JSP request attributes, a Velocity template model.
JSP/ZUL page are roughly/technically equivalent, both are handled by Servlets more or less, based on the same HttpServletRequest.
While it's possible to access the native request directly -(HttpServletRequest)Executions.getCurrent().getNativeRequest()
) - the built in ZK abstraction is an Execution
(wrapping around the request/response objects).
In your composer you can access the execution attributes as follows:
@Override
public void doAfterCompose(Div comp) throws Exception {
super.doAfterCompose(comp);
Execution exec = Executions.getCurrent();
String attr1 = (String) exec.getAttribute("attribute1");
RandomClassForThisExample randomObjectForThisExample =
(RandomClassForThisExample) exec.getAttribute("attribute2");
System.out.println("Hello cor3000 !");
}
Asked: 2021-08-29 05:30:45 +0800
Seen: 8 times
Last updated: Aug 30 '21