Frederic Daoud wrote:
Hi Eddy,

Thanks for your response.. a response from "Mr. Component" himself :-)

Unless re-used a lot, components are not worth the effort, IMHO.

I like the approach, although I personally prefer template decorators.

You've got my curiosity; what do you mean by template decorator?
Could you explain or point me to a document?

It is simply applying the Decorator design pattern to templates. See example.

Note: I can be anal about coding conventions sometimes, so I pass a bean to setBean() instead of any object.

Eddy
--
http://coding.mu
http://priscimon.com/blog
public class ListBean {
        private List elements;
        
        public List getElements() {
                return elements;
        }
        
        public void setElements(List elements) {
                this.elements = elements;
        }
}

public class ListTasks extends Element {
        private TasksListTemplate template;
        
        public void initialize() {
                // let's decorate our original template
                template = new 
TasksListTemplate(getHtmlTemplate("tasks.list")); 
        }
        
        public void processElement() {
                List tasks = ...; // get tasks from DB
                
                ListBean bean = new ListBean();
                bean.setElements(tasks);
                
                template.setBean(bean);
                print(template);
        }
        
        private static final class TasksListTemplate extends AbstractTemplate {
                private Template template;
                
                public TasksListTemplate(Template template) {
                        this.template = template;
                }
                
                
                public void setBean(Object bean) {
                        template.setBean(bean);
                        
                        List elements = ((ListBean) bean).getElements();
                        
                        for (Iterator i = 0; i < elements.iterator(); 
i.hasNext();) {
                                Task task = (Task) i.next();
                                template.setValue("title", task.getTitle());
                                template.setValue("description", 
task.getDescription());
                                template.setValue("dueDate", task.getDueDate());
                                
                                template.appendBlock("tasks-rows", "tasks-row");
                        }
                }
                
                // implement other abstract methods here
        }
}
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to