Hey all,

I've read some articles on MVP pattern, and at the first glance I
thought
that am understanding it, but now am very confused  about the term
VIEW IS PASSIVE. By that I understand that events are handled in the
presenter (it's too simple to separate and it's also obvious).

But what causes me headaches, is some logics like the code below. In
my application I would like to be as close as I can to the techniques
and aspects described in (Google I/O 2009 - Google Web Toolkit
Architecture: Best Practices For Architecting Your GWT App Ray Ryan
http://www.youtube.com/watch?v=PDuhR18-EdM )

In my app I get a simple logic to implement, here is a specification:

The user wants to create an html document, for that he must chose a
template to use. This template is divided to blocks ex: (image, text,
list OR list, text, image OR ...), this list (blocks) is provided by
the server and each block contains a value to set before he'll get
back to the server. Also each block could be mandatory.

************ Presenter ************

//...

List<BlockModel> blocks = null;
//Each block must get a reference to its value handler (for quick
access)
Map<BlockModel, HasValue> values = new HasMap<BlockModel, HasValue>();

public interface Display extends WidgetPresenter.Display{

        //
        //HasValue contains only one methode
        //String getValue()
        //
        public HasValue addTextBlock(String text);
        public HasValue addListBlock(Map<String, String> listItems, boolean
isMandatory);
        public HasValue addImageBlock(String url, String anonymousUrl);

        //the click on this button sets the new values in the blocks
        public HasClickHandler getValidationButton();
}

protected void onBind(){

        blocks = serviceImpl.getBlocks();
        HasValue valeuHandler = null;

        for(BlockModel block:blocks){
                if(block.getType().equals("text"))
                        valeuHandler = display.addTextBlock(block.getText());
                else if(block.getType().equals("image"))
                        valeuHandler =  display.addImageBlock(block.getUrl());
                else if(block.getType().equals("list"))
                        valeuHandler =  
display.addListBlock(block.getListValue());

                values.put(block, valeuHandler);
        }

        display.getValidationButton().addClickHandler( new ClickHandler(){

                public void onClick(ClickEvent event){
                        for(BlockModel block:blocks){

                                HasValue value  = values.get(block);
                                block.setValue(value.getValue());

                                //send it to the server
                                //...
                        }
                }
        });
}

//
//...


**************************** View **********************

//
//...

@Override
public HasValue addListBlock(Map<String, String> data, boolean
isMandatory){
        ListBox list = new ListBox()

        if(!isMandatory){
                list.addItem("choose ...", "-1");
        }

        for(Map.Entry<String, String> entry:data.entrySet()){
                list.addItem(entry.getValue(), entry.getKey());
        }

        container.add(list);

        return new HasValue(){
                String value = list.getValue(list.getSelectedIndex());
                //# START
                return value.equals("-1") ? null : value;
                //# END
        };
}

// this should be enough to show you what's could be wrong
//.............



IS THE LINE ENCLOSED BY //# IN THE VIEW BREAKS THE MVP PATTERN ??
THE VIEW IS NO LONGER PASSIVE ?
or it should be moved to the presenter and we return the raw value
from the view !!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to