0

I am calling another application context from window.showModalDialog but confused with following work. Same code to pass parameter within showModalDialg.

var myArguments = new Object();
myArguments.param1 = "Hello World :)";
window.showModalDialog("java2sTarget.html", myArguments, ''); 

and i can read these myArguments(parameters) in generated HTML using following code:

<script>
  document.write(window.dialogArguments.param1);//Hello World :)
</script>

I can't use query string & i am sending myArguments(parameter) because i want to hide parameter from Application user.

Now i am calling servlet from showModalDialog(..)

onclick="window.showModelDialog('http://localhost:7778/app/servlet/test',myArguments,'');" 

onclick="window.showModelDialog('http://localhost:7778/app/servlet/test',myArguments,'');"

But as per my knowledge

Servlet  --> Servlet container --> HTML+JS+CSS

so JS will be available at last phase, but i want to use in first phase(Servlet).

Now, i need to make some Decision in servelt code based on myArguments(parameter).

is there any way to read these myArguments(parameters) in servlet code?

Awan
  • 159
  • 1
  • 10

2 Answers2

0

Pass it as a request parameter in the query string.

var queryString = "param1=" + encodeURIComponent("Hello World :)");
onclick="window.showModelDialog('http://localhost:7778/app/servlet/test?' + queryString, myArguments, '');" 

No, there's no other alternative. The request URL is not visible in the modal dialog anyway.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks teacher, for your suggestion. i learned many things from your answers. But this time main goal to hide queryString from user. – Awan Feb 24 '12 at 07:07
0

As main objective is to hide query string from User to avoid misuse of those parameters. I tried following work around.

Developers send hidden parameters to get relative information form source(e.g.:DataBase). And we also know that we can send hidden information in Window.showModalDialog using dialogArguments

Work Around:

(i) I got relative information from server one-step before calling Window.showModalDialog using jQuery.getJSON()

(ii) i used google-gson API at servlet side to convert JavaBeans into Json strings.Solution 1 Solution 2

(iii) Convert JSON into javascript object using jQuery.parseJSON

var args = jQuery.parseJSON(json);
window.showModalDialog("pages/"+args.pageName, args, ''); 

i used args.pageName to make things dynamic

Please suggest improvements in this work-around. Thanks

Community
  • 1
  • 1
Awan
  • 159
  • 1
  • 10