Recently in web/tech Category

Grails makes validation of user input really simple.

Given virtually any Domain Class or Command Object, you can quickly and easily work up a form and validate it in no time.

The project I'm currently working on ( at work ) requires something above and beyond the normal validation routine - at least compared to most of the normal projects I have on my plate.

I'm at the point where I have the majority of the logic and flow taken care and there's no real validation of user input. That's intentional. I usually implement this as one of the last things so that I can move through the app without any barriers or having to fill each form out in its entirety.

So now I'm at the point where I start implementing validation and editing the default error messages. I have a form validation requirement that is dependent upon the values of other form fields. Since I haven't had this as a requirement for other apps in the past ( with Grails ) I decide to take a look at the documentation at the Grails site.

Crap! They are only documenting pretty simple, straight-forward stuff.

Say you want to validate the age field ( so that it cannot be null ) on a Domain Class or Command Object:

static constraints = {
     age(nullable:false)
}

Simple. Straight forward. I like it.

But my situation is considerably different.

In my situation the user must complete a form that constitutes a business address. Also on the form are fields that make up a contact name, title and phone number. The business rule states that if the form is submitted with a Contact Name or Contact Title there must be a Phone Number.

It would be nice if there were a built-in constraint like:

static constraints = {
      field1(mustBePresent:field2)
}

If I remember right Rails has something like this. I can't remember the name of the validator in Rails, but there's a way to do this with Grails . . .

It took some searching and most of the examples I found were posts to forums in which the implementation of the validation was not working correctly. While the posts gave me some insight, I had to try and figure out what was wrong with their code and how to get it working correctly.

Essentially what I want is validation on both the Contact Name and Contact Title fields. The validation should confirm that the Phone Number field is populated in the event that either the Contact Title or Contact Name fields are populated. For this example I'm not going to go into validating the content of the values, just the presence of.

The message can be essentially the same in the messages.properties file, but we'll need two entries.

     className.contactName.invalid.phone=A Phone Number must accompany a Contact Name.
     className.contactTitle.invalid.phone=A Phone Number must accompany a Contact Title.

Here's what I came up with:

constraints = {
     . . . . .
     phoneName( validator: { val, obj ->
          if(
            ( val != null && val.length() > 0 ) &&
            ( (obj.properties['phone'] == null) || (obj.properties['phone'].length() <= 0 )
            )
            {
                  return ['invalid.phone']
            }
      })
      phoneTitle( validator: { val, obj ->
          if(
            ( val != null && val.length() > 0 ) &&
            ( (obj.properties['phone'] == null) || (obj.properties['phone'].length() <= 0 )
            )
            {
                  return ['invalid.phone']
            }
      }) 
}

I could just as easily performed other validation checking for a valid phone number with regex, although that should probably done directly on the phone number field.

A good practical application of this is checking a password confirmation field. Perhaps I'll do that in another post.

I hoped this helped if you came across this post looking for an example like this - let me know in the comments.

Privacy a thing of the past

One of the blogs I tend to read is ReadWriteWeb ( RWW ). Yesterday they had an interesting article that got me to thinking a bit. According to RWW, Facebook's Zuckerberg Says The Age of Privacy is Over.

I read the post and the comments and watched the video. I guess the whole thing for me is, is this an accurate representation of what is really going on with society. Do people really care less about privacy? Are we really tending towards "more open" than "more privacy?"

Personally, I tend to believe that people are leaning towards taking privacy less seriously. That isn't to suggest that people care less. They still want their privacy. And when their privacy is violated they tend to get all up in arms about it. Take for example the high school student who posts not-so-flattering-things about their principal on their Myspace page and ends up getting kicked off the cheerleading squad or other school activity. Perhaps they thought that information was private, but didn't select the right setting? Who knows. Better yet, consider the teacher who posts pictures of her drinking at a party and subsequently loses her job and ends up getting all upset about it. Let's face it, the best thing to do is NOT put that info out there if you don't want the whole world seeing it.

But seriously, where does this attitude come from? Being a guy in his forties ( I hate to admit it . . .but ) I can remember when I pretty much took it for granted that stuff about me was private. I think a fairly decent example of this was the fact I used to prank call Domino's Pizza quite a bit. I would order pizzas for my friend across the street. Domino's always fell for it and me and my friend would laugh about it the next day. I could safely do this because caller id was not available. Now I could never get away with it.

Better yet assume that my girlfriend and I wanted to take naked pictures of each other. Back then I could use a Polaroid and there would be a single picture that I could hide or burn and no one would ever be the wiser. Today it's digital and copies could spread like a bad rash.

In other words, I think there's the issue of expectations. I'm not sure that people really expect privacy that much any more. We all know that our email addresses and phone numbers and any other information like buying habits are harvested with every swipe of a credit card or service sign-up. Then that information is sold to someone and they sell it and so on and so on. Our credit card data is but one hack away from being sold by some Eastern European computer geek since retailers, banks and credit card processors take data security about as seriously as the Bush administration took hurricane warnings.

However, because some people have become complacent about privacy doesn't strike me as a reason to adjust your corporate policy. If anything I would think that becoming more of an advocate for privacy would be the right thing to do.

Personally, I'm not a big user of facebook. I don't have a picture of myself there and I don't update my status or anything like that. I just use it to keep an eye on my kids. So what facebook does with their privacy controls is only important to me to the point that I might need to remind my kids that they need to be vigilant.

Some of the people commenting at RWW think this is going to really hurt facebook and that it's a good time to be a competitor. I don't know? Does this really make you want to leave if you have a facebook account?

What would true competition for facebook look like? If greater privacy was provided would you be willing to pay for it?

It's all about the data

I'm one of those people that most likely would have been diagnosed with ADD had it been as big an issue when I was a kid as it is now. I start projects, get to a certain point and then lose interest as another project pops up to take its place.

It's always been about the nature of the project and how interesting it is. Some projects have been able to hold my interest longer than others simply by virtue of the complexity, the newness of the technology or the potential value of the project. One of those projects that has moved from the front burner to the back burner and back again and so forth . . . is back on my radar and I'm working on it. But there's really kind of an interesting little story about it and why it is back on my radar again.

OpenID accepted here Learn more about OpenID

About this Archive

This page is an archive of recent entries in the web/tech category.

weather is the previous category.

writing is the next category.

Find recent content on the main index or look in the archives to find all content.