Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
JS Bournival
Default child page when clicking Parent Page
January 31, 2012 12:06 PM
Answer

JS Bournival

Rank: New Member

Posts: 11

Join Date: December 14, 2011

Recent Posts

Hi,

I know that, when you have for instance a parent page with a bunch of child pages, you can specify which one is the landing page when someone clicks on the parent page tab. IIRC it's done with the "Link to Page" dropdown of the parent page configuration.

Now, if I want to specify instead that I want «the first child page» as the landing page. Can I do that?

Or better, if the page I specified in the «Link To Page» isn't available (ex. user doesn't have permission), pick the first available.

Thank you.

JS.
Carlos Busto Capeans
RE: Default child page when clicking Parent Page
April 10, 2012 4:02 AM
Answer

Carlos Busto Capeans

Rank: New Member

Posts: 24

Join Date: September 7, 2011

Recent Posts

Hi,

I had to do something similar, but my case was more specific. Surely you can adapt the code to your needs.

I created a hook of "Portal properties" for event "servlet.service.events.pre" with this custom class:

 1
 2public class CustomPreServiceAction extends Action {
 3    public CustomPreServiceAction() {
 4        super();
 5    }
 6    public void run(HttpServletRequest request, HttpServletResponse response)
 7            throws ActionException {
 8        boolean tieneRol = false;
 9
10        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
11
12        if (themeDisplay.getURLCurrent().equalsIgnoreCase(PropsUtil.get("XXXXXXXXX"))) {
13            User user = themeDisplay.getUser();
14            try {
15                List<Role> roles = user.getRoles();
16                for (Role role : roles) {
17                    if (role.getName().equalsIgnoreCase(PropsUtil.get("YYYYYYYYYYY"))) {
18                        tieneRol = true;
19                    }
20                }
21            } catch (SystemException e) {
22                // TODO Auto-generated catch block
23                e.printStackTrace();
24            }
25
26            if (!tieneRol) {
27                try {
28                    response.sendRedirect(PropsUtil.get("ZZZZZZZZZ"));
29                } catch (IOException e) {
30                    // TODO Auto-generated catch block
31                    e.printStackTrace();
32                }
33            }
34        }
35
36    }
37
38}


I hope you will help.
Regards.