我正在使用liferay,并且我创建了自己的portlet,它刚刚添加了功能。但是我在添加书籍时遇到了一些错误
这是我的 view.jsp
<%@ include file="/init.jsp"%>
<%
Restaurant resto = (Restaurant) request.getAttribute("Restaurant");
if (resto == null) {
resto = new RestaurantImpl();
resto.setTable_Count(1);
}
%>
<liferay-portlet:actionURL name="addreRestaurant" var="addreRestaurantURL"></liferay-portlet:actionURL>
<aui:form action="<%=addreRestaurantURL.toString() %>" method="post" name="fm">
<aui:fieldset>
<%-- <liferay-ui:error key="title-required" message="title-required" /> --%>
<p>
<aui:input name="Name" label="Name" type="text"
value="<%=resto.getName()%>"></aui:input>
</p>
<%-- <liferay-ui:error key="author-required" message="author-required" /> --%>
<p>
<aui:input name="Location" label="Location" type="text"
value="<%=resto.getLocation() %>"></aui:input>
</p>
<%-- <liferay-ui:error key="pages-required" message="pages-required" />
<liferay-ui:error key="pages-cannot-be-zero"
message="pages-cannot-be-zero" /> --%>
<p>
<aui:input name="table_count" label="Table_count" type="text"
value="<%=String.valueOf(resto.getTable_Count()) %>"></aui:input>
</p>
<p>
<aui:input name="room_count" label="Room_count" type="text"
value="<%=String.valueOf(resto.getRoom_Count()) %>"></aui:input>
</p>
<p>
<aui:input name="reseller_ID" label="Reseller_ID" type="text"
value="<%=String.valueOf(resto.getReseller_ID()) %>"></aui:input>
</p>
<p>
<aui:button class="aui-button-input" type="submit" value="Submit" />
<aui:button class="aui-button-input" type="reset" value="Reset" />
</p>
</aui:fieldset>
</aui:form>
<liferay-ui:search-container emptyResultsMessage="no-restaurant" delta="5">
</liferay-ui:search-container>
以下是我的服务实现类
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.test.service.impl;
import java.util.Collections;
import java.util.List;
import com.test.model.Restaurant;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.test.service.base.RestaurantServiceBaseImpl;
/**
* The implementation of the restaurant remote service.
*
* <p>
* All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.test.service.RestaurantService} interface.
*
* <p>
* This is a remote service. Methods of this service are expected to have security checks based on the propagated JAAS credentials because this service can be accessed remotely.
* </p>
*
* @author bhavik.kama
* @see com.test.service.base.RestaurantServiceBaseImpl
* @see com.test.service.RestaurantServiceUtil
*/
public class RestaurantServiceImpl extends RestaurantServiceBaseImpl {
public Restaurant addreRestaurant(Restaurant restoParam) {
Restaurant restoVar;
try {
restoVar = restaurantPersistence.create((int) counterLocalService
.increment(Restaurant.class.toString()));
} catch (SystemException e) {
e.printStackTrace();
return restoVar = null;
}
try {
resourceLocalService.addResources(restoParam.getCompanyId(),
restoParam.getGroupId(), restoParam.getUserId(),
Restaurant.class.getName(), restoParam.getPrimaryKey(),false,
true, true);
} catch (PortalException e) {
e.printStackTrace();
return restoVar = null;
} catch (SystemException e) {
e.printStackTrace();
return restoVar = null;
}
restoVar.setLocation(restoParam.getLocation());
restoVar.setCompanyId(restoParam.getCompanyId());
restoVar.setResto_ID(restoParam.getResto_ID());
restoVar.setUserId(restoParam.getUserId());
restoVar.setGroupId(restoParam.getGroupId());
restoVar.setName(restoParam.getName());
restoVar.setRoom_Count(restoParam.getRoom_Count());
restoVar.setTable_Count(restoParam.getRoom_Count());
restoVar.setUserId(restoParam.getUserId());
try {
return restaurantPersistence.update(restoVar, false);
} catch (SystemException e) {
e.printStackTrace();
return restoVar = null;
}
}
public List<Restaurant> getAllerRestaurants() {
try {
return restaurantPersistence.findAll();
} catch (SystemException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
public List<Restaurant> getAllreRestaurants(long groupId, String title) {
try {
return restaurantPersistence.findByGroupId(groupId);
} catch (SystemException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
}
在出现错误之后,我面临着它无法找到 addreRestaurant 方法的问题,但我有那个方法。那么我在哪里做错了?
错误如下:
SEVERE: Servlet.service() for servlet TabsTest Servlet threw exception
java.lang.NoSuchMethodException: com.liferay.util.bridges.mvc.MVCPortlet.addreRestaurant(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
at java.lang.Class.getMethod(Class.java:1605).....
如下是我添加餐厅的 Portlet 类方法。
package com.test.portlet;
import java.util.ArrayList;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.test.model.Restaurant;
import com.test.service.RestaurantServiceUtil;
import com.test.util.RestaurantActionUtil;
import com.test.util.RestaurantValidator;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.util.bridges.mvc.MVCPortlet;
/**
* Portlet implementation class BooksPortlet
*/
public class RestaurantPortlet extends MVCPortlet {
private static Log log = LogFactory.getLog(RestaurantPortlet.class);
private static String errorJSP="/jsps/error.jsp" ;
public void addRestaurant(ActionRequest request, ActionResponse response) {
log.info("Inside addRegistration");
List<String> errors=new ArrayList<String>();
Restaurant resto=RestaurantActionUtil.getRestaurantFromRequest(request);
boolean bookValid=RestaurantValidator.validateBook(resto, errors);
if(bookValid) {
log.info(resto);
Restaurant test=RestaurantServiceUtil.addreRestaurant(resto);
if(test==null) {
log.error("REsto was Found Null");
//response.setRenderParameter("jspPage", errorJSP);
return ;
}
SessionMessages.add(request,"book-added");
return ;
}
else {
for (String error : errors) {
SessionErrors.add(request, error);
}
SessionErrors.add(request, "error-while-adding");
request.setAttribute("Restaurant",resto);
return ;
}
}
/*
public void deleteBooks(ActionRequest request, ActionResponse response) {
long bookId = ParamUtil.getLong(request, "bookId");
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(
WebKeys.THEME_DISPLAY);
if (Validator.isNotNull(bookId)) {
BooksLocalServiceUtil.deleteBooks(bookId, themeDisplay.getCompanyId());
SessionMessages.add(request, "book-deleted");
} else {
SessionErrors.add(request, "error-deleting");
}
}
*/
}
这是我的新错误跟踪...
14:16:50,870 INFO [RestaurantPortlet:35] Inside addRegistration
14:16:50,872 INFO [RestaurantPortlet:40] {Resto_ID=0, Name=dasd, Location=ads, Room_Count=2, Table_Count=1, userId=10196, companyId=10154, groupId=10180, Reseller_ID=55}
com.liferay.portal.ResourceActionsException: There are no actions associated with the resource com.test.model.Restaurant
at com.liferay.portal.service.impl.ResourceLocalServiceImpl.validate(ResourceLocalServiceImpl.java:1348)
at com.liferay.portal.service.impl.ResourceLocalServiceImpl.addResources(ResourceLocalServiceImpl.java:845)
at com.liferay.portal.service.impl.ResourceLocalServiceImpl.addResources(ResourceLocalServiceImpl.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...................... 14:16:50,878 错误 [RestaurantPortlet:43] REsto 被发现为空
我的动作资源映射 xml..
<?xml version="1.0" encoding="UTF-8"?>
<resource-action-mapping>
<portlet-resource>
<portlet-name>RestaurantPortlet</portlet-name>
<permissions>
<supports>
<action-key>addRestaurant</action-key>
<action-key>VIEW</action-key>
</supports>
<community-defaults>
<action-key>VIEW</action-key>
</community-defaults>
<guest-defaults>
<action-key>VIEW</action-key>
</guest-defaults>
<guest-unsupported>
<action-key>addRestaurant</action-key>
</guest-unsupported>
</permissions>
</portlet-resource>
<model-resource>
<model-name>com.test.Restaurant</model-name>
<portlet-ref>
<portlet-name>RestaurantPortlet</portlet-name>
</portlet-ref>
<permissions>
<supports>
<action-key>addRestaurant</action-key>
<action-key>VIEW</action-key>
</supports>
<community-defaults>
<action-key>VIEW</action-key>
</community-defaults>
<guest-defaults>
<action-key>VIEW</action-key>
</guest-defaults>
<guest-unsupported>
</guest-unsupported>
</permissions>
</model-resource>
</resource-action-mapping>