问题
During working with JSF 1.2 one page code is too large and JDeveloper gave too large code in service method exception. Now I want to split my JSF file in smaller files. During splitting I need some help and suggestion.
Beacuse the whole page binds with a single bean, is it also necessary to split the bean? If not, then how to overcome this? What is the best way to split JSF file and include in main page?
回答1:
You don't need to split the bean. You could just split the page fragments over multiple files which you include by <jsp:include>
(and not by @include
as that happens during compiletime and you would end up with still the same exception!). Note that you should store those include files in /WEB-INF
folder to prevent direct access by enduser.
So given this example of an "extremely large" page,
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
large chunk 1
</div>
<div>
large chunk 2
</div>
<div>
large chunk 3
</div>
</body>
</html>
You could split it as follows while keeping the beans:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<jsp:include page="/WEB-INF/includes/include1.jsp" />
<jsp:include page="/WEB-INF/includes/include2.jsp" />
<jsp:include page="/WEB-INF/includes/include3.jsp" />
</body>
</html>
and /WEB-INF/includes/include1.jsp
:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<div>
large chunk 1
</div>
and /WEB-INF/includes/include2.jsp
:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<div>
large chunk 2
</div>
and /WEB-INF/includes/include3.jsp
:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<div>
large chunk 3
</div>
来源:https://stackoverflow.com/questions/14833353/jsf-page-splitting