添加数据时liferay portlet中的NoSuchMethodException

时间:2012-09-28 06:56:58

标签: jsp model-view-controller liferay liferay-6 portlet

我正在使用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类方法addRestaurant ..

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>

5 个答案:

答案 0 :(得分:1)

您的方法:public Restaurant addreRestaurant(Restaurant restoParam)
portlet所需的方法:addreRestaurant(javax.portlet.ActionRequest,javax.portlet.ActionResponse)

答案 1 :(得分:1)

你的mvc类方法名是 addRestaurant (),而你的jsp需要:

名称= “的 addreRestaurant

方法名称是不同的:)

答案 2 :(得分:1)

您的新堆栈跟踪与其他错误有关。 问题出在RestauranteServiceImpl.addreRestaurant()中,更具体地说是片段:

resourceLocalService.addResources(restoParam.getCompanyId(),
                    restoParam.getGroupId(), restoParam.getUserId(),
                    Restaurant.class.getName(), restoParam.getPrimaryKey(),false,
                    true, true);

这意味着您没有与您的类或portlet相关的资源操作。您是否定义了资源 - 动作映射?

答案 3 :(得分:1)

我最后完成了这些事情......在数据库中,在actionrescources表中没有关于我的addRestaurant操作的条目。

经过大量的R&amp; D发现...我必须手动添加该表中的addRestaurant条目才能正常工作。

我现在正在搜索它是如何不自动添加资源操作的。

答案 4 :(得分:0)

正在运行

  

服务助洗剂

为我解决了这个问题。