此行的多个标记 - 字符串无法解析为变量 - 令牌“food”上的语法错误,删除

时间:2014-09-12 21:26:29

标签: eclipse liferay

我遇到这个错误: 1-此行的多个标记 - 字符串无法解析为变量 - 令牌“food”上的语法错误,删除

2-此行的多个标记      - 令牌“详细信息”上的语法错误,删除      这个标记      - 字符串无法解析为变量

我在NewPortlet.java

中用**标记了这些行

。以下是我的两个相关文件

NewPortlet.java

package com.test;

import java.io.IOException;
import java.util.Date;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;


public class NewPortlet extends MVCPortlet {

  public static String VIEW_JSP ="/html/new/view.jsp";

  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse ) throws IOException, PortletException {
    //renderRequest
    super.doView(renderRequest, renderResponse);
  }

  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)  throws IOException, PortletException {
    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
        try {
          if (cmd.equals(Constants.ADD)){

            String food = ParamUtil.getString(actionRequest, "food");
            String detail = ParamUtil.getString(actionRequest, "detail");

            long userId = CounterLocalServiceUtil.increment();
            User user_= UserLocalServiceUtil.createUser(userId);

         ** user_.setFood(food);
         ** user_.setDetail(detail);
            user_.setCreateDate(new Date());

            UserLocalServiceUtil.updateUser(user_ , false);
            SessionMessages.add(actionRequest,"food-added-succesfuly");
          }
        }catch (SystemException e) {
            //TODO Auto-generated Catch block
            e.printStackTrace();
        }
        super.processAction(actionRequest, actionResponse);
    }
  }
}

和我的服务构建商

<entity name="Food" local-service="true" remote-service="true">

        <!-- PK fields -->

        <column name="foodId" type="long" primary="true" />

        <!-- Group instance -->

        <column name="food" type="string" />
        <column name="detail" type="string" />
        <column name="createDate" type="new Date()" />
    ...

1 个答案:

答案 0 :(得分:2)

您正在尝试添加Food实体,但您已使用用户实体。 用户实体没有任何属性/列作为食物或细节。

要添加Food实体,您必须使用以下代码。

long userId = CounterLocalServiceUtil.increment(Food.class); 
Food foodEntry_=FoodLocalServiceUtil.createFood(userId); 
foodEntry_.setFood(food); 
foodEntry_.setDetail(detail); 
foodEntry_ .setCreateDate(new Date()); 
FoodLocalServiceUtil.updateUser(foodEntry_ , false); 
SessionMessages.add(actionRequest,"food-added-succesfuly");