/viewblock

JSP web block load,big page.

Primary LanguageJavaApache License 2.0Apache-2.0

viewblock

Maven Central GitHub release License

Viewblock is a JSP block loading tool, which is used to handle complex business request and page block loading, effectively reduce the coupling degree between the page blocks, and reduce the Ajax request of the conventional page.

demo

https://github.com/liyiorg/viewblock-example

features


  • annotation
  • support request parameters, type conversion
  • support Freemark, JSP template
  • support IOC spring
  • support asynchronous loading block (servlet3.0, web tomcat-7.0.50, jetty 9.2.19.v20160908, container: other web containers to be loaded asynchronously without HTML), occupying JS (embedded integrity, will not damage the page to the search engines.) , asynchronous and synchronous loading can be used simultaneously.

use scene

Viewblock is applicable to large pages, a single request multi page block logic processing, page code block reuse, asynchronous page loading project, can be used together with the MVC architecture, such as Spring MVC, Struts1 ,Struts2.

Full use example:


1. maven
<dependency>
  <groupId>com.github.liyiorg</groupId>
  <artifactId>viewblock</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>
2. web.xml
<filter>   
	<filter-name>viewblock</filter-name>   
	<filter-class>com.github.liyiorg.viewblock.core.ViewblockFilter</filter-class>  
	<init-param>   
		<param-name>config_properties</param-name>   
		<param-value>  	  		
		pack_scan=example.*    
		spring=false    
		jsp_template=/WEB-INF/block    
		freemarker=false    
		freemarker_template=/WEB-INF/block    
		freemarker_delay=0    
		freemarker_encode=UTF-8    
		</param-value>    
	</init-param>   
</filter>

<servlet id="jsp">
	<servlet-name>jsp</servlet-name>
	<async-supported>true</async-supported>
</servlet>
3. create viewblock
@ViewblockCollection
public class ExampleBlock {

	@Viewblock(name = "header", template = "header.jsp")
	public void header() {
		try {
			Thread.currentThread().sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	@Viewblock(name = "content", template = "content.jsp")
	public void content(@BRequestParam(required=false) String name,BModelMap bModelMap){
		try {
			Thread.currentThread().sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		bModelMap.addAttribute("name", name);
	}

	@Viewblock(name = "footer", template = "footer.ftl")
	public String footer() {
		try {
			Thread.currentThread().sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "footer.ftl";
	}
}
4. JSP page
sync load
<%@taglib uri="https://github.com/liyiorg/viewblock" prefix="viewblock"%>  

<viewblock:block name="header"/>  
<div>other html...</div>   
<viewblock:block name="content"/>
<viewblock:block name="footer"/>  
async load
<%@taglib uri="https://github.com/liyiorg/viewblock" prefix="viewblock"%>

<!-- Load asynchronous execution in order to load the page faster, and reduce the wait for the asynchronous output tag, the asynchronous execution block should be placed at the top of the JSP page.-->  
<viewblock:block name="content" async="true"/>

<viewblock:block name="header"/>
<div>other html...</div>
<!-- Output asynchronous execution content-->
<viewblock:output name="content"/>
  
<viewblock:block name="footer"/>  
<!-- Release asynchronous link -->
<viewblock:asyncFinish/>
jsp tag params
<%@taglib uri="https://github.com/liyiorg/viewblock" prefix="viewblock"%>

<viewblock:block name="header"/>
<viewblock:block name="content">
	<viewblock:param name="name" value="SLYH"/>
	<viewblock:param name="h" value="123"/>
</viewblock:block>
<viewblock:block name="footer"/>