I want get the keywords of the search with the portlet of Search. I saw that in the url appear: "struts_action=/search/seach" then I looked for in strut-config.xml and find:
action path="/search/search" forward="portlet.search.search"
I am trying to do a strut but I don't know very much about struts and it doesn't work. This is the code of 'liferay-hook.xml':
<portal-properties>portal.properties</portal-properties>
<struts-action>
<struts-action-path>/search/search</struts-action-path>
<struts-action-impl>com.segmentationProject.searchAction.struts.SearchAction</struts-action-impl>
</struts-action>
portal.properties:
auth.public.paths=/search/search
SearchAction.java:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.struts.BaseStrutsAction;
public class SearchAction extends BaseStrutsPortletAction {
#Override
public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
System.out.println("inside the process ");
super.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse);
}
#Override
public String render(StrutsPortletAction originalStrutsPortletAction,PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
// TODO Auto-generated method stub
System.out.println("inside the render");
return super.render(portletConfig, renderRequest, renderResponse);
}
}
Any idea about I missing or do wrong? I only want get the keywords and then do the search normally.
Thanks!
I think that this one will do the job :
String keywords = ParamUtil.getString(actionRequest, "keywords");
ParamUtil use the portlet namespace to retrieve parameters.
I think you must use originalStrutsPortletAction instead of super.
super.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse);
}
just replace super by originalStrutsPortletAction
originalStrutsPortletAction .processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse);
}
Related
I set default page URL in portal-ext.properties.
default.landing.page.path=/group/guest/home
Then create portlet with Controller :
public class UserPortrait extends MVCPortlet {
#Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) {
}
#Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
super.processAction(actionRequest, actionResponse);
}
}
Now , how to get landing page URL in processAction method.
Simply, use com.liferay.portal.kernel.util.PropsUtil.get(String propertyName) to get any property from portal-ext.properties file.
I have tried overriding existing StrutsPortletAction before with their existing struts path with success. However, I can't seem to do the same if I were to try creating my own struts action path.
<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>
The eclispe IDE gives me this error "/portal/set_viewers/" is not among possible values" and when I go ahead and deploy the built war anyways, tomcat errors as: com.liferay.portal.kernal.util.InstanceFactory can not access a member of class com.mine.blogs.hook.BlogEntryViewerStrutsPortletAction with modifiers ""
Tried with struts-action-path as /blogs/set_viewers/ failed as well.
This is the .java i'm using. Very basic actually.
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");
}
}
And the corresponding 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>
Please try changing the struts action URL to something other than starting with "/portal". Liferay may be reserving "/portal" for portal level action paths.
For example,
<struts-action-path>/blogs_entry/set_viewers/</struts-action-path>
The error was because of the Constructor. I've removed it and it's now deploying properly
I am overriding one of the actions of the calendar portlet . I want to do some functionality then redirect to another JSP after that. I tried using the sendRedirect function as follows:
1.
String redirect = ParamUtil.getString(actionRequest , "redirect");
actionResponse.sendRedirect(redirect);
2.
actionResponse.sendRedirect ("/calendar/view") ;
3.
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletURL url = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest), "8", themeDisplay.getPlid(),
PortletRequest.RENDER_PHASE);
url.setParameter("struts_action", "/calendar/view");
actionResponse.sendRedirect (url.toString()) ;
However, none of the methods cause the jsp to redirect to another one.
I am doing so in the processAction function and I am extending the BaseStrutsPortletAction.
Any suggestions how to solve it?
This is my overridden file :
public class TestAction extends BaseStrutsPortletAction {
public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
String cmdConstants = ParamUtil.getString(actionRequest, Constants.CMD);
if (cmdConstants.equals(Constants.APPROVE)) {
//some function
actionResponse.setRenderParameter("test", "test");
originalStrutsPortletAction.processAction(portletConfig, actionRequest, actionResponse);
}
}
public String render(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse) throws Exception {
String cmdConstants = ParamUtil.getString(renderRequest, Constants.CMD);
if (cmdConstants.equals(Constants.APPROVE)) {
if (renderRequest.getParameter("test").equals("test")) {
return "/portlet/calendar/view.jsp";
}
}
return originalStrutsPortletAction.render(null, portletConfig, renderRequest, renderResponse);
}
}
I have new action in a liferay hook which ideally will be calling methods created in an extension. But at run time when executing the action, it throws the exception
java.lang.ClassNotFoundException
for the methods created in the extension.
Has anybody created similar action in liferay hook? if so, what was the solution for this problem if encountered?
Here is my code:
public class ExampleStrutsAction extends BaseStrutsAction {
public String execute( HttpServletRequest request, HttpServletResponse response) throws Exception {
String name = ParamUtil.get(request, "name", "World");
ThemeDisplay themeDisplay= (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
BSCDynamicDataListLocalServiceUtil.cloneDynamicDataListPageInSuborganization(themeDisplay, name);
return "/portal/sample.jsp";
}
}
Try below code,
hook.xml
<hook>
<portal-properties>portal.properties</portal-properties>
<language-properties>
content/Language.properties
</language-properties>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<struts-action>
<struts-action-path>/my_account/edit_user</struts-action-path>
<struts-action-impl>com.test.hook.action.EditUserAction</struts-action-impl>
</struts-action>
<struts-action>
<struts-action-path>/users_admin/edit_user</struts-action-path>
<struts-action-impl>com.test.hook.action.EditUserAction</struts-action-impl>
</struts-action>
</hook>
EditUserAction class
public class EditUserAction extends BaseStrutsPortletAction
{
#Override
public void processAction(final StrutsPortletAction originalStrutsPortletAction, final PortletConfig portletConfig,
final ActionRequest actionRequest, final ActionResponse actionResponse) throws Exception
{
// add your custom code
originalStrutsPortletAction.processAction(portletConfig, actionRequest, actionResponse);
}
#Override
public String render(final StrutsPortletAction originalStrutsPortletAction, final PortletConfig portletConfig, final RenderRequest renderRequest,
final RenderResponse renderResponse) throws Exception
{
//add your custom code
return originalStrutsPortletAction.render(portletConfig, renderRequest, renderResponse);
}
}
I have created above hook for EditUserAction in Control Panel
Hope it helps you!!
Hi in JSF i need to perform some action when each request of the user ends. I need some kind of interceptor but i don't know how to do it. I need help with this please. Thanks
I recommend BalusC's blog: http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html
This article shows you how to intercept the JSF lifecycle and debug the information. This will also make it available for you to find out where your request ends.
If you posted some code here it could also help us find out where the true problem lies.
Here is an excerpt of the code that you need to implement to debug the lifecycle:
package mypackage;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
public class LifeCycleListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
public void beforePhase(PhaseEvent event) {
System.out.println("START PHASE " + event.getPhaseId());
}
public void afterPhase(PhaseEvent event) {
System.out.println("END PHASE " + event.getPhaseId());
}
}
If you want to have the FacesContext available, then the best place is the afterPhase of PhaseID.RENDER_RESPONSE inside a PhaseListener. For example:
public class MyPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void beforePhase(PhaseEvent event) {
// No operation here.
}
public void afterPhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
// Do your thing here with the FacesContext.
}
}
If you don't need the FacesContext, then the best place is after the line chain.doFilter(request, response) inside a Filter. For example:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
chain.doFilter(request, response);
// Do your thing here.
}