Announcement Announcement Module
Collapse
No announcement yet.
Creating dynamic validators with XML config files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating dynamic validators with XML config files

    Hey all,

    I am working on a "trouble ticket" project which will store the physical location of a computer by its Row and Seat number. What constitutes a valid entry would depend on how the physical location is set up in the office. This will obviously change over time, so I would like to read the valid Row and Seat settings, which I will use in the validation logic, from an XML config file.
    My current validator code for this method is as follows:

    Code:
    public void validateLocation(Computer computer, Errors errors){
            int max_row = 30;
            int max_seat = 10;
            int row = computer.getRow();
            int seat = computer.getSeat();
            if(row>max_row)
                errors.rejectValue("row", "INVALID_ROW", "Row number is too high.");
            if(seat>max_seat)
                errors.rejectValue("seat", "INVALID_SEAT", "Seat number is too high.");
        }
    How could I modify my approach to read in max_row and max_seat from an XML file and do so in the context of the Spring Framework architecture?

    Thanks,
    James Winans II

  • #2
    why don't you just set them as bean properties on your Validator object? (assuming your validator is defined in a Spring context file)?
    Code:
    <bean id="myVal" class="com.foo.SomeValidator">
      <property name="maxRows"><value>30</value></property>
      ... other props ...
    </bean>
    and specify the setters in your validator class.

    Regards[/code]

    Comment


    • #3
      Hey Davison,

      Thanks, this makes perfect sense. I'm new to the Java and Spring combo, so I wasn't sure of Springs best practice for this. I guess a validator is just a bean after all.

      Thanks,
      James

      Comment

      Working...
      X