在我的jsf页面中没有调用@PostConstruct

时间:2017-03-11 19:13:35

标签: java jsf primefaces jsf-2

我在同一主题上看过很多问题,但没有一个问题有帮助。事实上,我正在开始学习素数。

这是我的 xhtml 页面(模板):

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <f:view contentType="text/html" locale="en">
        <h:head>
            <title><ui:insert name="title">Master Data</ui:insert></title>
            <h:outputStylesheet library="css" name="layout.css"/>
            <h:outputStylesheet library="css" name="jsfcrud.css"/>
            <h:outputScript library="js" name="jsfcrud.js"/>
        </h:head>
        <h:body>
            <p:growl id="growl" life="3000" />
            <h:panelGroup layout="block" styleClass="slogan">
                <h:outputText value="Master Data Web module for single line v 1.0"/>
            </h:panelGroup>
            <h:form id="mainForm" prependId="false">
                <h:panelGrid columns="2" columnClasses="chaptersMenuColumn,chaptersContentColumn">

                    <h:form>
                        <f:ajax render=":content">
                            <p:menu>
                                <p:submenu label="Master Data Sections">
                                    <p:menuitem value="KPI" action="#{KpiBean.setPage('create')}" />
                                    <p:menuitem value="Queues" url=""/>
                                    <p:menuitem value="Causes" url=""/>
                                    <p:menuitem value="SubCauses" url=""/>
                                </p:submenu>
                            </p:menu> 
                        </f:ajax>
                    </h:form>

                    <h:panelGroup id="content" layout="block">
                         <ui:include src = "../views/#{KpiBean.page}.xhtml"/>
                    </h:panelGroup>
                </h:panelGrid>
            </h:form>
        </h:body>
    </f:view>
</html>

在这里我的豆子:

@Named
@SessionScoped
public class KpiBean implements Serializable {

    private String page= "View";

    @PostConstruct
    public void init() {
        page = "View"; //  Default include.
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

}

当我启动Glassfish服务器并部署构建时,我收到了错误:

javax.faces.view.facelets.TagAttributeException: /templates/template.xhtml @47,78 <ui:include src="../views/#{KpiBean.page}.xhtml"> Invalid path : ../views/.xhtml

    at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:129)

    at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)

1 个答案:

答案 0 :(得分:2)

实际上你的bean名为kpiBean(camelCase命名,小写的第一个字母)。