Unable to use Liferay Freindly URL Mapper - liferay-6

I was following this document from Liferay Website to work Map Firendly URL Mappings
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/adding-friendly-url-mapping-to-the-portlet
I am using Liferay version=6.1.0
During HyperLink navigation , i was getting the following url
http://localhost:8080/web/guest/what-we-do?p_p_id=sai_WAR_Saiportlet&
p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1
&_sai_WAR_Saiportlet_jspPage=%2Fhtml%2Fsai%2Fedit.jsp
To modify the above i have tried to use Friendly URL Mapper and i have done the following way
Inside liferay-portlet.xml file .
<portlet>
<portlet-name>sai</portlet-name>
<icon>/icon.png</icon>
<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
<friendly-url-mapping>sai</friendly-url-mapping>
<friendly-url-routes>com/test/sai-friendly-url-routes.xml</friendly-url-routes>
<instanceable>false</instanceable>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>
/js/main.js
</footer-portlet-javascript>
<css-class-wrapper>sai-portlet</css-class-wrapper>
</portlet>
Created a new file by name sai-friendly-url-routes.xml inside
D:\liferay-plugins-sdk-6.1.0-SNAPSHOT\portlets\Sai-portlet\docroot\WEB-INF\src\com\test\sai-friendly-url-routes.xml
The content inside sai-friendly-url-routes.xml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.1.0//EN" "http://www.liferay.com/dtd/liferay-friendly-url-routes_6_1_0.dtd">
<routes>
<route>
<pattern>/{mvcPathName}</pattern>
<generated-parameter name="mvcPath">/{mvcPathName}.jsp</generated-parameter>
</route>
</routes>
But i observed there is no change in the url
http://localhost:8080/web/guest/what-we-do?p_p_id=sai_WAR_Saiportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_sai_WAR_Saiportlet_jspPage=%2Fhtml%2Fsai%2Fedit.jsp
Please let me know where exactly i am doing mistake .

You leave the values as they are. That is, you leave {mvcPathName} and "mvcPath" as-is.
When the friendly URL is generated, it parses mvcPath (i.e., edit.jsp or view.jsp) from the URL and then the pattern is applied, replacing .../edit.jsp with .../edit.
This example works for the edit JSP. And it works for the view page; but NOT when clicking Save ... which is something I could look into. However, if you go to edit and then click the back link, the friendly URL will show for the view JSP.
I've created a ticket to complete this example so that it also goes to a friendly URL when clicking save. I'll update this section when we've made the fix.
Thanks.

Related

AEM:: Error Handling using the acs-aem-commons package

As defined here http://adobe-consulting-services.github.io/acs-aem-commons/features/errorpagehandler.html I am trying to confgure error pages for my application. Here is what I have done:
1) Created 404.jsp and default.jsp at /apps/sling/servlet/errorhandler as defined on the page.
2) Added below widget to the advanced tab:
<errorpages
jcr:primaryType="cq:Widget"
path="/apps/acs-commons/components/utilities/errorpagehandler/dialog/errorpages.infinity.json"
xtype="cqinclude"/>
3) Created /apps//config/com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.xml
with the following properties:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
prop.enabled="{Boolean}true"
prop.error-page.fallback-name="500"
prop.error-page.system-path="/content/error"
prop.error-page.extension="html"
ttl="{Long}300"/>
4) Created /content/myapp/en/errors using a fresh template. The template has only a parsys. Inside the /content/myapp/en/errors, I have created page 404 and 500 using the same template. In the video it is shown that when the speaker opens the pages 404.html and 500.html created under geometrixx from siteadmin he is able to see appropriate error messages. What I am not able to understand is that if my template consists of only a parsys how will the 404 and 500 pages show the error messge. From where are those messages being generated ? Am I missing something here ? Do I have to create any component ?
5) In the Page Properties of the page /content/myapp/en , I have configured /content/myapp/en/errors as the Error Page. To generate a 404 error when I try to access the URL /content/myapp/ent.html instead of /content/myapp/en.html it throws a
No resource found
Cannot serve request to /content/myapp/ent.html in /apps/sling/servlet/errorhandler/404.jsp
Not sure how do I get he nice looking pages as shown in the video.
5) How can I make the error messages authorable ?
Thanks in advance
No need to follow so many steps. The ACS commons package with the error handler is available as a package. Down load this package from This ACS commons git hub site
The name of the file is --> acs-aem-commons-content-1.9.6.zip(2.3 MB).
Then just create sling:OsgiConfig node in your /apps/myapp/config with
name --> com.adobe.acs.commons.wcm.impl.ComponentErrorHandlerImpl. Then put the below configuration into the node.
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="sling:OsgiConfig"
prop.edit.enabled="{Boolean}true"
prop.edit.html="/apps/acs-commons/components/utilities/component-error-handler/edit.html"
prop.preview.enabled="{Boolean}false"
prop.preview.html="/apps/acs-commons/components/utilities/component-error-handler/preview.html"
prop.publish.enabled="{Boolean}false"
prop.publish.html="/dev/null"
/>
Below is the configure component in crxde lite
Thats all. You need not do anything else.You will get proper error pages or messages for all 500 or 404 errors
As you said in 5th step In the Page Properties of the page /content/myapp/en , you have configured /content/myapp/en/errors as the Error Page. This error pages are work for for child pages under this path /content/myapp/en . In your case it will be work for all the childs under /content/myapp/en/*.html
Ex. It will work for /content/myapp/en/{invalidurl}.html
The question was about the page error handler, the answer is provided about in: component error handler. These two different things altogether.
the CEH handles the exception in component scope where as EPH handles it in request scope
when component fails and the exception is not handled by CEH and response is written as 500, it will be handled by EPH
For point 4) The template has only a parsys.
Yes you have to configure the components and place them in the parsys as you would do for your content pages that will display in case of error pages. The error handler gives you the flexibility to modify what shows up in error pages by keeping them authorable. You can change the look and feel of error pages for each of the valid HTTP errors.
For example, whatever I create in my content/error/404.html page will show up when the actual 404 is returned by the errorhandler.
In case of an invalid URL:
For point 5) In the Page Properties of the page /content/myapp/en , I have configured /content/myapp/en/errors as the Error Page. To generate a 404 error when I try to access the URL /content/myapp/ent.html instead of /content/myapp/en.html it throws an error.
The mistake that you did here was that you are trying to access a parent page url.
One solution would be to place the custom error pages at a level higher than the content pages for your website.
You can do this more than once. As in keep separate error page for global errors, some other for myapp, some others for myapp/en and so on.
So if you have seen there is a tab in page properties where you can author the error pages root url. This can be leveraged to give different URLs as per requirement.
For example,
If you want an error page for /content/myapp/ent.html then place a separate set of error handler pages at content/myapp in addition to those at content/myapp/en.
Then goto myapp.html and in Page Properties override the error page url to content/myapp/error.
For each parent whenever you need a separate error page url author those in page properties.
So now I have two renditions of my error page: One for content/myapp and other for content/myapp/en
As shown below:
path - /content/test.html (Global)
path - /content/myapp/ent.html (Myapp):
Config node:
Sample template to show the difference:

Redirect attribute of actionforward does not work in struts portlet bridge based portlet (JSR-168)

I did a lot of researching on the matter but cannot seem to find the answer to my question, so I hope you guys can help me out.
We have a struts 1.2.7 web app that we converted to a JSR-168 portlet using the Apache Struts Portlet Bridge.
This is all working very well except for one thing: the actionforwards that specify a redirect do not actually redirect to the specified action. These redirects DO work when running the app as a normal struts web app. Hence, we have a double submit problem in the portlet variant.
We make use of action chaining that ends with an action forwarding to a tile definition. For example:
<action path="/CreateIdmAccountSubmit" validate="true" input="catalog.createaccount.page" type="com.konakart.actions.login.CreateIdmAccountSubmitAction" name="CreateIdmAccountForm">
<forward name="FillRegistrationData" path="/FillRegistrationData.do" redirect="true"/>
</action>
<action path="/FillRegistrationData" validate="false" type="com.konakart.actions.registration.FillRegistrationDataAction" name="FillRegistrationDataForm">
<forward name="FillRegistrationDataPage" path="/FillRegistrationDataPage.do" redirect="false"/>
</action>
<action path="/FillRegistrationDataPage" forward="order.registrationdata.page"/> (tiles-def)
In this example the action /CreateIdmAccountSubmit processes a submitted form (POST) and creates an account in the db. After successfull creation the user is redirected to another action (/FillRegistrationData) which inits an order object and, on its turn, forwards to the orderregistration page which layout is defined in the tiles-defs.xml.
As I said this all works very well, form a functional perspective, but when a user hits f5 on the rendered order-registration-page the action /CreateIdmAccountSubmit is again invoked causing the account to be created double. As I said also this is not happening when running the app as a normal web app. Here, the mechanism works perfectly :)
I think that the problem is being caused by the fact that the redirect is done in the wrong phase but i am really not sure as why this does not work :)
Based on what I read I tried the fowllowing things to fix the redirect problem:
* specified the action that does the form submit as "actionUrl" in struts-portlet-config.xml (hoping that redirect is done in wrong phase?)
* replaced the normal html tag library by the struts-portlet variant (hoping that a valid url actionUrl was produced by my html:form that in some way made the redirect possible?)
These two steps did not seem to help and I am lost at how to accomplish a simple redirect in the portlet so that we can prevent the double submit problem.
Hope you guys can help me out!
I found the answer: the mechanism is dependent on the portal implementation. We use Liferay which does not work with redirects by default.
However, you can switch this on by declaring an element in liferay-portlet.xml called
<action-url-redirect>true</action-url-redirect>
This fixed the problem for us!

Redirect to same named page in directory structure before path changes

Well, say I have a number of html pages in my web. The case is that I´m doing changes sometimes in the directory structure, so when anybody try to access to a determinated URL, it's possible that such URL does not exit. The files names don't change but so do the paths.
As far as I now, the server takes the user to a "404" page that can be customized. Is possible to customize the page in this way?:
The user tries oneweb.com/oldpath/page.html; which does not exist.
A 404 customized page is launched
404 page runs an script IS THIS POSSIBLE?
The script is given the name of the file WHERE IS STORED SUCH NAME?
The script search the entire directory structure to find page.html HOW TO ACCESS TO THE STRUCTURE
The file is found and the new URL is stored: oneweb.com/newpath/page.html
a link appears showing the new URL
Maybe this process is relatively common and I can find some related code or tutorial?
Are you using Apache? Linux?
Add a 404 handler
ErrorDocument 404 /404.php
Then use 404.php to parse the url. This simple example just grabs everything after the last / in the URI so http://example.com/foo/bar/page.html would put page.html in $url:
$url = end(explode('/', $_SERVER['REQUEST_URI']));
Then use one of the comment example functions in http://php.net/manual/en/function.readdir.php to search your directory and find the file.
Then do a header 301 redirect
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://example.com/' . $file_path);

How Do You Get The Store Secure URL in Magento?

I have a form in Magento that is displayed over the insecure URL (http) but I need it to submit to the secure URL (https).
I display the URL I currently use the following code:
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
I am assuming I need to change the URL_TYPE_WEB to something else. Does anyone know what that something else is?
Have you tried this?
Mage::getUrl('',array('_secure'=>true))
I think that gets you the base secure url, I believe.
Mage::getUrl('customer/account/login',array('_secure'=>true))
Will get you to the login page. In other words,
Mage::getUrl('module/controller/action',array('_secure'=>true))
Will get you to any page you want, just substitute 'module/controller/action' for the appropriate combo.
Edit -- Fixed Typos
http://blog.geekslikeshinythings.com/2014/12/magento-force-secure-urls-https-on-all.html
this works in Mageno 1.9.1
use your app/etc/config.xml file
<?xml version="1.0"?>
<config>
<frontend>
<secure_url>
<all>/</all>
</secure_url>
</frontend>
</config>
If user is using https, this should force all urls to rewrite (created as) to https.
Use:
Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL);
to read the the configuration value inside magento that has been set inside admin.
this worked to me
echo Mage::getUrl('customer/account/loginPost',array('_secure'=>true));
For example:
if you browsing with http then
echo Mage::getUrl('customer/account/loginPost',array('_secure'=>true));
// http://dominio.com/customer/account/loginPost
if you browsing with https then
echo Mage::getUrl('customer/account/loginPost',array('_secure'=>true));
// https://dominio.com/customer/account/loginPost
You can do this in code and also from xml.
For example, if you want to set https for the check out page then you have to add the below code in your custom config.xml:
<code>
<secure_url>
<checkout_onepage>/checkout/onepage</checkout_onepage>
<checkout_multishipping>/checkout/multishipping</checkout_multishipping>
</secure_url>
</code>
Magento has a default feature for https for check out so you can do the same thing for other pages like for the customer page:
<code>
<secure_url>
<customer>/customer/</customer>
</secure_url>
</code>
I hope it'll help you.
Tried this its working for me.
Mage::getUrl('',array('_secure'=>true))
After added this code finally its look like below
IWD.ProductVideoView.urlGetVideo = "<?php echo Mage::getUrl('iwd_productvideo/player/getvideo/',array('_secure'=>true)); ?>?isAjax=true";

Get displaytag to use an action URL for page switching

I'm trying to use external paging in a JSR-286 portlet with DisplayTag 1.2.
I would like DisplayTag to generate the paging links from a parameterized Action URL that i have defined, but i can't seem to make that work.
Here is the code in my JSP:
<portlet:actionURL var=actionUrl >
<portlet:param name="someParam" value="someValue" >
</portlet:actionURL >
<display-el:table id="personsTable"
name="${portletSessionScope.persons}"
requestURI="${actionUrl}"
partialList="true"
size="${portletSessionScope.total}"
pagesize="${portletSessionScope.pageSize}" >
<display-el:column property="firstName"/ >
</display-el:table >
With the above code, it looks like Display-tag ignores the provided ${actionUrl} and generates a default Render URL. The generated links work fine (i can move through pages), but since my portlet requires an Action request to fetch other pages of data, the list in the session is never updated and the table always contains the same data, regardless of which page i select.
Is there a way i might make that work? Does DisplayTag support what i'm trying to do?
Thanks in advance for your help!
Create a form in your JSP and pass the form name to the displaytag:table as form attribute value. This will invoke the action URL that you have specified.