Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

Wednesday, December 11, 2013

Vaadin TextFields in a Table empty/null value not propagated for required field

Setup

Problem

When you create a table in Vaadin with a .setTableFieldFactory(), and you have a Field which is set to .setRequired(true), and a user puts in an empty value for that field after first putting in a non-empty value, the field won't be set to that empty value when iterating through the table to read the current values.

Solution

Make sure you invoke .setInvalidCommitted(true) on that field to have the empty value also be passed through; i.e "committed" even though validation fails.

For example:

urlTable.setTableFieldFactory(new DefaultFieldFactory() {

    @Override
    public Field createField(final Container container, final Object itemId, final Object 
                    propertyId, Component uiContext) {

    if (URL_PROPERTY_ID.equals(propertyId)) {
        
        final TextField urlText = new TextField();
        urlText.setRequired(true);

        // Add the below line to have also the empty string be
        // passed on!!
        // See: https://vaadin.com/forum#!/thread/1129126
        urlText.setInvalidCommitted(true);
        urlText.setImmediate(true);
        urlText.setNullRepresentation("");
        urlText.setInputPrompt("Enter a URL");
        return field;

}

Note the bold line.

And for completeness here an example of the iterating over the table to get the current entered values:

List result = new ArrayList();
int sequence = 1;
for (Iterator iterator = urlTable.getItemIds().iterator(); iterator.hasNext();) {

    // Get the current item identifier
    String itemId = (String) iterator.next();

    // Now get the actual item from the table.
    Item item = linksTable.getItem(itemId);
    @SuppressWarnings("unchecked")
    Property urlProperty = item.getItemProperty(URL_PROPERTY_ID);
    String url = urlProperty.getValue();

    // Fill the object
    UrlInfo urlInfo = new UrlInfo();
    urlInfo.setUrl(url);
    // ... set other stuff
    result.add(urlInfo);
    sequence++;
}

return result;

Related resources

The forum thread that put me on the right track can be found here.
Long thread related to required vs validation problems can be found here.
@NotNull bean validator annotation combined with setRequired() also has some issues.


Sunday, December 28, 2008

Best of this Week Summary 16 December - 28 December 2008

  • Great insight on Second Life's architecture. For example: "A physical server (1 CPU) is responsible for about 16 acres of land and it is connected to neighboring ones which are each responsible for another 16 acres. The server is responsible for the objects existing in its area, the scripts running, the users logged in and standing in its area". Presentation is one hour in total.

  • There's more to REST than meets the eye. And many REST APIs are not really as REST as Roy Fielding defines it. Media type design is an important item that was not in his original REST dissertation. Some interpretation of what Roy actually means can be found here.

  • JanRain (known for their OpenID libraries) have created a nice widget named RPX that allows you to integrate authentication within your existing site in an easy and user-intuitive way. I really like the clear, easy and non-intrusive way the possibilities are shown. For real novice users the redirecting to and from the authenticating sites might still be a little bit confusing though. Supported protocols are: OpenID 1.x/2.0, Facebook Connect, MySpaceID and Google. Below is a screenshot of what the registration part looks like:

    A couple of example sites where this is already implemented can be found here. And some more on the possibilities here.
    Note that from the technical overview you can see that the RPX server sits in between. That is the only disadvantage of this solution: that you are dependent on an intermediate server.

  • The W3 Consortium has released a webpage mobile-friendliness checker. The tests it performs can be found at the mobileOK Basic Tests 1.0 specification. Other validators you might know from them are the feed validator, XML Schema Validator, CSS validator or Markup validator. Running these very succesful services without any advertising is costing a lot of money. Therefore you can now donate here for support. If you compute how much time those validators have saved you, donating any small percentage of that will already help W3C keep these validators running.

Sunday, October 19, 2008

Best of this Week Summary 07 October - 19 October 2008

  • Having nice user-friendly bookmarkable URLs when you're using the Wicket web framework is not so trivial. Especially if you want those nice URLs when validation errors occur. As an example, on this Wicket based site enter "hello" in the end-date field. Now check the URL in your address bar just before you click Filter (http://online.ddpoker.com/leaderboard) and right after the submit when you see the validation error (http://online.ddpoker.com/?wicket:interface=:0:1:::). Here's the solution for those cases too!

  • Have you been clickjacked lately?

  • More clarification from Rod Johnson on the new maintenance policy for Spring.

  • As a side note, Microsoft is designing a new programming language "M", part of its new Oslo development and service-oriented strategy. Most likely it will be .Net based. Will it ever see the day of light? Much more concrete is this new open source Touchless SDK, which enables developers to create multi-touch based applications using a webcam for input.

Sunday, February 10, 2008

Best of this Week Summary 28 January - 10 February 2008

  • Interesting idea mentioned in this post: the very basic site inursite.com validates your markup daily and you get sent the result via email or RSS. Of course during the building your site should already validate, but this site can help for Continous Integration of your front-end.

  • Great overview of Javascript/AJAX performance issues in all major browsers (except Opera). You can use this information to know where to focus your Javascript optimizations on.

  • This week several BIG names joined OpenID: Google, Verisign and IBM.

  • Google's just released Social Graph API. It tries to find public relationships between people's accounts.