Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-1981

RadioGroup component validation error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 5.3.4, 5.4
    • 5.4
    • tapestry-core

    Description

      Here is example.
      Let's admit is bean with a property "number" which value should not be greater than 2.
      There are 2 forms with RadioGroup.
      The first form uses tapestry validation, The second - JSR-303.

      If you will choose "3" and will submit the first form - validation will not work.
      If you will choose "3" and will submit the second form that there will be an exception.

      package com.mycompany.mavenproject1.entities;
      
      import javax.validation.constraints.Max;
      
      /**
       *
       * @author AlexLumpov
       */
      public class Bean {
      
      	private int number;
      
      	@Max(2)
      	public int getNumber() {
      		return number;
      	}
      
      	public void setNumber(int value) {
      		number = value;
      	}
      }
      
      package com.mycompany.mavenproject1.pages;
      
      import com.mycompany.mavenproject1.entities.Bean;
      import org.apache.tapestry5.FieldValidator;
      import org.apache.tapestry5.annotations.Component;
      import org.apache.tapestry5.annotations.Environmental;
      import org.apache.tapestry5.annotations.Persist;
      import org.apache.tapestry5.corelib.components.RadioGroup;
      import org.apache.tapestry5.services.PropertyEditContext;
      
      /**
       * Start page of application mavenproject1.
       */
      public class Index {
      
      	@Component(parameters = {"value=bean.number", "validate=prop:beanValidator"})
      	private RadioGroup group2;
      
      	/* */
      	@Persist
      	private Bean bean;
      
      	/* */
      	@Environmental
      	private PropertyEditContext context;
      
      	public Bean getBean() {
      		if (bean == null)
      			bean = new Bean();
      		return bean;
      	}
      
      	public FieldValidator getBeanValidator() {
      		return context.getValidator(group2);
      	}
      }
      
      <!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
            xmlns:p="tapestry:parameter">
      
          <head>
              <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
      		<title>RadioGroup Validation Test</title>
          </head>
      
          <body>
      		<h1>test 1</h1>
              <t:form>
      
      			<t:errors/>
                  <t:RadioGroup value="bean.number" validate="max=2">
                      <t:radio value="1"/>1<br/>
                      <t:radio value="2"/>2<br/>
      				<t:radio value="3"/>3<br/>
      			</t:RadioGroup>
      
      			<t:submit/>
              </t:form>
      
      		<h1>test 2</h1>
      		<t:BeanEditForm object="bean">
      			<p:number>
      				<t:comp t:id="group2">
      					<t:radio value="1"/>1<br/>
      					<t:radio value="2"/>2<br/>
      					<t:radio value="3"/>3<br/>
      				</t:comp>
      			</p:number>
      		</t:BeanEditForm>
          </body>
      </html>
      

      Attachments

        1. mavenproject1.zip
          13 kB
          Alex Lumpov
        2. RadioGroup.java.patch
          2 kB
          Alex Lumpov

        Activity

          People

            Unassigned Unassigned
             alexlumpov Alex Lumpov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: