0

私はliferayを使用しており、機能を追加するだけの独自のポートレットを作成しました.しかし、本の追加でエラーが発生する方法がいくつかあります

これは私の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のメソッドが見つからないという問題に直面していますが、そのメソッドがあります.soどこで間違いを犯していますか?

エラーは次のとおりです。

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

以下は、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 ERROR [RestaurantPortlet:43] REsto が Null であることが判明しました

マイ アクション リソース マッピング 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>
4

5 に答える 5

1

私はついに物事を成し遂げました...データベースには、actionrescocesテーブルに私のaddRestaurantアクションに関するエントリがありません。

多くの研究開発がそれを発見した後..そのテーブルに addRestaurant エントリを手動で追加するだけで、うまくいきました。

resourceaction にエントリが自動的に追加されない理由を調べています。

于 2012-09-29T17:30:36.427 に答える
1

MVC クラスのメソッド名はaddRestaurant () ですが、jsp には以下が必要です。

name=" addreRestaurant "

メソッド名は異なります:)

于 2012-09-28T13:16:10.373 に答える
1

新しいスタック トレースは別のエラーに関連しています。問題は RestauranteServiceImpl.addreRestaurant() 、より具体的にはスニペット内にあります。

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

これは、クラスまたはポートレットに関連するリソース アクションがないことを意味します。resource-action-mapping を定義しましたか?

于 2012-09-28T15:04:21.670 に答える
1

Your method :public Restaurant addreRestaurant(Restaurant restoParam)
ポートレットで必要なメソッド:addreRestaurant(javax.portlet.ActionRequest,javax.portlet.ActionResponse)

于 2012-09-28T07:00:30.420 に答える
0

ランニング

サービスビルダー

私の問題を修正しました。

于 2013-01-16T10:47:22.510 に答える