掲示板

Custom portlet ADT - Content not showing

thumbnail
7年前 に Danielle Ardon によって更新されました。

Custom portlet ADT - Content not showing

Junior Member 投稿: 37 参加年月日: 16/06/06 最新の投稿
Hi!

I have created a simple custom liferay mvc portlet that displays products in a database. You can add products and delete them etc.
I'm quite new to liferay and as an excercise, I wanted to created a simple ADT that displays them in a simple list instead of a search container. I have a custom portletdisplaytemplatehandler, and it is added to liferay-portlet.xml. Also I have added all custom permissions etc. I have added a configuration jsp so you can choose an ADT. Lastly in the view I have added all the relevant code in the view.jsp to change the display when an ADT is added.
Somehow when I choose the ADT, the portlet does not show any more content. I have no idea what I am doing wrong. Does anyone know? I have added screenshots and all the relevant code.
view.jsp
<%@include file="init.jsp" %>


<%String redirect = PortalUtil.getCurrentURL(renderRequest); %>
&lt;%!com.liferay.portal.kernel.dao.search.SearchContainer<artikel> searchContainer = null;%&gt;
<portlet:renderurl var="addArtikelURL">
	<portlet:param name="mvcPath" value="/html/bestelliferay/add_artikel.jsp" />
	<portlet:param name="redirect" value="<%= redirect %>" />
</portlet:renderurl>
		


&lt;%
String displayStyle = GetterUtil.getString(portletPreferences.getValue("displayStyle", StringPool.BLANK));
long displayStyleGroupId = GetterUtil.getLong(portletPreferences.getValue("displayStyleGroupId", null), scopeGroupId);
long portletDisplayDDMTemplateId = PortletDisplayTemplateUtil.getPortletDisplayTemplateDDMTemplateId(displayStyleGroupId, displayStyle);
%&gt;

<c:choose>
    <c:when test="<%= portletDisplayDDMTemplateId > 0 %>">
    	&lt;% List<artikel> artikelen = ArtikelLocalServiceUtil.getArtikelen(scopeGroupId);
        PortletDisplayTemplateUtil.renderDDMTemplate(pageContext, portletDisplayDDMTemplateId, artikelen); 
        %&gt;
	</artikel></c:when>
	
    <c:otherwise>
    
    <aui:button-row>
	<c:if test="<%= ArtikelModelPermission.contains(permissionChecker, scopeGroupId, &quot;ADD_ARTIKEL&quot;) %>">
		<aui:button name="addArtikelButton" value="add-artikel" onClick="<%=addArtikelURL %>" />
	</c:if>
</aui:button-row>
    
		<liferay-ui:search-container emptyresultsmessage="There are no results!">
			<liferay-ui:search-container-results results="<%= ArtikelLocalServiceUtil.getArtikels(searchContainer.getStart(), searchContainer.getEnd()) %>" total="<%= ArtikelLocalServiceUtil.getArtikelsCount() %>" />
		
			<liferay-ui:search-container-row classname="nl.dardon.bestel.portlet.model.Artikel" keyproperty="artikelId" modelvar="artikel">
			
				<liferay-ui:search-container-column-text name="artikelId" property="artikelId" />
		
				<liferay-ui:search-container-column-text name="artikelNaam" property="artikelnaam" />
		
				<liferay-ui:search-container-column-text name="artikelNummer" property="artikelnummer" />
		
				<liferay-ui:search-container-column-text name="artikelOmschrijving" property="artikelomschrijving" />
		
				<liferay-ui:search-container-column-text name="artikelPrijs" property="artikelprijs" />
				
				<liferay-ui:search-container-column-jsp path="/html/bestelliferay/artikel_actions.jsp" align="right" />
		
				
			</liferay-ui:search-container-row>
		
			<liferay-ui:search-iterator />
		</liferay-ui:search-container>
	</c:otherwise>
</c:choose>
</artikel>

freemarker code

&lt;#if entries?has_content&gt;
	&lt;#list entries as curArtikel&gt;
		${curArtikel.artikelnaam}
	<!--#list-->
<!--#if-->

liferay-portlet.xml
<!--?xml version="1.0"?-->


<liferay-portlet-app>
	
	<portlet>
		<portlet-name>bestel-liferay</portlet-name>
		<icon>/icon.png</icon>
		<configuration-action-class>com.liferay.portal.kernel.portlet.DefaultConfigurationAction</configuration-action-class>
        <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
		<friendly-url-mapping>artikel</friendly-url-mapping>
		<friendly-url-routes>nl/dardon/bestel/portlet/artikel-friendly-url-routes.xml</friendly-url-routes>
		<template-handler>nl.dardon.bestel.portlet.template.BestelliferayPortletDisplayTemplateHandler</template-handler>
        <instanceable>false</instanceable>
		<header-portlet-css>/css/main.css</header-portlet-css>
		<footer-portlet-javascript>
			/js/main.js
		</footer-portlet-javascript>
		<css-class-wrapper>bestel-liferay-portlet</css-class-wrapper>
	</portlet>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>guest</role-name>
		<role-link>Guest</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>power-user</role-name>
		<role-link>Power User</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>user</role-name>
		<role-link>User</role-link>
	</role-mapper>
	
</liferay-portlet-app>

templatehandler
package nl.dardon.bestel.portlet.template;

import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
import com.liferay.portal.kernel.template.TemplateVariableGroup;
import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import nl.dardon.bestel.portlet.model.Artikel;

public class BestelliferayPortletDisplayTemplateHandler extends BasePortletDisplayTemplateHandler {

	@Override
	public String getClassName() {
		return Artikel.class.getName();
	}

	@Override
	public String getName(Locale locale) {
		return "BestelliferayTemplate";
	}

	@Override
	public String getResourceName() {
		return "bestelliferay_WAR_bestelLiferayportlet";
	}
	
	@Override
	public Map<string, templatevariablegroup> getTemplateVariableGroups(
			long classPK, String language, Locale locale) throws Exception {

		Map<string, templatevariablegroup> templateVariableGroups = super
				.getTemplateVariableGroups(classPK, language, locale);

		TemplateVariableGroup templateVariableGroup = templateVariableGroups
				.get("fields");

		templateVariableGroup.empty();

		templateVariableGroup.addCollectionVariable("artikelen", List.class,
				PortletDisplayTemplateConstants.ENTRIES, "artikel", Artikel.class,
				"curArtikel", "artikelnaam");

		return templateVariableGroups;
	}

}</string,></string,>
thumbnail
7年前 に Fernando Fernandez によって更新されました。

RE: Custom portlet ADT - Content not showing

Expert 投稿: 396 参加年月日: 07/08/22 最新の投稿
Hi,

Maybe you don't need ADT for this. ADT are for customizing Liferay's apps output. If you are building your own app, you just build the output the way you want.

If you want to show a list instead of the searchcontainer, just put the UL/LI html code inside the portlet's JSP.

HTH

Fernando