if (!empty($_SERVER['HTTP_CLIENT_IP']))
$ip=$_SERVER['HTTP_CLIENT_IP'];
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip=$_SERVER['REMOTE_ADDR'];
?>
In the previous two articles Rich Web Application with Spring MVC CRUD Demo and Rich Web Application with Spring MVC CRUD Demo – Part II, we’ve explored the advantages of combining ZK with Spring MVC and the benefits of manipulating the data between Spring MVC and ZK MVVM data binding. In this article, we’ll briefly talk about how Java configuration could be used to replace the XML configuration in ZK Spring MVC and the convenience of using a new feature in ZK 8 – Shadow Selector – to control shadow elements.
To-do Management Demo (Changing templates by Shadow Selector)
The following demonstrates changing templates in ZK Spring MVC through using a new feature in ZK 8 – Shadow Selector.
Instead of defining in a springmvc-servlet.xml file, we could define by a Java configuration class.
The only difference from Spring is you have to extend ZKWebMvcConfigurerAdapter.
@EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "org.zkoss.zkspringmvc.demo" })
public class MvcConfig extends ZKWebMvcConfigurerAdapter {
@Bean
public ViewResolver getViewResolver() {
ZKUrlBasedViewResolver resolver = new ZKUrlBasedViewResolver();
resolver.setViewClass(new ZKView().getClass());
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix("");
return resolver;
}
}
Controller
In the controller, the method for changing templates should return a Shadow Selector.
In line 3, the shadow selector “::shadow:todo” means changing the selected “::shadow” shadow element and changing the applied template to the “todo” template.
For more examples of Shadow Selector, please visit this page.
What is a bit different from the Shadow Selector document is that “::shadow” would only select the first shadow root in this version of zkspringmvc.
In line 3, we use a shadow element to apply the “todo” template. By setting dynamicValue=”true”, this shadow element will be stored on the server side for updates later.
I got blank page and the following trace in the jetty server
INFO: FrameworkServlet ‘springmvc’: initialization completed in 580 ms
2016-02-23 11:23:56.040:INFO:oejs.AbstractConnector:Started SelectChannelConnect
or@0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 5 seconds.
Feb 23, 2016 11:24:32 AM org.zkoss.util.resource.impl.LabelLoaderImpl loadLabels
INFO: Loading labels for en_US
Feb 23, 2016 11:24:32 AM org.zkoss.util.resource.impl.LabelLoaderImpl loadLabels
@Ismail
Yes, the wrong file was committed. However, the correct zul file had already been provided at the time of publication.
If you continue to encounter problems, feel free to point them out, thanks!
@Aaron
The problem you’ve got might be caused by the expiry date of zkspringmvc, and it has bean updated. So, please clone the repository again. If there is any problem, feel free to let us know. Thanks.
Tried your demo app. Compiles and runs without any error, but when I hit the url http://localhost:8080/zkspringmvc-demo/mvc/todos2/
I got blank page and the following trace in the jetty server
INFO: FrameworkServlet ‘springmvc’: initialization completed in 580 ms
2016-02-23 11:23:56.040:INFO:oejs.AbstractConnector:Started SelectChannelConnect
or@0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 5 seconds.
Feb 23, 2016 11:24:32 AM org.zkoss.util.resource.impl.LabelLoaderImpl loadLabels
INFO: Loading labels for en_US
Feb 23, 2016 11:24:32 AM org.zkoss.util.resource.impl.LabelLoaderImpl loadLabels
INFO: Loading labels for en
@Tanmay
There were some errors in the zul page of the demo project..
They have been corrected and work fine now
Thank you for pointing them out.
There were some errors in the zul page of the demo project..
@Ismail
Yes, the wrong file was committed. However, the correct zul file had already been provided at the time of publication.
If you continue to encounter problems, feel free to point them out, thanks!
Excuse me, I try this demo , but @ZKSelector(“#submit”) Button submit is null in TodoCollector.java edit method. Can any body tell me why ? thank you.
@Aaron
The problem you’ve got might be caused by the expiry date of zkspringmvc, and it has bean updated. So, please clone the repository again. If there is any problem, feel free to let us know. Thanks.
java.lang.IllegalStateException: Components can be accessed only in event listeners Error
@raja
Could you provide an example and steps to reproduce this exception? Thanks!