[weld-dev] @Inject FacesContext
Gavin King
gavin.king at gmail.com
Tue Nov 10 17:24:30 EST 2009
Ah. Hrm. A good point, which I had not thought of, is that you can't
assign it to an instance variable.
But you can use a static import, and just write: getFacesContext()
everywhere. Easy.
Like I said, I can add this in a maintenance release if its important.
On Tue, Nov 10, 2009 at 5:21 PM, Dan Allen <dan.j.allen at gmail.com> wrote:
>
>> The reason for injection is to be able to stub and unit test easily. Right
>> now the getCurrentInstance() is static and you'd need to use ugly
>> constructions to replace it with a stub (I am not saying it's impossible but
>> I am talking here from the feedback I've gathered and personal experience
>> when unit testing pure JSF).
>
> And the other, more subtle annoyance is the you have to eventually make that
> decision in a method when to create a local variable for FacesContext
> because your code is getting too verbose.
>
> FacesContext ctx = FacesContext.getCurrentInstance();
>
> I hate writing that line. Every time I do, I think to myself "I hate this
> stupid line of code."
>
> -Dan
>
> --
> Dan Allen
> Senior Software Engineer, Red Hat | Author of Seam in Action
> Registered Linux User #231597
>
> http://mojavelinux.com
> http://mojavelinux.com/seaminaction
> http://www.google.com/profiles/dan.j.allen
>
--
Gavin King
gavin.king at gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org
More information about the weld-dev
mailing list