Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under validation...

HikiCulture says...

Here's the latest batch of HikiCulture members I've given VIP status to:

Glasses
Porygon
FONEternal
LyricalIllusions
Hitori
Carruthers
Knots
shorelinetrance
gloomba
MobiusBrain
sibirskaya_koshka
geegor

Congrats.

Filed under: Validation

unugurn says...

QuipuKit 1.6.2: JSF library with a set of advanced UI components and clientside validation http://bit.ly/eLJum

Filed under: validation

trapo says...

Sometime ago I was fighting with Hibernate Validator, trying to implement an unique constraint and I could not figure out how to create one that requires database access:

The problem is that your validators can't access sessionFactory or any other interface to the database. I know that I can break some rules and instantiate a sessionFactory/session/connection directly inside the Validator, but I dislike to do wrong things consciously. So, I looking for alternatives.

Then, while studying the new validation support offered by Spring, I just discovery that using Spring I can inject any bean inside my ConstraintValidators. From Spring documentation:

By default, the LocalValidatorFactoryBean configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean.

And here is how you can use that Spring feature to implement unique constraint.

THE UNIQUE ANNOTATION

It is very simple and direct. You can see details about implementing your custom annotations in Hibernate Validator docs.

@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy=UniqueConstraintValidator.class)
@Documented
public @interface Unique {
    String message() default "{constraints.unique}";
    Class<?> entity();
    String field();
    Class<?>[] groups() default {};   
    Class<? extends Payload>[] payload() default {};
}

You can also see the code at GitHub, where trapo is hosted. If I decide to change something, you can get an updated version there. Once you have the @Unique annotation, you must implement the ConstraintValidator referenced by "validationBy" property in @Constraint annotation above. Here is the code using a bean injected by Spring:

public class UniqueConstraintValidator implements ConstraintValidator<Unique, String> {

    @Autowired private SessionFactory sessionFactory;
   
    private Class<?> entity;
    private String field;
   
    public void initialize(Unique annotation) {
        this.entity = annotation.entity();
        this.field = annotation.field();
    }

    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(StringUtils.isEmpty(value)) {
            return false;
        }
        return query(value).intValue() == 0;
    }

    private Number query(String value) {
        HibernateTemplate template = new HibernateTemplate(sessionFactory);
        DetachedCriteria criteria = forClass(entity)
                                   .add(eq(field, value))
                                   .setProjection(count(field));
        return (Number)template.findByCriteria(criteria).iterator().next();
    }

}

Just like the @Unique annotation, you can find the code in GitHub. Now you just need a Validator bean that can be injected in the classes that need it.

<bean id="validator"
      class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

Voilá!

THE UGLY PART

Right now, Hibernate Validor don't offer any way to know from where your annotations are coming. If you take some time to think about the ConstraintValidator above, you will notice that I manually configure the entity class and field information that were annotated. I need that information to know what query I must execute in order to validate the uniqueness of the field. Bad to me. Really bad. Now I have to provide this information by myself annotating the field like the code highlighted below:

    @NotEmpty @Unique(entity = Forum.class, field = "name")
    private String name;

I can even hear the DRY concept crying! I can't also find a way to reflect this to my schema. Maybe Hibernate Validator can offer some interfaces that we can use to implement all this stuff.

Filed under: validation

Will says...

W3C says <link> and <style> should only be in the <head>. Why am i concerned with validation? I'm not; so I was originally alright with my first attempt to reduce code repetition.

Each page has a very similar top and an identical bottom.The problem with the top is in the included scripts and styles. All pages load corners. Some load fancy box. one loads visualize. Each of these has its own style sheet. Additionally each page has a different title, some custom style, and a unique position in the navigation display. I'd like include both in one gutted file and then load the meat on demand from external files. I could take care of loading uncommon styles and scrips simply by including them in the body. This works on firefox at least. The title and nav display could easily be handled by on click action, passing an argument or (as is the current implementation) deducing from the url. Also, broken up like this, I could add fancy effects by loading with the data via $.ajax in jQuery. So I did all of this, the whole time thinking hash marks in the url would add sufficient browser aware navigation (a working back button).  This was not the case.
content transitioned with beautiful fades while the bottom and top were able to stay static. It looked professional. But the back button did nothing. Each page changed window.location.hash. but the browser didn't care or remember the last real "GET." Disappointing. Worse, I didn't spend enough time to figure out how facebook or gmail does it. It was too cumbersome to implement anyway. I was doing this to save work (while avoiding actually doing something productive).
Instead of breaking the load into two files: one with most static stuff that calls in the real content. I've done two static-ish pages (top and bottom) and one page the meat that calls in the other two. I load uncommon scripts and styles, then the top, do the heavy lifiting, and then call in the bottom. No more fancy effects. But the code is clearer, authentication can be done in the top and doesn't have to be repeated (php include works so the $user variable established and potentially authenticated in the top container is accessible and therefore actionable to the including script.) The only remaining hick-up is navigation customization per page. Because it's in the middle of the top content, I didn't want to truncate the top and extend each content page. And i didn't want to include two different top pages just to figure out which anchor tag to put the current class on. Instead I came up with this ugly hack.

/*ugly ugly ugly way to set get current location for sytling navigation*/
    $current = preg_replace("/.*\/(.*).php.*/", "$1", $_SERVER["REQUEST_URI"], 1); 
    $hascurrent= array( 'home' => '', 'dashboard' => '', 'new' => '',  'edit' => '', 'publish' => '' );
     $hascurrent[$current] = ' class="current" ';

and then later in the php file
<li style="padding-left:0px">
            <?php echo $hascurrent['home']?>>My Account</li>
         <li><?php echo $hascurrent['new'] . $hascurrent['edit']. $hascurrent['publish']?>
                                >Build a Case</li>
         <li><?php echo $hascurrent['dashboard']?>>Case Dashboard</li>
        <li>Help</li>
 

I get a name from the url, removing the junk before and after the relevant part of the file name using preg_replace. Where all value are otherwise ' ', I add 'class=curernt' to the element of the hascurrent array called by that name of the file. Then I ask for the value of each array by this name in on the approprate link in the navigation portion. Nothing but whitespace will be added unless the current file name is called. Then the class=current is injected. Ugly, but functioning.

Filed under: validation

taptopia says...



We are nearing the availability of our first iPhone application, Tap Groups. This will be the first in a series of business related apps that compliment the daily use of the iPhone by business users. Our goal at Taptopia is to provide value-added applications that make a great device even better. There is a clear focus at Apple to make the fastest selling mobile phone a part of true enterprise integration. Additional evidence, as noted in prior posts, confirm the fact that this is truly the direction for the iPhone.

Tap Groups is a simple app that allows users to create groups for use in Contacts. This capability is lacking from the native iPhone OS and has already made contact management much easier for us and our internal testers. We can't wait to share the app with other iPhone users. We will post immediately once the app goes live in the App Store.


Filed under: validation

taptopia says...


Apple is known for their innovation and support. It is clear that there is a very specific development cycle within the software group. This process is very guarded and up until right before release, the features are typically unknown. This makes it tough for application developers to plan products that have and longevity, if they aren't immediately included in an OS release.

This has happened for a number of products designed around missing features in the iPhone OS. A couple of examples are as follows. Consider remote file access. This is a big missing feature in the initial releases. Naturally, many vendors rallied around providing various products to make up for the lacking functionality. A number of solutions addressed this via various cloud-based offerings. The most compelling were those that provided WebDAV support and actually provided MobileMe access. Quickoffice developers provided Mobile Files which has since been named Quickoffice Files (iTunes link) and has been rolled into their suite of products. Another great implementation was Air Sharing (iTunes link) by Avatron software. They offer a couple of versions with different features. It didn't take long for Apple to provide their MobileMe iDisk client (iTunes link) which is a very nice application for Mobile Me users. This is an example of Apple eventually providing application support.

Apple also implements native support for certain features where app developers have addressed the lack of functionality. A good example of this was the initial lack of a landscape keyboard. There are a number of landscape keyboard apps that hit the App Store as a result. The following are just a few of the many that are available (all are iTunes links): Compose, Sideways, Wide Email. Then there was the 3.0 release of the iPhone OS and these apps are now somewhat less appealing and competitive due to the inclusion of the landscape keyboard.

It is imperative that some level of product planning is necessary. The fact that Apple is subject to provide your functionality as a part of the core OS is always a possibility but it is not always a bad thing. Many of the apps mentioned above differentiate themselves by adding additional features within the solution thus staying ahead of the curve. Competition, whether it be from other developers or Apple directly, encourages innovation and creativity. There are still many opportunities to enhance the iPhone user experience (wink, wink) and we believe that we have a great future ahead that is full of great applications that provide real value and benefit.

Filed under: validation

taptopia says...


One of the goals within our business is to initially take the iPhone platform and tailor applications for business users. Our team is comprised of individuals with at wealth of business, entrepreneurial, and technology experience. We are also daily users of the technology for which we develop. We have the same frustrations as everyone else and are launching applications that will hopefully solve some of the current issues we have found for business users.

In a recent article in the Wall Street Journal, the trend of business adoption of the iPhone is being driven by developers. It is clear that Apple wants to be the leader in the business market and has enabled a powerful community of developers that are creating very practical and useful applications.

We see the opportunity and have been saying this for a long time. It is nice to have mainstream media articulate the vision.

Filed under: validation

Hiếu says...

Do you need a validation? Watch on!

 

Filed under: Validation

Jake says...

I quote below from an American nerd athlete artist.  He's relieved at the American electorate's ability to choose the intellectual candidate.  But his comment intends to celebrate neither American nor Chinese culture.

We live in a country where the nerd gets beaten up in middle school.  In China, the nerd is the bully.

I did not know this about China when I lived there.  I never saw it happen, never heard stories about it until today.  But it does make sense.  Good grades earn big teacher love and, with it, positions of authority in classrooms.  And there doesn't exist a school-connected athletic infrastructure to balance the power.  Validation comes first for the successfully academic minds and significantly later, if at all, for anyone else.

Anyone have any experience with this?  I'd love to know more.

Filed under: validation