0

I created a portlet, I generated the .jar of service and move it to /tomcat/lib/ext. Then I created a hook that use the same BD. But when I try to do a 'DynamicQuery' in the hook it doesn't work, then I try to create a new function in RuleLocalServiceImpl.java, generate again the .jar and move it to /tomcat/lib/ext. But it doesn't work, when I try to execute I have this error:

java.lang.NoSuchMethodError: com.segmentationPortlet.service.RuleLocalServiceUtil.getActiveRule(Ljava/util/Date;)Ljava/util/List;

This is de code of function:

public class RuleLocalServiceImpl extends RuleLocalServiceBaseImpl {
   /*
    * NOTE FOR DEVELOPERS:
    *
    * Never reference this interface directly. Always use {@link com.segmentationPortlet.service.RuleLocalServiceUtil} to access the rule local service.
    */
    public List<Rule> getActiveRule(Date lastLogin) throws SystemException {
        DynamicQuery dq_rules = DynamicQueryFactoryUtil.forClass(Rule.class, PortalClassLoaderUtil.getClassLoader())
            .add(PropertyFactoryUtil.forName("modifiedDate").ge(lastLogin))
            .add(PropertyFactoryUtil.forName("status").eq(true));

            List<Rule> listRules = RuleLocalServiceUtil.dynamicQuery(dq_rules);
            return listRules;
    }
}

I tried stop the tomcat, delete the .jar and create again but don't work.

This is the code of hook:

package com.segmentationProjecthookLogin.hook;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.segmentationPortlet.model.ConditionsRule;
import com.segmentationPortlet.model.Rule;
import com.segmentationPortlet.service.ConditionsRuleLocalServiceUtil;
import com.segmentationPortlet.service.RuleLocalServiceUtil;


public class LoginAction extends Action {

    private static boolean  isVelocityEngineStarted = false;
    public void run(HttpServletRequest req, HttpServletResponse res) {     
        System.out.println("Login");
        User user;
        try {
            user = PortalUtil.getUser(req);     
            Date lastLogin = user.getLastLoginDate();
            List<Rule> listRule = RuleLocalServiceUtil.getActiveRule(lastLogin);
            System.out.println("Size " + listRule.size());
        } catch (PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (com.liferay.portal.kernel.exception.SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (com.liferay.portal.kernel.exception.PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}

Thank you!

4

2 に答える 2

0

ありがとう!しかし、私は問題を解決しました。間違いは、フックが古いバージョンの .jar を使用していたことです。私はここにリンクを置きます:

https://www.liferay.com/es/community/forums/-/message_boards/message/29010435

于 2013-09-25T08:01:57.737 に答える