Liferay : How to receive the parameters of renderURL through a Portlet class - liferay-6

I read that the renderURL will be responsible to execute the renderPhase only (That is the doView Method of the java class )
Now in one of the JSP i have a Hyper Link to navigate to the another page as shown
(This is the starting page of the Portlet)
<a href="<portlet:renderURL>
<portlet:param name="goto" value="IpByHourPage"/>
<portlet:param name="jspPage" value="/page2.jsp" />
</portlet:renderURL>">
Click here to go to Second Page
</a>
Now my question is that , is it possible taht instead of getting the parameters inside the page2.jsp and processing it , is it possible that to recieve these parameters inside the java file that is
I want to recieve this parameters inside the SecondPort as shown below .
For example
public class SecondPort extends MVCPortlet {
public void doView(RenderRequest renderRequest, RenderResponse renderResponse throws IOException, PortletException
{
// do something in this code here .
}

Yes, you can get your parameter set in <portlet:param> tag in your portlet class.
You can read that parameter in doView method by following :-
public class SecondPort extends MVCPortlet {
public void doView(RenderRequest renderRequest, RenderResponse renderResponse throws
IOException, PortletException
{
String goto = renderRequest.getParameter("goto");
String jspPage= renderRequest.getParameter("jspPage");
//Do something here....
}
like this..

Related

CustomAction Types in AEM From Component

I am creating a form using form-components. I have email-field and UserName field. I want to send an email to the given email id on click of submit button. In the form I select my custom action type which invoke a servlet which is responsible to send an email. My custom action type has only forward.jsp as script file :
<%#page import="com.day.cq.wcm.foundation.forms.FormsConstants"%><sling:defineObjects/><%
System.out.println(":::::::::::::::"+resource.getPath());
FormsHelper.setForwardPath(slingRequest, resource.getPath() + ".custommail.html");
FormsHelper.setRedirectToReferrer(request, true);
%>
I can see my forward.jsp is getting called when i click submit button, as i can see resourcePath(content/geometrixx/en/toolbar/newsletter/jcr:content/par/start) in stdout.log. But servlet not getting call, In case i hit localhost:4502/content/geometrixx/en/toolbar/newsletter/jcr:content/par/start.custommail.html servlet gets invoke, don't know why its not invoking with FormsHelper.
And also how can we pass parameter i.e. email-field to servlet.
Any Idea.
Thanks
You need to have a servlet registered to your form start component and the proper selector. If you are using the foundation form this would be something like this:
#SlingServlet(resoruceTypes = "foundation/components/form/start", methods = "POST", selectors = "custommail", extenstions = "html", generateComponent = false)
public class CustomMailServlet extends SlingAllMethodsServlet {
#Override
protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException {
//your code here
}
}
Checkout this blog http://labs.sixdimensions.com/blog/2012-08-20/sending-email-adobe-cq-api/ to get and understanding of Email functionality in AEM.

data-sly-call in sightly not invoking

I was trying the sample example given at [a link]http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/use-api-in-java.html. I have created the component SightlyTest in which the data-sly-call to the template does not work. Below are my files inside component:
extra.html
<template data-sly-template.extra="${# text}"
data-sly-use.extraHelper="${'ExtraHelper' # text=text}">
<p>${extraHelper.reversedText}</p>
</template>
ExtraHelper.java
package apps.AEMProject.components.content.SightlyTest;
import com.adobe.cq.sightly.WCMUse;
public class ExtraHelper extends WCMUse {
private String reversedText;
public String getReversedText() {
return reversedText;
}
#Override
public void activate() throws Exception {
String text = get("text", String.class);
reversedText = new StringBuilder(text).reverse().toString();
System.out.print("reversedText ::: "+reversedText);
}
}
SightlyOp.java
package apps.AEMProject.components.content.SightlyTest;
import com.adobe.cq.sightly.WCMUse;
public class SightlyOp extends WCMUse {
private String lowerCaseTitle;
private String lowerCaseDescription;
#Override
public void activate() throws Exception {
lowerCaseTitle = getProperties().get("title", "").toLowerCase();
lowerCaseDescription = getProperties().get("description", "").toLowerCase();
}
public String getLowerCaseTitle() {
return lowerCaseTitle;
}
public String getLowerCaseDescription() {
return lowerCaseDescription;
}
}
SightlyTest.html
<div data-sly-use.sg="SightlyOp"
data-sly-use.extra="extra.html">
<h1>${sg.lowerCaseTitle}</h1>
<p>${sg.lowerCaseDescription}</p>
<div data-sly-call="${extra # text=properties.description}"></div>
</div>
sg.lowerCaseTitle & sg.lowerCaseDescription is working fine, but nothing display for data-sly-call
Thanks
Try this in SightlyTest.html instead,
<div data-sly-use.sg="SightlyOp" data-sly-use.extra1="extra.html">
<h1>${sg.lowerCaseTitle}</h1>
<p>${sg.lowerCaseDescription}</p>
<div data-sly-call="${extra1.extra # text=properties.description}"></div>
</div>
Modified to data-sly-use.extra1 to differentiate between the variable and the template being called.
I realize I've come to the party a little late, but I'd like to expand on Aditya's answer.
Think of the file extra.html more like a "library" of data-sly-templates rather, since it could contain as many of them as you want (each with a different name). So when you "use" the extra.html file you're sort of importing those templates into a namespace you provide on the use statement. You can then call the templates using that "namespace".
<div data-sly-use.sg="SightlyOp"
data-sly-use.extra="extra.html">
<!--/*${extra} is now a namespace for the templates in extra.html. (you can name it whatever you like for more clarity*/-->
<h1>${sg.lowerCaseTitle}</h1>
<p>${sg.lowerCaseDescription}</p>
<!--/*since your template is called extra, and it's in the namespace called extra you call it with ${extra.extra}*/-->
<div data-sly-call="${extra.extra # text=properties.description}"></div>
</div>

Wicket Test Error: component 'BookmarkablePageLink' is not type

I have created a linkpage FooPage, sothat when somebody clicks on this link, some text "test test" is desplayed to the user, so far good.
I have created the folloing basic page:
FooPage.java
public class FooPage extends WebPage {
public FooPage() {
add(new Label("label", "test test"));
} }
FooPage.html
<div wicket:id="label"></div>
In MyPnel.java I add the created page as follow:
MyPanel.java
public class MyPanel extends Panel{
add(new BookmarkablePageLink<Void>("foobar", FooPage.class));
}
MyPanel.html:
<a wicket:id="foobar" href="FooPage"></a>
Now when I test the created component with junit as follows:
#Test
public void startPage() {
wicketTester.assertComponent("foobar", FooPage.class);
}
I get the following error:
junit.framework.AssertionFailedError: component 'BookmarkablePageLink'
is not type:FooPage
Any idea what is the problem or hot to solve this?
As Ian already said, assertComponent checks that the type of the component is a subtype of a class. For your usecase you should use
wicketTester.assertBookmarkablePageLink("foobar", FooPage.class, new PageParameters());
Should you not try
wicketTester.assertComponent("foobar", BookmarkablePageLink.class);
instead (since the component of ID "foobar" is of type BookmarkablePageLink)?

Confusion in understanding/ following this website for Default Landing page

I have a confusion in understanding /implementing this page .
Hi , I am trying to follow this website for showing the Default Login page once the user logs in .
Please go through this to understand the question .
http://liferaydemystified.blogspot.in/2011/04/liferay-default-landing-page.html
I have some questions regarding this .
After entering this things inside the portal-ext.properties file
login.events.post=com.liferay.portal.events.LoginPostAction,
com..defaultlandingpage.CustomLandingPageAction
auth.forward.by.last.path=true
default.landing.page.path=
And i want to use the same CustomLandingPageAction as defined by the author in the web site .
The LoginMVCPortlet is my java file , which will recieve the parameters (Username and Password ) from the UI .
public class MyLoginPortlet extends MVCPortlet {
public void checkLogin(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String name = actionRequest.getParameter("name");
String password = actionRequest.getParameter("password");
// Contact the DB for validation .
}
My question is that , how this CustomLandingPageAction and my LoginMVCPortlet class are actually related .
Is this approach the correct one, or am I missing anything?
How to do this? I am using Liferay 6.1 for development.
Please let me know in case you need any information.
put redirection in portlet processAction methode:
#Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
//defaultLandingPage = ...
actionResponse.sendRedirect(defaultLandingPage);
};

How to redirect in Play Framework?

When I call other action in one action, it also display itself template, in Play 1.1 RC
and when I Redirect("...url") but it does not work, is there someone that can help me?
Just to add to the answers above, here's how you redirect to an external url:
public static void index() {
redirect("http://geeks.aretotally.in");
}
To redirect, you simply call the action. From the example in the documentation:
public static void show(Long id) {
Article article = Article.findById(id);
render(article);
}
public static void edit(Long id, String title) {
Article article = Article.findById(id);
article.title = title;
article.save();
show(id);
}
At the end of the edit action, the call to show(...) will cause a redirect on the client's browser as if they had hit the same URL that routes to the show method.
Since none of these answers provide a general/reusable method to do this, here is my code. This allows you to create any number of redirects in the conf/routes file without creating a controller for each.
Yes, this is trivial, but perhaps it is of use to someone.
conf/routes:
GET /admin Application.redirect(url:'/admin/index.html')
app/controllers/Application.java:
public class Application extends Controller {
public static void redirect(String url) {
redirect(url, true);
}
}
In the play framework, when you call an action, by default it renders the template associated with that action.
For example, a Contoller named Application
public static void index()
Will render
app/views/Application/index.html
To make it render a different view, then you can specify the template as the first parameter in the render method.
So,
renderTemplate("Application/myOtherTemplate.html");
Redirect should only really be used if you are redirecting to a URL outside of your application.