-
FEATURED COMPONENTS
First time here? Check out the FAQ!
How to get @PathVariable from Spring Boot to the MVC Page Controller?
Is it possible?
Seems there are no way other than using Session and Use HttpServletRequest then?
Ugh. it's hacky isn't it? It's the controller method
import jakarta.servlet.http.HttpServletRequest;
@GetMapping("/mvvm/{id}")
public String MvvmPageWithId(@PathVariable Integer id, HttpServletRequest request)
{
// Hacky?
request.getSession().setAttribute("id", id);
return "mvvm";
}
On the Mvvm Method (if MVVM?), but same I think if it's MVC, on the doAfterInit()?
import org.springframework.web.bind.annotation.PathVariable;
import jakarta.servlet.http.HttpServletRequest;
private Integer id;
@Init
public void init() {
// MVVM Init
// @see books[dot]zkoss[dot]org/zk-mvvm-book/8.0/viewmodel/initialization.html
Execution exec = Executions.getCurrent();
HttpServletRequest request = (HttpServletRequest) exec.getNativeRequest();
Object o = request.getSession().getAttribute("id");
if (o == null) return;
String idSession = String.valueOf(o);
request.getSession().removeAttribute("id");
String idUrl = idSession;
try {
this.setId(Integer.parseInt(idUrl));
}
catch(Exception e)
{
Messagebox.show("Its not int : " + idUrl, new Button[] { Button.OK }, null);
}
}
I think it's not hacky, since spring handles a request differently from ZK. You can pass it through a session or a request attribute. But I think storing the id into the request scope is better than the session scope. Since this will not affect other browser tabs. For example:
@GetMapping("/mvvm/{id}")
public String mvvmExample(@PathVariable Integer id, HttpServletRequest request) {
request.setAttribute("id", id);
return "mvvm";
}
In a ViewModel:
@Init
public void init() {
Executions.getCurrent().getAttribute("id");
}
ZK MVC pattern means you control UI by calling ZK component's API. What you use is Spring MVC which is different from ZK MVC.
Asked: 2023-11-08 00:24:22 +0800
Seen: 6 times
Last updated: Nov 14
bug with intboxes on mobile devices
zk keikai-how to add custom button/label to formulabar?
zk-keikai- update multiple cells parallel at same time asynchronously
zk-keikai-How to auto fit column width based on text
zk-keikai-ClipboardPateEvent-called twice
Reference a spring bean from VariableResolver