0

I need to get userPrincipal inside a piece of Javascript code. My app currently uses Dojo on the client side and servlets on the server side. I am not using JSF, nor JSP (and if possible I would try to avoid using it only for this purpose), nor JQuery (I would avoid mixing JQuery with Dojo). I have read this interesting post Mixing JSF EL in a JavaScript file . Following the idea #1, I have written a Bean but I am not sure on how to embed the call to the Bean in my (quite long) js file.

Community
  • 1
  • 1
perissf
  • 15,979
  • 14
  • 80
  • 117

1 Answers1

1

If you don't use JSF or JSP or anything similar, just bare servlets, I recommend creating a servlet which takes the userPrincipal name from the HttpServletRequest (or any other place) and returns it in JSON format. Then you can do an AJAX call to the servlet and find out what you need. I don't know Dojo too well, but I believe you can insert this AJAX call in your event chains pretty easily.

I don't recommend mixing managed beans with plain-old servlets.

If AJAX is not an option for you because of its asynchronous nature, you cand create a servlet that serves text/javascript content which offers the principal's name in the form of javascript code and then add a script tag to your page.

vteodor
  • 71
  • 4
  • Yes this is a good option. I would have liked a Managed Bean also but maybe it's not necessary to add Faces only for that... – perissf Sep 04 '11 at 19:50