我已經嘗試覆蓋現有的StrutsPortletAction之前,他們現有的struts路徑成功。但是,如果我嘗試創建自己的struts操作路徑,我似乎無法做到這一點。如何創建一個新的(原始)struts路徑?
<hook>
<custom-jsp-dir>/custom_jsps</custom-jsp-dir>
<struts-action>
<struts-action-path>/portal/set_viewers/</struts-action-path>
<struts-action-impl>com.mine.blogs.hook.BlogEntryViewerStrutsPortletAction</struts-action-impl>
</struts-action>
</hook>
的Eclispe的IDE給我這個錯誤「/門戶/ set_viewers /」是不是中可能的值」,當我繼續前進,因爲反正部署內置戰爭,tomcat的錯誤:com.liferay.portal.kernal.util.InstanceFactory can not access a member of class com.mine.blogs.hook.BlogEntryViewerStrutsPortletAction with modifiers ""
試圖與Struts的行動路徑/blogs/set_viewers/
也失敗了。
這是我使用。其實很基本的的.java。
package com.mine.blogs.hook;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import com.liferay.portal.kernel.struts.StrutsPortletAction;
public class BlogEntryViewerStrutsPortletAction implements StrutsPortletAction {
BlogEntryViewerStrutsPortletAction(){
super();
}
@Override
public void processAction(
PortletConfig arg0, ActionRequest arg1, ActionResponse arg2)
throws Exception {
// TODO Auto-generated method stub
System.out.println("process1");
}
@Override
public void processAction(
StrutsPortletAction arg0, PortletConfig arg1, ActionRequest arg2,
ActionResponse arg3)
throws Exception {
// TODO Auto-generated method stub
System.out.println("process2");
}
@Override
public String render(
PortletConfig arg0, RenderRequest arg1, RenderResponse arg2)
throws Exception {
// TODO Auto-generated method stub
System.out.println("render1");
return null;
}
@Override
public String render(
StrutsPortletAction arg0, PortletConfig arg1, RenderRequest arg2,
RenderResponse arg3)
throws Exception {
// TODO Auto-generated method stub
System.out.println("render2");
return null;
}
@Override
public void serveResource(
PortletConfig arg0, ResourceRequest arg1, ResourceResponse arg2)
throws Exception {
// TODO Auto-generated method stub
System.out.println("serve1");
}
@Override
public void serveResource(
StrutsPortletAction arg0, PortletConfig arg1, ResourceRequest arg2,
ResourceResponse arg3)
throws Exception {
// TODO Auto-generated method stub
System.out.println("serve2");
}
}
而相應的liferay-hook.xml
<hook>
<custom-jsp-dir>/custom_jsps</custom-jsp-dir>
<struts-action>
<struts-action-path>/blogs_entry/set_viewers/</struts-action-path>
<struts-action-impl>com.mine.blogs.hook.BlogEntryViewerStrutsPortletAction</struts-action-impl>
</struts-action>
</hook>
您是否使用BaseStrutsPortletAction擴展BlogEntryViewerStrutsPortletAction? – Haris
是的,做到了。但是我也意識到,IDE並沒有提示我創建重寫所需的方法,比如render,processAction等。 – MerC
它不是強制性的以覆蓋所有的方法,BaseStrutsPortletAction類具有方法的基本實現。 – Haris