Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

liferay - ResourceActionsException While adding the value in database in my own portal

I am having Following error while adding some value to database.

My Error trace is as follows

...
    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).......

So Whats the mistake in my acrtion methods?

This is my serviceiml class

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

My Portlet class is as follows...

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

        }

    }

*/

Please Guide me that where am doing mistake..

My default.xml in resource action folder

<?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>

This is my restuarntactionutilclass and i have doubt that something goes wrong here..but don't know am i right or wrong.please check it...

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


}

The object resto is always coming null

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are 2 option that might help:

  1. Add this to liferay-portlet.xml

    add-default-resource tag

  2. Or add actions in your custom service by supplying another xml. Check out http://www.liferay.com/community/wiki/-/wiki/Main/Permissioning+in+Plugin+Environment#section-Permissioning+in+Plugin+Environment-Step+1


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...