Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I want to validate the details provided by the user before taking them into the processing. My UIs have Text boxes, Combos mainly and, there are some fields that user must provide a data, in some fields only certain type of data may be accepted like texts, Dates/times, numbers etc. When it comes to date/ time we should check whether the provided data is in the valid range.

My question are

Q1. Where to do validation in MVP pattern?

My options are

  1. Implement validation as a service available to Presenters. (Through DI for ex.)
  2. Do the validation in the UI itself in a event like KeyPress.
  3. Presenter itself handles the validation.

Q2. How to do the validation.

My options are

i. All controllers like text boxes in the View are encapsulated in properties (Getters / Setters)

public string Age
{
    get { return txtAge.Text; }
    set { txtAge.Text = value; }
}

ii. UI fires the event Validate(sender, e)

iii. Presenter listen and hook it up to the handler which then invokes Validate() method

iv. In Validate() method it'll detect the controller raised the event (sender) and read the corresponding property to get the value in the controller.

v. Then it will check the type against the type in the model and decide the validity and then alert the user

The problem here is that I may have to expose all controllers through string properties as other wise it will give exceptions when the user enters an invalid type.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.