Pass data between multiple pages | Community
Skip to main content
December 16, 2022
Solved

Pass data between multiple pages

  • December 16, 2022
  • 3 replies
  • 2717 views

We have requeement to implement several pages in forms like manner (using forms is out of the scope).

On one page user (anonymous) could fill in some data and by clicking next he could be redirected to another page to enter more data or read some info and continue to next page in the line...

User can go back and forth. On the last page, data that user entered on the previous pages will be used for calculation, maybe generate some graph... 

We could use http session (obviously no caching on dispatcher), maybe cookie if we don't break size limit...

We plan to minimize use of jscript, so using browser local storage is no option.

 

I would like to hear other approaches that could allow us to pass data  between pages.

 

Thank you

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Avinash_Gupta_

Hi Avinash,

>Why you don't want to leverage the session or local storage approach?

 

If you are talking about http session, that will be probably our approach, I was just wondering on the downsides and some alternatives. We have never used http session on aem projects so we dont know if there are any gotchas ?

Local storage is not an option because we are very limited on using jscript becaus of the project requrements. So most of the logic needs to be coded on the server side.


Hi @nbg62 

 

Servlet API provides Session management through HttpSession interface. We can get session from HttpServletRequest object using following methods. HttpSession allows us to set objects as attributes that can be retrieved in future requests.

 

https://www.digitalocean.com/community/tutorials/java-session-management-servlet-httpsession-url-rewriting 

3 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
December 16, 2022

Instead of multiple pages, Cant you do it in single page with multiple Divs which shows the input for the user's data. You can show/hide the divs based on user's click on prev and next using javascript. Finally you can calculate when the last div data is submitted. This requires javascript work.

nbg62Author
December 17, 2022

Thanks Saravanan,

 

That is known old approach to wizard like pages but I think setting up and maintaining such a page would be a major pain to the authors but it is solution worth considering.

Avinash_Gupta_
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
December 16, 2022

Hi @nbg62 

 

There are two ways to implement the solution and it depends on your use case:-

 

1. Pages URLs are entirely different and requires refresh: Better would be to use session or local storage to capture the field details as cookie size limit is very less 4096 bytes instead session/local storage provides you 5MB of data.

 

2. Single Page : If your entire uses case fits into a single page application and doesn't require refresh, then go with the solution proposed by @saravanan_dharmaraj .Simply hide and show the div sections as user click on prev and next. Finally at the end submit the application to do the calculation and generate the graph.

 

Hope this helps.

nbg62Author
December 17, 2022

Hi Avinash,

 

If we opt for http session approach, does http session in aem behaves same as servlet http session ?

 

Going with spa editor approach, that is a big change for us, as we don't have React experience in the team neather we have built aem app based on spa before, it is just a bad timing to go for it.

 

Thanks

Avinash_Gupta_
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
December 19, 2022

Hi @3783033 

 

I think you can try with using Http session context. Past days, when we were using JSP's we usually set the session context objects in one jsp and read the value in another. Not tried the session approach with slightly though. 

 

First.jsp

String name="Hello";
Session.setAttribute("Name",name);

 

Second.jsp
Session.getAttribute("Name");

 

Why you don't want to leverage the session or local storage approach? It's a very simple and convenient implementation to pass the data from one page to another.

 

Also, I wasn't talking about implementing it in React or Angular.js. You can use the forms wizard approach to show and hide the sections. There is only logic needed on JS side.

joerghoh
Adobe Employee
Adobe Employee
December 26, 2022

You can use the HTTP Session object on the server, but this definitely impacts the scalability of the system; because every page needs to be rendered on the server. And don't forget to use a sticky session approach on the publish side.

 

I would recommend to switch to an SPA approach, and let the user fill all the data in a single "page". And just the final step (form data submission) requires the server end point.

nbg62Author
December 27, 2022

Thanks Jorg,

 

correct, caching will be impacted.

 

We considered SPA approach but current team doesn't have React/Angular experience and we haven't done any SPA kind of AEM projects, apart from that we require server side rendering which adds additional complexity with Adobe IO involvement.