-
1. Re: Simple question: finding the client IP address in a sess
norman.richards Jan 6, 2007 12:20 AM (in response to smokingapipe)<factory name="remoteAddr" value="#{facesContext.externalContext.request.remoteAddr}" />
-
2. Re: Simple question: finding the client IP address in a sess
smokingapipe Jan 6, 2007 2:36 AM (in response to smokingapipe)Thank you Norman. I put that into my components.xml and now I can do an injection like:
@In("#{remoteAddr}") private String ipString;
and it works, which is pretty cool.
Seam. There's quite a bit of a learning curve but once it is working it's pretty cool stuff. -
3. Re: Simple question: finding the client IP address in a sess
norman.richards Jan 6, 2007 2:55 AM (in response to smokingapipe)If you add auto-create="true" to the factory definition you could just do:
@In String remoteAddr;
(without auto-create, you need create="true" on the above) -
4. Re: Simple question: finding the client IP address in a sess
smokingapipe Jan 7, 2007 1:53 AM (in response to smokingapipe)I did that and it works. That is cool! I didn't even know about factory elements in components.xml. I might set them up for other things I need, like looking at HTTP headers (user-agent, etc). Given that I can traverse maps in EL that should be a piece of cake.
I've been in Servlet-world for a long time so this is quite an adjustment; no more servlets, no more thinking in terms of requests. But it's so obviously superior, once you get it working. Getting it working is non-trivial, and answering, "why is this not working" is not obvious until you've worked in it for a while, but it is an amazing thing once it gets going. -
5. Re: Simple question: finding the client IP address in a sess
norman.richards Jan 7, 2007 2:40 AM (in response to smokingapipe)My view is that ideally you should never have to think about URLs or request parameters or session variables when writing a web application. Or at least you shouldn't have to think about them any more than you think about your database tables and columns when writing code to use an entity. Sure you need to worry about your column name when creating the mapping meta-data, but when you call person.setName(), you shouldn't be exposed to any of that.