Liferay: Facelet portlet is empty
I have developed a simple facelet portlet. Changed the ViewHandler in the faces-config.xml
as it is said in the book:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config
1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config xmlns="http://java.sun.com/JSF/Configuration">
<application>
<view-handler>
com.sun.facelets.FaceletPortletViewHandler
</view-handler>
</application>
<factory>
<faces-context-
factory>com.liferay.util.bridges.jsf.myfaces.MyFacesContextFactoryImpl</faces-
context-factory>
</factory>
</faces-config>
There are 2 .xhtml
pages: template.xhtml
<?xml version="1.0" encoding="UTF-8" ?>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<html>
<head>
</head>
<body>
<h:outputText value="block"></h:outputText>
<h:outputLabel value="label" for="input"/>
<h:inputText id="input"/>
JUST TEXT
<ui:insert name="insertBlock">
<h:outputText value="defaultText"></h:outputText>
</ui:inse开发者_运维百科rt>
</body>
</html>
and insertedBlock.xhtml
<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition template="template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<ui:define name="insertBlock">
<h:outputText value="Inderted block"/>
<h:outputLabel value="test label" for="testInput"/>
<h:inputText id="testInput"/>
</ui:define>
</ui:composition>
portlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>LiferayFirstPortlet_war_exploded</portlet-name>
<display-name>LiferayFirstPortlet_war_exploded</display-name>
<portlet-class>com.test.HelloWorld</portlet-class>
<init-param>
<name>default-view</name>
<value>insertedBlock.xhtml</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>LiferayFirstPortlet_war_exploded</title>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>
When I deploy this portlet on the Liferay - no errors are displayed. But when I add the portlet on a page IT IS EMPTY - just the empty rectangle. The code of the page (html code inspection in the fireBug) shown that there is no content in the portlet either.
What did I do wrong?
Did you include liferay specific artifacts? For a porlet to be deployed in liferay, the artifact needs some liferay specific configuration files. You can create a skeletal artifact using the Liferay Plugin SDK. (You can find it in, additional files download section.)
Or you can download the JSF samples and alter it to match your configuration.
精彩评论