Thursday, November 13, 2014

On anger and arguments

When I start to feel angry at my wife and I see an argument brewing, I often stop to ask myself "what is the cost of the argument, and is it worth the cost?"  Generally, when I look at it this way, I discover it's not.  So often, the underlying issue is something trivial, and the damage done by the argument can be enormous, especially if it escalates.

Sometimes I try to think of some way of addressing an issue without turning it into an argument.  For example, the other day I noticed that my wife had not cleaned the pans she had used to cook her breakfast, leaving them for me to deal with (again).  I thought about confronting her directly, but whenever that happens, she immediately twists it to be about something she had done for me, making me into an ungrateful dick.  So instead, I took a sideways tack.  As I was cleaning the kitchen I looked over at the pans and said "didn't I just clean those yesterday?"  Somehow, that got the point across without it becoming an argument.

Wednesday, September 10, 2014

Determining keyboard modifiers (like Shift-Click) on a Wicket AjaxLink

If you want to determine if a user issued, say, a shift-click on an AjaxLink in Wicket 6, here's how you do it:

1) Add pass the keyboard state from javascript to the onClick function,via DynamicExtraParameters
2) Get the passed value in the onClick callback via the RequestParameters

Here's some sample code:

add(new AjaxLink("my-link") {
    @Override
    protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
        super.updateAjaxAttributes(attributes);
        attributes.getDynamicExtraParameters()
            .add("return {shiftKey: attrs.event.shiftKey};");
    }

    @Override
    public void onClick(AjaxRequestTarget target) {
        boolean shiftKey =
            RequestCycle.get().getRequest().getRequestParameters().
                getParameterValue("shiftKey").toBoolean();
        if (shiftKey) {
            ....
        }
    }         
};