Expandir minha barra de realizações na Comunidade.

Mark Solution

Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.

SOLUCIONADO

Reading a localStorage property in browser and use it in sightly-test condition

Avatar

Level 2

Hi,

I have a Path stored in the localStorage of my browser and would like to use it to test a path condition in Sightly.

Can you please let me know if this can be accomplished? If Yes, a prototype of the code would help.

Thanks in advance.

Regards,

Sagar

1 Solução aceita

Avatar

Resposta correta de
Level 5

Hi Sagar,

Reading localstorage directly in sightly is not possible. Localstorage is a related to client side and passing that value to directly to sightly is not possible. You might have to write some servlet :

Make an ajax  call in the component like below:

var url = "/bin/someservlet?localstorageval=" + localStorage.getItem("somelocalstorage") + "&resourcepath="+${resource.path}

In the servlet you can set the value of the localstorage to the resource path, which we are passing to the servlet.

Now you can access the value as ${properties.whatevervalue}

whatevervalue = This is the value which you set to the resource(component resource).

This is not a good solution but this is what I got it in my mind.

You can add a hidden field to you dialog and set some default value to it.

This might not work on the first load because ajax call will be done after sightly it already loaded.

Ver solução na publicação original

2 Respostas

Avatar

Administrator

Avatar

Resposta correta de
Level 5

Hi Sagar,

Reading localstorage directly in sightly is not possible. Localstorage is a related to client side and passing that value to directly to sightly is not possible. You might have to write some servlet :

Make an ajax  call in the component like below:

var url = "/bin/someservlet?localstorageval=" + localStorage.getItem("somelocalstorage") + "&resourcepath="+${resource.path}

In the servlet you can set the value of the localstorage to the resource path, which we are passing to the servlet.

Now you can access the value as ${properties.whatevervalue}

whatevervalue = This is the value which you set to the resource(component resource).

This is not a good solution but this is what I got it in my mind.

You can add a hidden field to you dialog and set some default value to it.

This might not work on the first load because ajax call will be done after sightly it already loaded.