Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Hierarchical long friendly url
Hello!
We need to use friendly urls like \xxx\yyy\zzz
Urls are localized (stores in DB with %-symbols) and may be long enough.
To make friendlyurl hierarchical I use ModelListener-hook with onAfterUpdate() action, and it normally works.
But default friendlyurl length is only 255 characters.
With changed length at db-column all works, but fails at
FriendlyURLEntryLocalServiceImpl.updateFriendlyURLEntry()
at validate() method
Guess1
How to correct modify length of friendlyurl column (at 'layout' and 'layoutfriendlyurl' tables)?
May be with EXT or model-hints?
Guess2
Not to modify DB, but create a new table with my own long friendly urls?
I will try to create this with service-builder.
1. Save urls
works fine
2. To find layout with url I override
LayoutLocalServiceWrapper.getFriendlyURLLayout()
used in
PortalImpl.getPortletFriendlyURLMapperLayoutQueryStringComposite()
Page successfully found, but url in address panel change to 'system' at
FriendlyUrlServlet with PortalImpl.getLocalizedFriendlyURL()
And I dont want to override whole PortalImpl.
May be it is real to override FriendlyUrlServlet?
Or something else to get control about Liferay friendlyurl?
Dear Sergey Shishov,
Thank you for participating in the Liferay
Community. Your post is currently awaiting moderation
and will not be visible to other posters.
Also please note you are limited to 3 posts
per hour and 50 posts per day. Exceeding the post
limit will temporarily disable posting.
One of our moderators will review your post shortly.
Sincerely,
Webmaster
webmaster@community.liferay.com
http://liferay.dev
Finally there are:
1) service-builder component to store long friendly urls (FriendlyUrlLong)
2) ModelListener-hook to create long friendly urls (buiseness logic)
3) Override some LayoutLocalService methods:
- updateLayout (replace urls with cropped one)
- deleteLayout (syncronious remove our urls)
- getFriendlyURLLayout
@Override
public Layout getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL) throws PortalException {
Layout layout = null;
// Try find by our long friendly url.
String normalizedUrl = FriendlyURLNormalizerUtil.normalizeWithEncoding(friendlyURL);
FriendlyUrlLong friendlyUrlLong = FriendlyUrlLongLocalServiceUtil.fetchByFriendlyUrl(normalizedUrl);
if (friendlyUrlLong != null) {
long plid = friendlyUrlLong.getPlid();
layout = LayoutLocalServiceUtil.fetchLayout(plid);
}
// Try find by liferay.
if (layout == null) {
layout = LayoutLocalServiceUtil.getLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);
}
return layout;
}
4) Override some LayoutFriendlyURLLocalService methods:
- updateLayoutFriendlyURLs (replace urls with cropped one)
- getLayoutFriendlyURL
@Override
public LayoutFriendlyURL getLayoutFriendlyURL(long plid, String languageId) throws PortalException {
LayoutFriendlyURL layoutFriendlyURL = getLayoutFriendlyURLInternal(plid);
if (layoutFriendlyURL != null) {
return layoutFriendlyURL;
}
return super.getLayoutFriendlyURL(plid, languageId);
}
@Override
public LayoutFriendlyURL getLayoutFriendlyURL(long plid, String languageId, boolean useDefault) throws PortalException {
LayoutFriendlyURL layoutFriendlyURL = getLayoutFriendlyURLInternal(plid);
if (layoutFriendlyURL != null) {
return layoutFriendlyURL;
}
return super.getLayoutFriendlyURL(plid, languageId, useDefault);
}
private LayoutFriendlyURL getLayoutFriendlyURLInternal(long plid) {
// Try to find our long friendly url.
FriendlyUrlLong friendlyUrlLong = FriendlyUrlLongLocalServiceUtil.fetchFriendlyUrlLong(plid);
if (friendlyUrlLong != null) {
String longFriendlyUrl = friendlyUrlLong.getFriendlyUrl();
// Compose fake LayoutFriendlyURL.
LayoutFriendlyURL fakeLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.createLayoutFriendlyURL(0);
fakeLayoutFriendlyURL.setFriendlyURL(longFriendlyUrl);
return fakeLayoutFriendlyURL;
}
return null;
}