Programmatically add the created item name to the site page url - java

I have site pages with structure like this:
/Collections (main page that appears on main navigation menu)
/Add Collection (child page that appears as a drop down (hover) on main navigation menu)
/General Information (child page of Add Collection that appears as tabbed sub navigation menu below main navigation menu. After adding the collection, I redirect to this page.)
So the idea is to add a collection, redirect to the General Information page where I show the information about that added collection.
The first and second level pages have theme1, while the third level page "General Information" has theme2. In the site administration, this third level page has friendly url http://localhost:8080/web/guest/collections/general-information
and this is what I am trying to modify programmatically.
In the portlet class after creating a collection, I append id parameter to this friendly url
response.sendRedirect(themeDisplay.getURLPortal()+"/collections/"+"general-information?id="+id);
and in the theme2 and jsp, I get this id to display the General Information of appropriate collection.
What I want to do is perhaps modify the friendly url programmatically and accomodate the collection name in this url. Something like:
http://localhost:8080/web/guest/collections/{collectionname}/general-information
How can I do this?

Related

Programmatically set active-menuitem of PrimeFaces responsive themes

We're using one of the new responsive themes of PrimeFaces 8 (Mirage if that matters) I've implemented a dynamic menu to create the menu of my page. Depending on several parameters, the landing page can be different. Example:
Suppose there's a communications environment in which the menu items are
Documents (opens by default)
E-mail
Pictures
When arriving in the communications environment, the application checks whether there are new e-mails. If so, the user won't arrive on the "Documents" page but on the "E-mails" page.
The theme uses cookies to restore the menu state based on what the user has chosen previously. So suppose last time (s)he has chosen "Pictures", the result now is that the menu item "Pictures" is marked as active-menuitem but the displayed page is "E-mail".
I was already able to clear the cookies so that no menu item is active, but now I'm trying to activate the correct menu item. I got most successful by calling
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('li'));
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('ul').closest('li'));
but since the page is rebuild using ajax, this only works once 🤨. Using the build-in .active-menuitem doesn't work so that's why I introduced .custom-active-menuitem that I set in Java code:
DefaultMenuItem.builder()
.value("E-mail")
.icon("fa fa-letter")
.command("#{communicationBean.openEmailPage()}")
.styleClass("custom-active-menuitem") // or something else to mark this item active
.process("#this")
.update(":page");
So now I'm puzzled. Can someone please get me in the correct direction? How can I make the theme show the menu item I choose as active one?

How to navigate/browse on next/previous page in aem?

I'm developing pages in AEM 6.3. Right now I have a situation to develop a page containing 2 links that browse to next and previous page with respective to current page. Let's say I have 3 pages under my project site /content/project/en.
Page A
Page B
Page C
Let's assume, if I'm on Page B, then my next page should be Page C and previous page should be Page A. Those two links(next/previous) should redirect me to Page A and Page B.
There might be many approaches to do that but what I have in mind is that, I'll be making an ajax get request which will return me next and previous pages in key/value format. To do this I'll be using sling servlet object to get the page path and query builder to make query on that path to get the next and previous page. This approach works fine if there is very limited number of pages but would be time consuming if pages increases.
I want simple solution to implement this. Or is there any plugin in aem to do this? I also tried to do that with currentPage.nextSibling() in sightly but there is no such thing exist in aem.
One possible solution is to create an end point that -
can be called upon a page
returns page paths (use page.listChildren())as JSON array
Two ways to do that -
In your app’s base page, add a jsp listChildren.jsp that renders json
Create a resourceType based servlet with selector listChildren and extension json. ResourceType being page’s resourceType myapp/page/testpage
Call this endpoint on parent page of the page being rendered, thus you get list of all siblings page path and current page’s path. You can get this endpoint to be catchable so as to avoid multiple publish hit.
Once you get JSON, use it in JS to get the index of current page path (use find(‘path/to/current/page)). once you have index, you could use index-1 & index+1 to get previous and next page path.
Note - in case you are using short path for website url make sure JSON also return short path
As addition with new requirement which was page on next/previous link should be sorted in created date with respective of current page. So I came up with following solution.
I have created a component name 'Next Previous Pagination' and used a WCMUsePojo model in htl language. This model is responsible to get next and previous page of the current page. Following are the jcr queries to get next and previous page.
For next Page,
select page.* from [cq:Page] AS page WHERE
ISDESCENDANTNODE(page,'/content/project/myCurrentPage')
AND page.[jcr:content/jcr:created] >= CAST('${createdDateOfCurrentPage}' AS
DATE) AND NAME(page) <>'${currentPageName}' ORDER BY page.
[jcr:content/jcr:created] asc Limit 1
For previous page,
select page.* from [cq:Page] AS page WHERE
ISDESCENDANTNODE(page,'/content/project/myCurrentPage')
AND page.[jcr:content/jcr:created] <= CAST('${createdDateOfCurrentPage}' AS
DATE) AND NAME(page) <>'${currentPageName}' ORDER BY page.
[jcr:content/jcr:created] desc Limit 1

True difference between pageContext.getSession().setAttribute() and pageContext.setAttribute()

I have been going crazy about resetting some validation error on one of my jsp pages. This is a project inherited from people I cannot reach anymore (dead or unavailable). I have a jsp page with lots of custom taglibs where further pages are added as tabs and the parent page has action buttons to open things like forms. There is a validation error and some configuration parameter being set/modified both in the tabs section and the parent page. But the interesting thing is that I can see the heavy use of pageContext.setAttribute(), session.setAttribute() and pageContext.getSession().setAttribute(). If my initial knowledge is right, pageContext is quite heavily used in servlet-based implementations. but how different things would be if I use those following three on my JSp pages to set attributes?
** Example Scenario (my problem): **
I have some attributes set in the parent page, which are also being set/modifed in the tabs page (embedded in the parent page). I want to remove them such that if there is a validation error, I will simply remove what I have in the tabs page i.e. next time the page will simply load those attributes from the parent page. Do I use pageContext.setAttribute() in the tabs page, but use pageContext.getSession().setAttribute() in the parent page?
KR,
Page scope
When we put in our JSP page, scope is available only for the JSP page that put it.
This is the default scope, so is the same to call pageContext.setAttribute("", "", PageContext.PAGE_SCOPE); same as pageContext.setAttribute("", "");
Session scope
session.setAttribute() and pageContext.getSession().setAttribute() both are same.
What you put on your session scope is available across all requests on the same user session.
Is the same to call pageContext.setAttribute("", "", PageContext.SESSION_SCOPE); same as session.setAttribute("", "");

How to create Multi step form

We want to give option to author to create multi steps tabs or wizard. This number of steps/tabs should be configurable in Form Start component in Edit button. Once author selects the number of steps/tabs then steps/tabs will be created automatically and then author can drag and drop other components like "File Upload", etc.. Please refer to the attached screenshot.
Kindly let me know how to proceed on this.
You can try to leverage the OOTB tabctrl component provided in geometrixx-outdoors along with the OOTB form component. The only customization needed would be changing the form end component to accomodate prev and next buttons, and then adding a bit of javascript to navigate the tabs on click of those buttons.
Steps to create this.
Drag and drop the default form component on page.
Inside the form drag and drop the tab control component.
Configure the number of tabs required and the contents within each tab in the tab control component.
Modify the form end component to accomodate the previous and next buttons.
Attach handlers for the previous and next buttons using the following JS(currently consists only of the basic functionality. Can be modified according to your requirements).
JS:
jQuery(function ($) {
$(document).on('click', '.prev', function(){ // 'prev' is class of previous button
var tabctrl = $(this).closest('form').find('.tabctrl');
var currentItemHeader = $(tabctrl).find(".tabctrl-header li.active");
$(currentItemHeader).prev().find('a').click();
});
$(document).on('click', '.next', function(){ // 'next' is class of next button
var tabctrl = $(this).closest('form').find('.tabctrl');
var currentItemHeader = $(tabctrl).find(".tabctrl-header li.active");
$(currentItemHeader).next().find('a').click();
});
});
NOTE: Try to include the appropriate clientlibs in geometrixx site before testing this, else tabctrl wouldn't work properly. Or else, you can check this dierctly in geometrixx-outdoors site.

after back button, portlet does not go in to processaction

I have a portlet which involves displaying several JSP pages.
In first JSP page A, when I click the Submit button on Page A the processAction() method takes action and a JSP page B appears.
Now if I use Web Browser's Back button to page A and click the Submit button again, the
JSP page B appears but I noticed the processAction() didn't take any action. (Usually clicking Submit button in a JSP page can result in the processAction() to take action).
Can anyone help for this problem? In my Porlet, it MUST go to the process action but it doesn't after back button.
This is the default behavior. Portal has "Multiple Action URL Protection " enabled by default. When a page loads, an action link is created and that link contains an action ID. The same action ID cannot be used again in the same session. So when you click on Back Button, if the page is loaded from the history cache, your Form contains the same action link which was used before. So portal simple reloads the page, rather than calling the processAction().
You can disable this by adding the following configuration for your portlet in portlet.xml file.
<init-param>
<name>wps.multiple.action.execution</name>
<value>true</value>
</init-param>
Without seeing any code, it sounds as if your form response may be cached. What is the method attribute on your <form> ? Forms submitted via GET (or no method attribute at all) are allowed to be cached; in which case neither the server nor your portlet's processAction(...) will be invoked - the browser will re-render the previous response from cache.
If you post some code there may be more offers to help...

Categories