Not able to Manipulate HSt Response while ajax request

61 views
Skip to first unread message

Ben-10@Dev

unread,
Sep 26, 2016, 12:55:04 PM9/26/16
to Hippo Community
Hi,
   I have been sending ajax request to server. Once job has been done i want to send a response to clinet with json data. i am not able to figure out loop whole in code.
Case 1- Once i have code for response like this 


on browser does not include response like this





Case 2 - When i have include line in code printWriter.close(); then it through me error in console Caused by: java.lang.IllegalStateException and response included as json data.

 Please provide a solution for this or any suggestion for this.
Jsp code is 





Ard Schrijvers

unread,
Sep 26, 2016, 1:13:41 PM9/26/16
to hippo-c...@googlegroups.com
Hey Ben,

for action requests we use the PRG pattern see [1], so your requirement is not possible with action requests. Don't you want to post to some rest endpoint? That seems to match your use case better. Otherwise to a org.hippoecm.hst.core.component.HstComponent#doBeforeServeResource method, see [2]

HTH,

Regards Ard


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
Hippo USA, Inc. 71 Summer Street, 2nd Floor Boston, MA 02110, United states of America.

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

Ben-10@Dev

unread,
Sep 26, 2016, 3:43:40 PM9/26/16
to Hippo Community
Thanks Ard.
  I have two forms/two component on same page. I don't want to submit both on same stage. One form will be submit from ajax request and response of that request will be shown at same time without affecting other form values(without refreshing page).


On Monday, September 26, 2016 at 10:43:41 PM UTC+5:30, a.schrijvers wrote:
Hey Ben,

for action requests we use the PRG pattern see [1], so your requirement is not possible with action requests. Don't you want to post to some rest endpoint? That seems to match your use case better. Otherwise to a org.hippoecm.hst.core.component.HstComponent#doBeforeServeResource method, see [2]

HTH,

Regards Ard

On Mon, Sep 26, 2016 at 6:55 PM, Ben-10@Dev <priya...@gmail.com> wrote:
Hi,
   I have been sending ajax request to server. Once job has been done i want to send a response to clinet with json data. i am not able to figure out loop whole in code.
Case 1- Once i have code for response like this 


on browser does not include response like this





Case 2 - When i have include line in code printWriter.close(); then it through me error in console Caused by: java.lang.IllegalStateException and response included as json data.

 Please provide a solution for this or any suggestion for this.
Jsp code is 





--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

Ben-10@Dev

unread,
Sep 27, 2016, 5:55:47 AM9/27/16
to Hippo Community
Hi Ard,
     I have tried to write response(JSON) on dobeforeRender but response also contain html so it's not able to parse JSON.

Ard Schrijvers

unread,
Sep 27, 2016, 6:05:37 AM9/27/16
to hippo-c...@googlegroups.com
Hey Ben,

I referred to using doBeforeServeResource, see [1]

Regards Ard

[1] https://www.onehippo.org/library/concepts/component-development/serve-a-dynamic-resource.html

On Tue, Sep 27, 2016 at 11:55 AM, Ben-10@Dev <priya...@gmail.com> wrote:
> Hi Ard,
> I have tried to write response(JSON) on dobeforeRender but response
> also contain html so it's not able to parse JSON.
>
>
>
> On Tuesday, September 27, 2016 at 1:13:40 AM UTC+5:30, Ben-10@Dev wrote:
>>
>> Thanks Ard.
>> I have two forms/two component on same page. I don't want to submit both
>> on same stage. One form will be submit from ajax request and response of
>> that request will be shown at same time without affecting other form
>> values(without refreshing page).
>>
>> On Monday, September 26, 2016 at 10:43:41 PM UTC+5:30, a.schrijvers wrote:
>>>
>>> Hey Ben,
>>>
>>> for action requests we use the PRG pattern see [1], so your requirement
>>> is not possible with action requests. Don't you want to post to some rest
>>> endpoint? That seems to match your use case better. Otherwise to a
>>> org.hippoecm.hst.core.component.HstComponent#doBeforeServeResource method,
>>> see [2]
>>>
>>> HTH,
>>>
>>> Regards Ard
>>>
>>> [1] https://en.wikipedia.org/wiki/Post/Redirect/Get
>>> [2]
>>> https://www.onehippo.org/library/concepts/component-development/serve-a-dynamic-resource.html
>>>
>>> On Mon, Sep 26, 2016 at 6:55 PM, Ben-10@Dev <priya...@gmail.com> wrote:
>>>>
>>>> Hi,
>>>> I have been sending ajax request to server. Once job has been done i
>>>> want to send a response to clinet with json data. i am not able to figure
>>>> out loop whole in code.
>>>> Case 1- Once i have code for response like this
>>>>
>>>>
>>>> on browser does not include response like this
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Case 2 - When i have include line in code printWriter.close(); then it
>>>> through me error in console Caused by: java.lang.IllegalStateException and
>>>> response included as json data.
>>>>
>>>> Please provide a solution for this or any suggestion for this.
>>>> Jsp code is
>>>>
>>>>
>>>>
>>>>
>>>>

Ben-10@Dev

unread,
Oct 2, 2016, 5:07:35 AM10/2/16
to Hippo Community
Thanks Ard, 
       resource was very helpful.
Cheers

neha malhotra

unread,
Aug 31, 2017, 2:25:49 AM8/31/17
to Hippo Community
 Hi Ben-10@Dev,

can you please share details on usage of
doBeforeServeResource.

Use case is submit form using ajax
Reply all
Reply to author
Forward
0 new messages