How to modify the Page property in the Page component jsp and set the new modified value back to the Page property by setProperty(..,...) method? Can we set the Page property back?
My Situation is I want to set the Unique Page ID for every page I create, So I would like this to be a Page Property.
I am considering the the current datetime is unique feature, So I want to convert this current datetime to unix time value a long value and want to set this PageID property to that page.
I can access the Page properties in the Page component jsp file, But when I try to set the Page property it wont throw error nor it sets my new modified value.
My Code in Component JSP is as below:
SlingRepository repository = resourceResolver.adaptTo(SlingRepository.class);
Session session = repository.loginAdministrative(null);
Node node= session.getNode("Absolute path of the Page");
node.setProperty("jcr:Pageid",Unix Datetime );
session.save();
Any help to create a Unique Page ID will be really appreciated
Thanks a ton in Advance
Solved! Go to Solution.
Views
Replies
Total Likes
What s your exact use case? Page property stored at "Absolute path of the Page"+/jcr:content so modfying it should fix the issue. You can use [1] & very bad idea to use admin session. Also logic should be part of template not at component level.
[1]
Long.toString(Calendar.getInstance().getTimeInMillis())
Views
Replies
Total Likes
You cannot call repository.loginAdministrator from a component to modify the JCR. Only fron an external Java app. You need to call adaptto method. See http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html.
Views
Replies
Total Likes
What s your exact use case? Page property stored at "Absolute path of the Page"+/jcr:content so modfying it should fix the issue. You can use [1] & very bad idea to use admin session. Also logic should be part of template not at component level.
[1]
Long.toString(Calendar.getInstance().getTimeInMillis())
Views
Replies
Total Likes
Thanks for your quick response.
My exact scenario is I need to create a unique page id for all my pages created using my page template.
this page id property should get generated automatically on page creation.
I want to access this pageid based on the google analytics result and store those Page id's against the loggedin user id.
When the user login again after 24 hours, I will query the JCR with all the PageId's stored for this user and list out all those pages for the user.
For this process first step i need to have a Unique PageID generated for each page on page creation.
Any help in this regard is really appreciated.
Thanks
Views
Replies
Total Likes
Hey Sham,
Thanks a lot . I get the issue fixed.
I used Page Path as the unique ID for every page .
Views
Replies
Total Likes
Views
Likes
Replies