Empty Portlet body in custom portlet - liferay

We have a custom portlet having an MVCActionCommand invoked from another portlet. MVCActionCommand executed successfully but on the page it's showing empty portlet body in results page. Expected is jsp is having data to render based on response and we are having static html code like input text and tabs to filter data.
We are using below code in Controller to redirect to JSP
actionResponse.setRenderParameter("jspPage", "/META-INF/resources/results_page.jsp);
Main issue is, this we are facing only in PROD environment, UAT & local environment it's working fine
Below is my portlet #component values.
#Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.search",
"com.liferay.portlet.instanceable=false",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.init-param.add-process-action-success-action=false",
"javax.portlet.name=SearchResults",
"javax.portlet.resource-bundle=content.Language",
"com.liferay.portlet.add-default-resource=true",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
Redirection to page is happening correctly but portlet body is empty. In this page I have some static HTML code in this page and its also not loading.
Why different environments have different behavior for same piece of code? Below is the screen shot.

I would recommend that you use the "mvcPath" parameter since "jspPath" is deprecated. Example usage: EditUserOrganizationsMVCActionCommand.java

Related

Different kind of redirection in a portlet

I would like to know the different kind of redirections in the portets and how to realize them. How to go from one view (jsp file) to another in the same portlet, how to go from one page to another from a portlet. It is for the purpose of making a form so I would like to do this in a processAction.
Your answer is not clear.
However, in Liferay, you can route your application using urls.
For example, you can create a portlet action url on your own.
You can try something like this:
HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));
PortletURL oPortletURL = PortletURLFactoryUtil.create(request, <portletName> , <plid>, <portletPhase>);
oPortletURL.setParameter("myParameter1", "parameter1");
String portletURL = oPortletURL.toString();
Where:
<portletName> is the javax.portlet.name of your portlet
<plid> is the ID of a page where is located an instance of your <portletName> portlet (try to check Layout and LayoutFriendlyUrl tables)
<portletPhase> is the phase you need, for example PortletRequest.ACTION_PHASE
Finally, you can use setParameter() method to pass parameters in query string.
On the jsp for a single portlet: If you use Liferay's MVCPortlet, you can just add the mvcPath parameter with the name of the JSP, to make sure your portlet renders with this JSP. Nothing else.
Pages have a URL. If you want to redirect to another page, you'll have to configure the page's URL somewhere. However, that's rarely done unless you're implementing a Navigation portlet. Your question sounds more like you have a multi-page portlet.

display a success message on different portlet

I have form on a porlet, after submission of that form, page is redirecting to another portlet for that i am using actionResponse.sendRedirect("/abc/bcd/newWebPage")
and i am landing on to different page. One that page the same potlet is added with different screen, Now i want to display a success message on next page.
for that i am using portlet session and passing parameter to jsp.
PortletSession session = actionRequest.getPortletSession();
session.setAttribute("SUCCESSA", "Successfully",PortletSession.APPLICATION_SCOPE);
But its not working.
Any help how to achieve that?
When you say One that page the same potlet is added with different screen, I understand that you have another instance of the same portlet in different page. By the way, you haven't explained what is not working for you. I assume you are wondering how to read in the JSP page. It's pretty straight forward:
In Controller:
PortletUtils.setSessionAttribute(request, "SUCCESSA", "Successfully", PortletSession.APPLICATION_SCOPE);
In JSP:
pageContext.setAttribute("succcessa", PortletUtils.getSessionAttribute(renderRequest, "SUCCESSA", PortletSession.APPLICATION_SCOPE));
The PortletUtils does the same as setting the attribute using the PortletRequest object but its preferrable.
To remove the session attribute:
PortletUtils.setSessionAttribute(request, "SUCCESSA", null, PortletSession.APPLICATION_SCOPE);
The implementation of PortletUtils is that it removes the session attribute if value is null, if a session existed at all.

JSF web application -- opening a particular page based on url parameters

Our project uses a Web Application developed using JSF, primefaces, xhtml. Currently user can login and navigate through pages sequentially by clicking on 'action' links, like:-
index.xhtml --> login.xhtml --> classes.xhtml --> students.xhtml --> student_info.xhtml
i.e. first login --> shows the list of classes --> user selects a class --> shows the list of students in that class --> user selects a student --> shows the student info.
Each of the pages has its own 'backing bean' classes. They are instantiated as and when the user clicks through the pages.
Also, user can navigate back via certain links on each page-- say, from 'student_info' page, he/she can go back to the 'students' page.
Now requirement is: user can directly go to an inner page, say, student_info page by typing an 'url' with additional parameters, ?user=alice,?passwd=xyz, ?class=5, ?studentRollNo=15.
Also, the user should still be able to navigate back to other pages (i.e. once the page is opened, their should be no behavior difference whether the user navigated normally to student_info page or, whether he directly provided url with parameters).
My questions are:-
How to read url parameters in JSF?
Which page (or backing bean) should handle the parameters? Should it be done centrally, or, in each page (backing bean) ?
In case each page handles its relevant parameters only -- is there way to redirect remaining parameters to the next page ?
What are the best practices used in such implementations?
Note:
Actual web application is much more complex, tried to provide a simpler picture which pinpoints my problem.
new to JSF, Web App etc. Don't know if there are some JSF terminologies to describe above issues.
you can pass it by url request, and each BackingBean handle it
ex:
mypage.xhtml?myparam=test
and inject the HttpServletRequest in your BackingBean (if you are using CDI)
#Inject
HttpServletRequest request;
and get the param
#PostConstruct
public void init() {
String myparam = request.getParameter("myParam");
}
for redirect to other page you can use
public String redirect() {
return "otherPage.xhtml?faces-redirect=true&otherParam=test";
}

Cannot use attribute forms in page template?

I am using JDeveloper 11.1.2.3.0
I have to show a popup by clicking a link that is located in the page template. For this I created a popup within the pageTemplate then inserted a dialogBox and within the dialog box I dragged and dropped my VO from the DataControl panel and inserted it as an ADF form. The problem is that when I run and click the link (that contains the "ShowPopupBehavior") I am getting this error:
//C:/Oracle/Middleware/jdeveloper/jdev/system11.1.2.3.39.62.76.1/MyNew/ViewControllerWebApp.war/WEB-INF/templates/myTemplates.jsf #58,118 value="#{bindings.TypeName.inputValue}": Target Unreachable, 'TypeName' returned null
ADF_FACES-60097:For more information, please see the server's error log for an entry beginning with: ADF_FACES-60096:Server Exception during PPR, #2
This happens for every View that I can insert here. Is this comming because I am not allowed to insert ADF forms within the page template?
If so please give me a hint to achieve what I explained in the first sentence.
I just figured out the solution to this problem. Each page has its own bindings, so a page that uses the templates (or if want to use bindings from other pages) has to declare that page in the Executables section of the page Bindings. The new executable should have the ID of the page (of the template in this case) and the path of the page. Then the bindings of the template can be accessed as explained here:
public String cb1_action() {
BindingContext bctx = BindingContext.getCurrent();
DCBindingContainer bindings =
(DCBindingContainer)bctx.getCurrentBindingsEntry();
//access the page template Pagedef file reference in the
//Executable section of the consumer page's Pagedef file
DCBindingContainer templateBinding =
(DCBindingContainer)bindings.get("ptb1");
//get the MethodBinding
OperationBinding printMethod =
(OperationBinding)templateBinding .get("printThis");
//invoke the print method exposed on the template's PageDef file
printMethod.getParamsMap().put("message","Hello World");
printMethod.execute();
return null;
}
https://blogs.oracle.com/jdevotnharvest/entry/how_to_invoke_adf_bindings
ps: Pay attention not to bind the value of the template in your page ex: value="#{bindings.ptb1}" - it is a bit strange but in this case you will not get the page bindings and will get only the template ones.
The value property containing #{bindings.ptb1} should be removed from the pageTemplate tag but the ptb1 reference has to be in the pages PageDef file.

What is the difference between doView() and render() functions in Liferay?

What is the actual difference between doView() and render() functions in Liferay? and also what is the difference between renderRequest and resourceRequest?
doView() = to handle render requests when in VIEW mode.
render() = This method invokes the doDispath() method and sets the title of the portlet by using getTitle() method. Then it invokes one of doView(), doEdit(), doHelp(), etc. depending of the portlet mode specified in the RenderRequest.
Again, RenderRequest is when you want to handle requests in the VIEW mode of the portlet. If your portlet uses additional resources to render the view (i.e. images, JavaScript files, etc.) then the JSP that renders the view will use <portlet:resourceURL /> tags to generate valid URLs to those resources. Those URLs will be processed with a pair of ResourceRequest and ResourceResponse objects.
You can override the resource phase though but bear in mind that when you use ResourceRequest/ResourceResponse to serve, the portlet can't change the current portlet mode, window state or render parameters. And also the parameters set on the resource urls are not the render parameters and they are valid to serve only that current resource request.

Resources