title: How can I validate a field as required depending on another field's value in SEAM?
body: <p>I'm trying to create a simple custom validator for my project, and I can't seem to find a way of getting seam to validate things conditionally.</p>
  
  <p>Here's what I've got:</p>
  
  <p>A helper/backing bean (that is NOT an entity)</p>
  
  <pre><code>@RequiredIfSelected
  public class AdSiteHelper {
    private Date start;
    private Date end;
    private boolean selected;
    /* getters and setters implied */
  }
  </code></pre>
  
  <p>What I need is for "start" and "end" to be required if and only if selected is true.</p>
  
  <p>I tried creating a custom validator at the TYPE target, but seam doesn't seem to want to pick it up and validate it. (Maybe because it's not an entity?)</p>
  
  <p>here's the general idea of my custom annotation for starters:</p>
  
  <pre><code>@ValidatorClass(RequiredIfSelectedValidator.class)
  @Target(ElementType.TYPE)
  @Retention(RetentionPolicy.RUNTIME)
  public @interface RequiredIfSelected {
      String message();
  }
  
  public class RequiredIfSelectedValidator implements Validator&lt;RequiredIfSelected&gt;, Serializable {
    public boolean isValid(Object value) {
      AdSiteHelper ash = (AdSiteHelper) value;
      return !ash.isSelected() || (ash.getStart() &amp;&amp; ash.getEnd());
    }
    public void initialize(RequiredIfSelected parameters) { }
  }
  </code></pre>