-1

在向数据库添加一些值时出现以下错误。

我的错误跟踪如下

...
    10:06:10,730 INFO  [RestaurantPortlet:35] Inside addRegistration
    10:06:10,731 INFO  [RestaurantPortlet:40] {Resto_ID=0, Name=KFC, Location=AHMEDABAD, Room_Count=0, Table_Count=0, userId=10196, companyId=10154, groupId=10180, Reseller_ID=0}
    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).......

那么我的行动方法中的错误是什么?

这是我的服务班

/**
 * 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.setResto_ID(restoParam.getResto_ID());
        restoVar.setName(restoParam.getName());
        restoVar.setLocation(restoParam.getLocation());
        restoVar.setRoom_Count(restoParam.getRoom_Count());
        restoVar.setTable_Count(restoParam.getRoom_Count());
        restoVar.setCompanyId(restoParam.getCompanyId());
        restoVar.setUserId(restoParam.getUserId());
        restoVar.setGroupId(restoParam.getGroupId());
        restoVar.setReseller_ID(restoParam.getReseller_ID());



        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();
        }
    }
}

我的 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);

            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 ;
        }


    }

    /*
    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");

        }

    }

*/

请指导我在哪里做错了..

我在资源操作文件夹中的 default.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>DELETE</action-key>
                <action-key>UPDATE</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>UPDATE</action-key>
                <action-key>DELETE</action-key>
            </guest-unsupported>
        </permissions>
    </model-resource>

</resource-action-mapping>

这是我的restuarntactionutilclass,我怀疑这里出了什么问题……但不知道我是对还是错。请检查一下……

package com.test.util;

import java.util.List;

import javax.portlet.ActionRequest;

import com.test.model.Restaurant;
import com.test.model.impl.RestaurantImpl;

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;


/*Apr 20, 2011
 5:17:37 PM
 */
public class RestaurantActionUtil {

    public static Restaurant getRestaurantFromRequest(ActionRequest request) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request
                .getAttribute(WebKeys.THEME_DISPLAY);
        String Name = ParamUtil.getString(request, "Name",
                "Name Not Availible");
        String Location = ParamUtil.getString(request, "Location",
                "Location Not Availible");
        String table_count = ParamUtil.getString(request, "Table_Count", "0");
        String room_count=ParamUtil.getString(request, "Room_Count","0");
        String reseller_id=ParamUtil.getString(request, "Reseller_ID","0");

        int table = Integer.parseInt(table_count);



        int room = Integer.parseInt(room_count);



        int reseller = Integer.parseInt(reseller_id);


        Restaurant resto = new RestaurantImpl();
        resto.setName(Name);
        resto.setLocation(Location);
        resto.setTable_Count(table);
        resto.setRoom_Count(room);
        resto.setReseller_ID(reseller);
        resto.setCompanyId(themeDisplay.getCompanyId());
        resto.setGroupId(themeDisplay.getLayout().getGroupId());
        resto.setUserId(themeDisplay.getUserId());

        return resto;
    }


}

对象恢复总是为空

4

3 回答 3

2

有两个选项可能会有所帮助:

  1. 将此添加到 liferay-portlet.xml

    添加默认资源标签

  2. 或者通过提供另一个 xml 在您的自定义服务中添加操作。查看http://www.liferay.com/community/wiki/-/wiki/Main/Permissioning+in+Plugin+Environment#section-Permissioning+in+Plugin+Environment-Step+1

于 2012-09-28T11:47:41.497 回答
1

也许这有帮助http://www.liferay.com/community/forums/-/message_boards/message/3465412

于 2012-09-28T10:22:39.513 回答
-1

我刚刚在 Liferay 数据库的资源操作表中编辑了一个条目,其中包含我想要添加的操作,例如“addRestaurant”,最后是它的工作。

于 2012-10-01T09:14:30.240 回答