You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Ron Piterman (JIRA)" <ta...@jakarta.apache.org> on 2005/07/17 10:38:10 UTC

[jira] Created: (TAPESTRY-410) IdentityValidator

IdentityValidator
-----------------

         Key: TAPESTRY-410
         URL: http://issues.apache.org/jira/browse/TAPESTRY-410
     Project: Tapestry
        Type: Improvement
  Components: Framework  
    Versions: 4.0    
    Reporter: Ron Piterman
    Priority: Minor


The following class compares the validated field against another field. It works in two modes: 
match=<fieldname> and differ=<fieldname>

Cheers,
Ron


package org.apache.tapestry.form.valid;

import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.form.TextField;
import org.apache.tapestry.form.ValidationMessages;
import org.apache.tapestry.form.validator.BaseValidator;

public class IdentityValidator extends BaseValidator {
	private String _fieldName;
	private int _matchType;
	private String _identityMessage;
	
	private static final int DIFFER = 0;
	private static final int MATCH = 1;
	
	
	public IdentityValidator() {
		super();
	}


    public IdentityValidator(String initializer)
    {
        super(initializer);
    }

    public String toString(IFormComponent field, Object value)
	    {
	        if (value == null)
	            return null;

	        return value.toString();
	    }

	public void validate(IFormComponent field, ValidationMessages messages, Object object) 
		throws ValidatorException
	    {
	        TextField referent = 
	        	(TextField)field.getContainer().getComponent(_fieldName);

                //TODO: if component is null treat _fieldName as an ognl expression
	        
	        boolean notEq = notEqual ( referent.getValue() , object ); 
	        
	        if ( _matchType == MATCH ? notEq : !notEq )
	            throw new ValidatorException(buildIdentityMessage(messages, field, referent),
	                    ValidationConstraint.CONSISTENCY);
	    }

	    public String getMatch()
	    {
	        return _fieldName;
	    }

	    public void setMatch(String field)
	    {
	        _fieldName = field;
	        _matchType = MATCH;
	        
	    }
	    
	    public String getDiffer() {
	    	return _fieldName;
	    }
	    
	    public void setDiffer(String field) {
	    	_fieldName = field;
	    	_matchType = DIFFER;
	    }

	    
	    /** @since 3.0 */
	    public String getIdentityMessage()
	    {
	        return _identityMessage;
	    }

	    /**
	     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is the minimum length.
	     * Parameter {1} is the display name of the field.
	     * 
	     * @since 3.0
	     */

	    public void setMinimumLengthMessage(String string)
	    {
	        _identityMessage = string;
	    }

	    /** @since 3.0 */

	    protected String buildIdentityMessage(ValidationMessages messages, IFormComponent field, IFormComponent referent)
	    {
	        Object[] parameters = new Object[] {
	        		field.getDisplayName(), _matchType, referent.getDisplayName()
	        };
	    	return messages.formatValidationMessage(_identityMessage, 
	    			"invalid-field-equality", parameters);
	        
	    }
	    
	    private boolean notEqual(Object o1, Object o2) {
	    	if (o1 == null && o2 == null)
	    		return false;
	    	if (o1 == null  || o2 == null)
	    		return true;
	    	return !o1.equals(o2);
	    }

}


==============================

hivemind:

    <contribution configuration-id="tapestry.form.validator.Validators">
       <validator name="match" configurable="true" 
       class="org.apache.tapestry.form.valid.IdentityValidator"/>
    </contribution>

	<contribution configuration-id="tapestry.form.validator.Validators">
       <validator name="differ" configurable="true" 
       class="org.apache.tapestry.form.valid.IdentityValidator"/>
    </contribution>

=========================


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


[jira] Updated: (TAPESTRY-410) IdentityValidator

Posted by "Jesse Kuhnert (JIRA)" <ta...@jakarta.apache.org>.
     [ http://issues.apache.org/jira/browse/TAPESTRY-410?page=all ]

Jesse Kuhnert updated TAPESTRY-410:
-----------------------------------

    Fix Version/s: 4.1.2

> IdentityValidator
> -----------------
>
>                 Key: TAPESTRY-410
>                 URL: http://issues.apache.org/jira/browse/TAPESTRY-410
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.0
>            Reporter: Ron Piterman
>            Priority: Minor
>             Fix For: 4.1.2
>
>
> The following class compares the validated field against another field. It works in two modes: 
> match=<fieldname> and differ=<fieldname>
> Cheers,
> Ron
> package org.apache.tapestry.form.valid;
> import org.apache.tapestry.form.IFormComponent;
> import org.apache.tapestry.form.TextField;
> import org.apache.tapestry.form.ValidationMessages;
> import org.apache.tapestry.form.validator.BaseValidator;
> public class IdentityValidator extends BaseValidator {
> 	private String _fieldName;
> 	private int _matchType;
> 	private String _identityMessage;
> 	
> 	private static final int DIFFER = 0;
> 	private static final int MATCH = 1;
> 	
> 	
> 	public IdentityValidator() {
> 		super();
> 	}
>     public IdentityValidator(String initializer)
>     {
>         super(initializer);
>     }
>     public String toString(IFormComponent field, Object value)
> 	    {
> 	        if (value == null)
> 	            return null;
> 	        return value.toString();
> 	    }
> 	public void validate(IFormComponent field, ValidationMessages messages, Object object) 
> 		throws ValidatorException
> 	    {
> 	        TextField referent = 
> 	        	(TextField)field.getContainer().getComponent(_fieldName);
>                 //TODO: if component is null treat _fieldName as an ognl expression
> 	        
> 	        boolean notEq = notEqual ( referent.getValue() , object ); 
> 	        
> 	        if ( _matchType == MATCH ? notEq : !notEq )
> 	            throw new ValidatorException(buildIdentityMessage(messages, field, referent),
> 	                    ValidationConstraint.CONSISTENCY);
> 	    }
> 	    public String getMatch()
> 	    {
> 	        return _fieldName;
> 	    }
> 	    public void setMatch(String field)
> 	    {
> 	        _fieldName = field;
> 	        _matchType = MATCH;
> 	        
> 	    }
> 	    
> 	    public String getDiffer() {
> 	    	return _fieldName;
> 	    }
> 	    
> 	    public void setDiffer(String field) {
> 	    	_fieldName = field;
> 	    	_matchType = DIFFER;
> 	    }
> 	    
> 	    /** @since 3.0 */
> 	    public String getIdentityMessage()
> 	    {
> 	        return _identityMessage;
> 	    }
> 	    /**
> 	     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is the minimum length.
> 	     * Parameter {1} is the display name of the field.
> 	     * 
> 	     * @since 3.0
> 	     */
> 	    public void setMinimumLengthMessage(String string)
> 	    {
> 	        _identityMessage = string;
> 	    }
> 	    /** @since 3.0 */
> 	    protected String buildIdentityMessage(ValidationMessages messages, IFormComponent field, IFormComponent referent)
> 	    {
> 	        Object[] parameters = new Object[] {
> 	        		field.getDisplayName(), _matchType, referent.getDisplayName()
> 	        };
> 	    	return messages.formatValidationMessage(_identityMessage, 
> 	    			"invalid-field-equality", parameters);
> 	        
> 	    }
> 	    
> 	    private boolean notEqual(Object o1, Object o2) {
> 	    	if (o1 == null && o2 == null)
> 	    		return false;
> 	    	if (o1 == null  || o2 == null)
> 	    		return true;
> 	    	return !o1.equals(o2);
> 	    }
> }
> ==============================
> hivemind:
>     <contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="match" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> 	<contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="differ" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> =========================

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


[jira] Assigned: (TAPESTRY-410) IdentityValidator

Posted by "Andreas Andreou (JIRA)" <ta...@jakarta.apache.org>.
     [ http://issues.apache.org/jira/browse/TAPESTRY-410?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Andreou reassigned TAPESTRY-410:
----------------------------------------

    Assignee: Andreas Andreou

> IdentityValidator
> -----------------
>
>                 Key: TAPESTRY-410
>                 URL: http://issues.apache.org/jira/browse/TAPESTRY-410
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.0
>            Reporter: Ron Piterman
>         Assigned To: Andreas Andreou
>            Priority: Minor
>             Fix For: 4.1.2
>
>
> The following class compares the validated field against another field. It works in two modes: 
> match=<fieldname> and differ=<fieldname>
> Cheers,
> Ron
> package org.apache.tapestry.form.valid;
> import org.apache.tapestry.form.IFormComponent;
> import org.apache.tapestry.form.TextField;
> import org.apache.tapestry.form.ValidationMessages;
> import org.apache.tapestry.form.validator.BaseValidator;
> public class IdentityValidator extends BaseValidator {
> 	private String _fieldName;
> 	private int _matchType;
> 	private String _identityMessage;
> 	
> 	private static final int DIFFER = 0;
> 	private static final int MATCH = 1;
> 	
> 	
> 	public IdentityValidator() {
> 		super();
> 	}
>     public IdentityValidator(String initializer)
>     {
>         super(initializer);
>     }
>     public String toString(IFormComponent field, Object value)
> 	    {
> 	        if (value == null)
> 	            return null;
> 	        return value.toString();
> 	    }
> 	public void validate(IFormComponent field, ValidationMessages messages, Object object) 
> 		throws ValidatorException
> 	    {
> 	        TextField referent = 
> 	        	(TextField)field.getContainer().getComponent(_fieldName);
>                 //TODO: if component is null treat _fieldName as an ognl expression
> 	        
> 	        boolean notEq = notEqual ( referent.getValue() , object ); 
> 	        
> 	        if ( _matchType == MATCH ? notEq : !notEq )
> 	            throw new ValidatorException(buildIdentityMessage(messages, field, referent),
> 	                    ValidationConstraint.CONSISTENCY);
> 	    }
> 	    public String getMatch()
> 	    {
> 	        return _fieldName;
> 	    }
> 	    public void setMatch(String field)
> 	    {
> 	        _fieldName = field;
> 	        _matchType = MATCH;
> 	        
> 	    }
> 	    
> 	    public String getDiffer() {
> 	    	return _fieldName;
> 	    }
> 	    
> 	    public void setDiffer(String field) {
> 	    	_fieldName = field;
> 	    	_matchType = DIFFER;
> 	    }
> 	    
> 	    /** @since 3.0 */
> 	    public String getIdentityMessage()
> 	    {
> 	        return _identityMessage;
> 	    }
> 	    /**
> 	     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is the minimum length.
> 	     * Parameter {1} is the display name of the field.
> 	     * 
> 	     * @since 3.0
> 	     */
> 	    public void setMinimumLengthMessage(String string)
> 	    {
> 	        _identityMessage = string;
> 	    }
> 	    /** @since 3.0 */
> 	    protected String buildIdentityMessage(ValidationMessages messages, IFormComponent field, IFormComponent referent)
> 	    {
> 	        Object[] parameters = new Object[] {
> 	        		field.getDisplayName(), _matchType, referent.getDisplayName()
> 	        };
> 	    	return messages.formatValidationMessage(_identityMessage, 
> 	    			"invalid-field-equality", parameters);
> 	        
> 	    }
> 	    
> 	    private boolean notEqual(Object o1, Object o2) {
> 	    	if (o1 == null && o2 == null)
> 	    		return false;
> 	    	if (o1 == null  || o2 == null)
> 	    		return true;
> 	    	return !o1.equals(o2);
> 	    }
> }
> ==============================
> hivemind:
>     <contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="match" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> 	<contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="differ" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> =========================

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


[jira] Commented: (TAPESTRY-410) IdentityValidator

Posted by "Andreas Andreou (JIRA)" <ta...@jakarta.apache.org>.
    [ http://issues.apache.org/jira/browse/TAPESTRY-410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12461670 ] 

Andreas Andreou commented on TAPESTRY-410:
------------------------------------------

Ron, is it possible to attach the files in this issue, instead of copy-pasting them... I believe we have to do it this way so as not to have any licensing issues

> IdentityValidator
> -----------------
>
>                 Key: TAPESTRY-410
>                 URL: http://issues.apache.org/jira/browse/TAPESTRY-410
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.0
>            Reporter: Ron Piterman
>         Assigned To: Andreas Andreou
>            Priority: Minor
>             Fix For: 4.1.2
>
>
> The following class compares the validated field against another field. It works in two modes: 
> match=<fieldname> and differ=<fieldname>
> Cheers,
> Ron
> package org.apache.tapestry.form.valid;
> import org.apache.tapestry.form.IFormComponent;
> import org.apache.tapestry.form.TextField;
> import org.apache.tapestry.form.ValidationMessages;
> import org.apache.tapestry.form.validator.BaseValidator;
> public class IdentityValidator extends BaseValidator {
> 	private String _fieldName;
> 	private int _matchType;
> 	private String _identityMessage;
> 	
> 	private static final int DIFFER = 0;
> 	private static final int MATCH = 1;
> 	
> 	
> 	public IdentityValidator() {
> 		super();
> 	}
>     public IdentityValidator(String initializer)
>     {
>         super(initializer);
>     }
>     public String toString(IFormComponent field, Object value)
> 	    {
> 	        if (value == null)
> 	            return null;
> 	        return value.toString();
> 	    }
> 	public void validate(IFormComponent field, ValidationMessages messages, Object object) 
> 		throws ValidatorException
> 	    {
> 	        TextField referent = 
> 	        	(TextField)field.getContainer().getComponent(_fieldName);
>                 //TODO: if component is null treat _fieldName as an ognl expression
> 	        
> 	        boolean notEq = notEqual ( referent.getValue() , object ); 
> 	        
> 	        if ( _matchType == MATCH ? notEq : !notEq )
> 	            throw new ValidatorException(buildIdentityMessage(messages, field, referent),
> 	                    ValidationConstraint.CONSISTENCY);
> 	    }
> 	    public String getMatch()
> 	    {
> 	        return _fieldName;
> 	    }
> 	    public void setMatch(String field)
> 	    {
> 	        _fieldName = field;
> 	        _matchType = MATCH;
> 	        
> 	    }
> 	    
> 	    public String getDiffer() {
> 	    	return _fieldName;
> 	    }
> 	    
> 	    public void setDiffer(String field) {
> 	    	_fieldName = field;
> 	    	_matchType = DIFFER;
> 	    }
> 	    
> 	    /** @since 3.0 */
> 	    public String getIdentityMessage()
> 	    {
> 	        return _identityMessage;
> 	    }
> 	    /**
> 	     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is the minimum length.
> 	     * Parameter {1} is the display name of the field.
> 	     * 
> 	     * @since 3.0
> 	     */
> 	    public void setMinimumLengthMessage(String string)
> 	    {
> 	        _identityMessage = string;
> 	    }
> 	    /** @since 3.0 */
> 	    protected String buildIdentityMessage(ValidationMessages messages, IFormComponent field, IFormComponent referent)
> 	    {
> 	        Object[] parameters = new Object[] {
> 	        		field.getDisplayName(), _matchType, referent.getDisplayName()
> 	        };
> 	    	return messages.formatValidationMessage(_identityMessage, 
> 	    			"invalid-field-equality", parameters);
> 	        
> 	    }
> 	    
> 	    private boolean notEqual(Object o1, Object o2) {
> 	    	if (o1 == null && o2 == null)
> 	    		return false;
> 	    	if (o1 == null  || o2 == null)
> 	    		return true;
> 	    	return !o1.equals(o2);
> 	    }
> }
> ==============================
> hivemind:
>     <contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="match" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> 	<contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="differ" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> =========================

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


[jira] Resolved: (TAPESTRY-410) IdentityValidator

Posted by "Andreas Andreou (JIRA)" <de...@tapestry.apache.org>.
     [ https://issues.apache.org/jira/browse/TAPESTRY-410?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Andreou resolved TAPESTRY-410.
--------------------------------------

    Resolution: Fixed

> IdentityValidator
> -----------------
>
>                 Key: TAPESTRY-410
>                 URL: https://issues.apache.org/jira/browse/TAPESTRY-410
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.0
>            Reporter: Ron Piterman
>         Assigned To: Andreas Andreou
>            Priority: Minor
>             Fix For: 4.1.2
>
>
> The following class compares the validated field against another field. It works in two modes: 
> match=<fieldname> and differ=<fieldname>
> Cheers,
> Ron
> package org.apache.tapestry.form.valid;
> import org.apache.tapestry.form.IFormComponent;
> import org.apache.tapestry.form.TextField;
> import org.apache.tapestry.form.ValidationMessages;
> import org.apache.tapestry.form.validator.BaseValidator;
> public class IdentityValidator extends BaseValidator {
> 	private String _fieldName;
> 	private int _matchType;
> 	private String _identityMessage;
> 	
> 	private static final int DIFFER = 0;
> 	private static final int MATCH = 1;
> 	
> 	
> 	public IdentityValidator() {
> 		super();
> 	}
>     public IdentityValidator(String initializer)
>     {
>         super(initializer);
>     }
>     public String toString(IFormComponent field, Object value)
> 	    {
> 	        if (value == null)
> 	            return null;
> 	        return value.toString();
> 	    }
> 	public void validate(IFormComponent field, ValidationMessages messages, Object object) 
> 		throws ValidatorException
> 	    {
> 	        TextField referent = 
> 	        	(TextField)field.getContainer().getComponent(_fieldName);
>                 //TODO: if component is null treat _fieldName as an ognl expression
> 	        
> 	        boolean notEq = notEqual ( referent.getValue() , object ); 
> 	        
> 	        if ( _matchType == MATCH ? notEq : !notEq )
> 	            throw new ValidatorException(buildIdentityMessage(messages, field, referent),
> 	                    ValidationConstraint.CONSISTENCY);
> 	    }
> 	    public String getMatch()
> 	    {
> 	        return _fieldName;
> 	    }
> 	    public void setMatch(String field)
> 	    {
> 	        _fieldName = field;
> 	        _matchType = MATCH;
> 	        
> 	    }
> 	    
> 	    public String getDiffer() {
> 	    	return _fieldName;
> 	    }
> 	    
> 	    public void setDiffer(String field) {
> 	    	_fieldName = field;
> 	    	_matchType = DIFFER;
> 	    }
> 	    
> 	    /** @since 3.0 */
> 	    public String getIdentityMessage()
> 	    {
> 	        return _identityMessage;
> 	    }
> 	    /**
> 	     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is the minimum length.
> 	     * Parameter {1} is the display name of the field.
> 	     * 
> 	     * @since 3.0
> 	     */
> 	    public void setMinimumLengthMessage(String string)
> 	    {
> 	        _identityMessage = string;
> 	    }
> 	    /** @since 3.0 */
> 	    protected String buildIdentityMessage(ValidationMessages messages, IFormComponent field, IFormComponent referent)
> 	    {
> 	        Object[] parameters = new Object[] {
> 	        		field.getDisplayName(), _matchType, referent.getDisplayName()
> 	        };
> 	    	return messages.formatValidationMessage(_identityMessage, 
> 	    			"invalid-field-equality", parameters);
> 	        
> 	    }
> 	    
> 	    private boolean notEqual(Object o1, Object o2) {
> 	    	if (o1 == null && o2 == null)
> 	    		return false;
> 	    	if (o1 == null  || o2 == null)
> 	    		return true;
> 	    	return !o1.equals(o2);
> 	    }
> }
> ==============================
> hivemind:
>     <contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="match" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> 	<contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="differ" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> =========================

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


[jira] Commented: (TAPESTRY-410) IdentityValidator

Posted by "Andreas Andreou (JIRA)" <de...@tapestry.apache.org>.
    [ https://issues.apache.org/jira/browse/TAPESTRY-410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12481824 ] 

Andreas Andreou commented on TAPESTRY-410:
------------------------------------------

Almost finished... just the docs pending

> IdentityValidator
> -----------------
>
>                 Key: TAPESTRY-410
>                 URL: https://issues.apache.org/jira/browse/TAPESTRY-410
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.0
>            Reporter: Ron Piterman
>         Assigned To: Andreas Andreou
>            Priority: Minor
>             Fix For: 4.1.2
>
>
> The following class compares the validated field against another field. It works in two modes: 
> match=<fieldname> and differ=<fieldname>
> Cheers,
> Ron
> package org.apache.tapestry.form.valid;
> import org.apache.tapestry.form.IFormComponent;
> import org.apache.tapestry.form.TextField;
> import org.apache.tapestry.form.ValidationMessages;
> import org.apache.tapestry.form.validator.BaseValidator;
> public class IdentityValidator extends BaseValidator {
> 	private String _fieldName;
> 	private int _matchType;
> 	private String _identityMessage;
> 	
> 	private static final int DIFFER = 0;
> 	private static final int MATCH = 1;
> 	
> 	
> 	public IdentityValidator() {
> 		super();
> 	}
>     public IdentityValidator(String initializer)
>     {
>         super(initializer);
>     }
>     public String toString(IFormComponent field, Object value)
> 	    {
> 	        if (value == null)
> 	            return null;
> 	        return value.toString();
> 	    }
> 	public void validate(IFormComponent field, ValidationMessages messages, Object object) 
> 		throws ValidatorException
> 	    {
> 	        TextField referent = 
> 	        	(TextField)field.getContainer().getComponent(_fieldName);
>                 //TODO: if component is null treat _fieldName as an ognl expression
> 	        
> 	        boolean notEq = notEqual ( referent.getValue() , object ); 
> 	        
> 	        if ( _matchType == MATCH ? notEq : !notEq )
> 	            throw new ValidatorException(buildIdentityMessage(messages, field, referent),
> 	                    ValidationConstraint.CONSISTENCY);
> 	    }
> 	    public String getMatch()
> 	    {
> 	        return _fieldName;
> 	    }
> 	    public void setMatch(String field)
> 	    {
> 	        _fieldName = field;
> 	        _matchType = MATCH;
> 	        
> 	    }
> 	    
> 	    public String getDiffer() {
> 	    	return _fieldName;
> 	    }
> 	    
> 	    public void setDiffer(String field) {
> 	    	_fieldName = field;
> 	    	_matchType = DIFFER;
> 	    }
> 	    
> 	    /** @since 3.0 */
> 	    public String getIdentityMessage()
> 	    {
> 	        return _identityMessage;
> 	    }
> 	    /**
> 	     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is the minimum length.
> 	     * Parameter {1} is the display name of the field.
> 	     * 
> 	     * @since 3.0
> 	     */
> 	    public void setMinimumLengthMessage(String string)
> 	    {
> 	        _identityMessage = string;
> 	    }
> 	    /** @since 3.0 */
> 	    protected String buildIdentityMessage(ValidationMessages messages, IFormComponent field, IFormComponent referent)
> 	    {
> 	        Object[] parameters = new Object[] {
> 	        		field.getDisplayName(), _matchType, referent.getDisplayName()
> 	        };
> 	    	return messages.formatValidationMessage(_identityMessage, 
> 	    			"invalid-field-equality", parameters);
> 	        
> 	    }
> 	    
> 	    private boolean notEqual(Object o1, Object o2) {
> 	    	if (o1 == null && o2 == null)
> 	    		return false;
> 	    	if (o1 == null  || o2 == null)
> 	    		return true;
> 	    	return !o1.equals(o2);
> 	    }
> }
> ==============================
> hivemind:
>     <contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="match" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> 	<contribution configuration-id="tapestry.form.validator.Validators">
>        <validator name="differ" configurable="true" 
>        class="org.apache.tapestry.form.valid.IdentityValidator"/>
>     </contribution>
> =========================

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org