활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
Hey there ,
I'm new to CQ and playing around with forms . I have a html form (not cq form) where i am posting to a custom servlet which creates properties on a specific node in jcr and also saves the values to a .txt file based on some custom logic .
After successful post , i want to return to the same form page with saved values reloaded on the form ? Normally my requirement is , only to write to a .txt file on post , but since i have to show the saved values to user reloaded in a form I'm also saving to node so that they can be easily retrieved when compared to parsing the text file .
What would the best way to achieve it ?
Thanks in advance for your pointers and tips .
해결되었습니다! 솔루션으로 이동.
조회 수
답글
좋아요 수
Hi, well in that case. If you have your values stored under a node you can retrieve them with something
like thisin the jsp page:
//.. in jsp page //..code String MY_PATH = "/path/to/the/specific/node"; Resource myNodeResource = resourceResolver.getResource(MY_PATH); ValueMap myValuemap = myNodeResource.adaptTo(ValueMap.class); //...more code fetch the values of interes and check that they exist
.. then get the values from the value map and then just init the form with these values.
Of course you need some better code than the above, with error handlig etc. but you get the basic idea.
Good luck
/Johan
조회 수
답글
좋아요 수
On easy way to accomplish this would be to make the servlet redirect back to the same form with the submitted values as variables (in the way you choose). An example of this could be
//In the servlet //...lots of code.. session.setAttribute("email", email == null ? "" : email); session.setAttribute("name", name == null ? "" : name); session.setAttribute("message", message == null ? "" : message); res.sendRedirect(req.getHeader("referer")+"#"+formId); return; //... more code
After this, you can simply retrieve those values in the jsp when the page loads and do something with them.
/Johan
조회 수
답글
좋아요 수
Hi Johan ,
Thanks for the reply. The way you mentioned would work for case in which immediately after successful post,load the form with the values in session.
How about the case in which I freshly open the form page (state of the form page before i do a post)and it loads with saved properties,
thanks in advance
조회 수
답글
좋아요 수
Hi, well in that case. If you have your values stored under a node you can retrieve them with something
like thisin the jsp page:
//.. in jsp page //..code String MY_PATH = "/path/to/the/specific/node"; Resource myNodeResource = resourceResolver.getResource(MY_PATH); ValueMap myValuemap = myNodeResource.adaptTo(ValueMap.class); //...more code fetch the values of interes and check that they exist
.. then get the values from the value map and then just init the form with these values.
Of course you need some better code than the above, with error handlig etc. but you get the basic idea.
Good luck
/Johan
조회 수
답글
좋아요 수
조회 수
Likes
답글