JSF page splitting

喜欢而已 提交于 2019-12-11 19:14:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!