Foros de discusión
Update friendly URL moving a page
Paolo Giannone, modificado hace 7 años.
Update friendly URL moving a page
New Member Mensajes: 21 Fecha de incorporación: 15/02/17 Mensajes recientes
Good evening.
my target is to update the friendly url of a page when I move it. For instance I move the page 'my hook' to Assets. When I save I want to change the friendly url of my page from /myhook to assets/myhook.
Here is a picture:
To reach my target I try using hooks:
The problem with this hook is that it produces a loop because for each update it calls the onAfterUpdate method.
How can I solve?
Thank you.
my target is to update the friendly url of a page when I move it. For instance I move the page 'my hook' to Assets. When I save I want to change the friendly url of my page from /myhook to assets/myhook.
Here is a picture:
To reach my target I try using hooks:
public class LayoutFriendlyUrlListener extends BaseModelListener<layoutfriendlyurl> {
@Override
public void onAfterUpdate(LayoutFriendlyURL newLayoutFriendlyUrl)
throws ModelListenerException {
try{
log.debug("LISTENER onAfterUpdate Layout -> update friendyurl");
Layout newLayout = LayoutLocalServiceUtil.fetchLayout(newLayoutFriendlyUrl.getPlid());
String oldFriendlyUrl = newLayout.getFriendlyURL();
String newFriendlyUrl = oldFriendlyUrl.substring(oldFriendlyUrl.lastIndexOf("/"));
if(newLayout.getParentPlid() > 0){
Layout parentLayout = LayoutLocalServiceUtil.fetchLayout(newLayout.getParentPlid());
newFriendlyUrl = parentLayout.getFriendlyURL() + newLayout.getFriendlyURL();
}
newLayout.setFriendlyURL(newFriendlyUrl);
LayoutLocalServiceUtil.updateLayout(newLayout);
newLayoutFriendlyUrl.setFriendlyURL(newFriendlyUrl);
LayoutFriendlyURLLocalServiceUtil.updateLayoutFriendlyURL(newLayoutFriendlyUrl);
}catch(Exception ex) {
log.error("Error........... ", ex);
}
}
</layoutfriendlyurl>
The problem with this hook is that it produces a loop because for each update it calls the onAfterUpdate method.
How can I solve?
Thank you.
Sandeep Nair, modificado hace 7 años.
RE: Update friendly URL moving a page
Liferay Legend Mensajes: 1744 Fecha de incorporación: 6/11/08 Mensajes recientes
Hi,
Try overriding the service updateLayoutFriendlyURL using Service Wrapper instead of ModelListener.
Regards,
Sandeep
Try overriding the service updateLayoutFriendlyURL using Service Wrapper instead of ModelListener.
Regards,
Sandeep