On 18 août, 18:40, davis <[email protected]> wrote:
> I'm trying to implement a version of MVP as discussed at Google I/O
> talk:
>
> http://code.google.com/events/io/sessions/GoogleWebToolkitBestPractic...
>
> So, one can have a presenter class that defines an internal interface,
> and I see it typically done like this:
>
> class PhoneEditor {
> interface Display {
> HasClickHandlers getSaveButton();
> ...
> }
>
> It seems to me that this tends to get a bit unwieldly in practice.
> For example, I have an account registration page. Let's say it
> contains a TextBox for username and a PasswordTextBox for password.
>
> Here are some things I'd like to do to that box in my presenter:
>
> get the value, so I could have
>
> interface Display {
> HasValue<String> getUsername();
> HasValue<String> getPassword();
> }
>
> But I also have validation code in my presenter, which will validate
> the content of the fields, and do things like set style errors.
>
> #addStyleName( ) is defined on UIObject, so I'm kinda out of luck with
> that interface unless I define something like:
>
> interface Display {
> HasValue<String> getUsername();
> HasValue<String> getPassword();
> UIObject getUsernameBox();
> UIObject getPasswordBox();
> }
>
> but that is kind of a ridiculous and redundant interface. So, really,
> my question is what is so wrong with:
>
> interface Display {
> TextBoxBase getUsernameBox();
> TextBoxBase getPasswordBox();
> }
>
> I get the fact that if you can use the Has* interfaces, it helps
> decouple the presenter from the view more by allowing the view to
> change to other UI widgets later on, but I find it far too limiting in
> being able to manipulate the view objects without either having large,
> redundant interfaces or else doing lots of unsafe casting.
>
> Has anyone else encountered this conundrum, and how are they
> approaching it? I'm inclined to make my Display interfaces explicit.
Your presenter shouldn't deal with "styles", it should instead tell
the view to show error near/on the "username" and/or password (or
nowhere particularly). It's the responsibility of the view to
determine (be implemented that way) if it should set a red background
and/or red border on the textbox, and/or show an icon next to the box,
and/or show an "error summary" above or below the boxes, etc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---