cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel Form.java
Date Tue, 13 Apr 2004 21:29:48 GMT
sylvain     2004/04/13 14:29:48

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        Form.java
  Log:
  Ensure events are always handled, even if before or after processing
  
  Revision  Changes    Path
  1.7       +29 -9     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java
  
  Index: Form.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Form.java	9 Apr 2004 16:43:21 -0000	1.6
  +++ Form.java	13 Apr 2004 21:29:48 -0000	1.7
  @@ -47,13 +47,17 @@
       
       private Boolean endProcessing;
       private Locale locale = Locale.getDefault();
  -    private CursorableLinkedList events;
       private FormHandler formHandler;
       private Widget submitWidget;
       private ProcessingPhase phase = ProcessingPhase.LOAD_MODEL;
       private boolean isValid = false;
       private ProcessingPhaseListener listener;
   
  +    //In the "readFromRequest" phase, events are buffered to ensure that all widgets had
the chance
  +    //to read their value before events get fired.
  +    private boolean bufferEvents = false;
  +    private CursorableLinkedList events;
  +
       public Form(FormDefinition definition) {
           this.definition = definition;
       }
  @@ -70,12 +74,17 @@
        */
       public void addWidgetEvent(WidgetEvent event) {
           
  -        if (this.events == null) {
  -            this.events = new CursorableLinkedList();
  +        if (this.bufferEvents) {
  +            if (this.events == null) {
  +                this.events = new CursorableLinkedList();
  +            }
  +            
  +            // FIXME: limit the number of events to detect recursive event loops ?
  +            this.events.add(event);
  +        } else {
  +            // Send it right now
  +            event.getSourceWidget().broadcastEvent(event);
           }
  -        
  -        // FIXME: limit the number of events to detect recursive event loops ?
  -        this.events.add(event);
       }
       
       /**
  @@ -213,8 +222,19 @@
               setSubmitWidget(submit);
           }
           
  -        doReadFromRequest(formContext);
  -        fireWidgetEvents();
  +        try {
  +            // Start buffering events
  +            this.bufferEvents = true;
  +            
  +            doReadFromRequest(formContext);
  +            
  +            // Fire events, still buffering them: this ensures they will be handled in
the same
  +            // order as they were added.
  +            fireWidgetEvents();
  +        } finally {
  +            // No need for buffering in the following phases
  +            this.bufferEvents = false;
  +        }
           
           // Notify the end of the current phase
           if (this.listener != null) {
  
  
  

Mime
View raw message