DigitalJoel

2009/08/31

20/20/20

Filed under: general, health, tools — digitaljoel @ 9:13 pm

I found recently that my eyes were getting extremely tired at work.  After a few hours on the computer, while I wasn’t sleepy tired, my eyes would just ache, itch, droop, or water.  Some time ago my eye doctor told me to do the 20/20/20 rule for my eyes.

Every 20 minutes, look at something at least 20 feet away, for at least 20 seconds.  This is supposed to keep your eyes from focusing too hard on one thing for too long and getting fatigued.  Unfortunately, when I get deep into a programming task, it’s hard to remember to look away every 20 minutes.

Another tool I installed last week that seems to have made a significant difference is f.lux.  Someone on stackoverflow.com or slashdot or something mentioned it so I checked it out.  In the week that I have used it, I have found that my eyes are not nearly as tired as they used to be.

At first, I was a little put off by the pee-pee yellow color of the white’s on my LCD monitor, but after only a few hours I could tell a difference.  You can configure it to your liking, and disable it if you need to.  I set the daytime levels a little lower than the default.  I don’t really use the ‘daytime/nighttime’ settings, and I’m sure I could manually tweak my monitor to match the output I get from F.lux, but by simply installing the software I didn’t have to mess with that.  It also works on any monitor I hook my laptop up to, so I don’t have to manually configure each monitor.

If you find that you get dry, tired, itchy, or watery eyes after a few hours in front of the computer, give F.lux a try and see what you think.

Advertisements

2009/08/25

Passing action methods in Facelets using array notation

Filed under: facelets, java, JSF — digitaljoel @ 3:21 am

When I was first learning facelets, I often ran into a problem when I was passing an action method into an included facelet file. For instance, I had file1.xhtml, which would include my custom tag component file2.xhtml (defined within my taglib.xml file.) file2.xhtml had a commandLink or commandPrompt that needed an action. Since I would re-use file2.xhtml and allow it to call different actions, I needed a way to pass the action method to file2.

The first thought was to include it as an attribute of my component.

<myns:mytag
   myActionAttribute="${mybean.myaction}" />

and then within file2, which in this case is mapped to mytag:

<h:commandLink value="${mybean.myValue}" action="${myActionAttribute}" />

When I tried to execute this, faces would complain to me that mybean had no myaction property. I knew it did and would be endlessly frustrated by this.
The answer is to reference the action method using array notation. On any bean referenced in facelets you can reference the properties using dot notation, as in ${mybean.myaction}, OR you can also reference it using array notation, such as ${mybean[“myaction”]}.
I never did dig in far enough in order to figure out exactly what was going on under the hood, but I’m guessing ${mybean.myaction} was actually evaluated before being sent to mytag. In order to avoid this, pass the bean, and then pass the action method as a string to the component, such as:

<myns:mytag
   myActionController="${mybean}"
   myActionMethod="myaction" />

Notice that the method is just a string. Then in your component, reference it in array notation ( how many times can I say array notation! )

<h:commandLink value="${mybean.myValue}" action="${myActionController&#91;myActionMethod&#93;}" />

Notice that the method is NOT quoted. myActionMethod will be replaced by the String value passed in the value of the attribute, and that method on the bean will be called as the action of the commandLink.

Create a free website or blog at WordPress.com.