You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Th...@ppimedia.de on 2006/11/16 14:10:04 UTC

Tapestry 4.1.1 Back/Foward Button Problem

 Hi all,

 I'm working with the snapshot of Tapestry 4.1.1 and try to support the
back/forward 
 browser button. My page contains a 'filter' form, that a Submit 
 Button component submits...

 .html:

 <form jwcid="FilterForm">

   ... many components ...

   <span jwcid="@Submit" async="ognl:true" 
     updateComponents="ognl:{'filterArea','overviewContent'}" 
     value="message:common.action.apply"></span>
 </form>

 .jwc:

 <component id="FilterForm" type="Form">
   <binding name="async" value="ognl:true" />
   <binding name="delegate" value="beans.delegate" />
   <binding name="listener" value="listener:evaluateFilter" />
 </component>

 generated browser html source:

 ...
 
 dojo.addOnLoad(function(e) {

 ...

 tapestry.cleanConnect(dojo.byId("Submit"), "onclick", "event178957379");
 tapestry.event178957379=function(e){
   dojo.event.browser.stopEvent(e);
   tapestry.form.submit("FilterForm", "Submit", 
 
"async":true,"json":false,"url":"/ajax-test/Overview,FilterForm.sdirect?
     updateParts=filterArea&updateParts=overviewContent"});           
 };
 dojo.event.connect(dojo.byId("Submit"), "onclick", tapestry,
"event178957379");
 
 ...

 Okay thats the source ... my problem is, if the user changes the form (a
filter) 
 attributes (maybe: first name is 'peter' then 'paul' ... ) and clicks the
submit button, 
 then the result area updates with the correct result. 
 But if he clicks the browser back/forward button ... the previous/next 
 form state is broken. The first name attribute is wrong ... 
 Hmm therefore i overwrite the tapestry.form.submitAsync method like this:

 tapestry.form.submitAsync = function( form, content, submitName, parms )
 {
  dojo.log.debug("Binding Form Ajax-request...");
  var form = dojo.byId( form );
  if( !form )  
  {
    dojo.raise("Form not found with id " + id );
    return;
  }
  var formId = form.getAttribute("id");
  if( !tapestry.form.validation.validateForm( form, this.forms[ formId ] ) )

  {
    dojo.log.debug("Form validation failed for form with id " + formId );
    return;
  }
  if( submitName )
  {
    form.submitname.value = submitName;
    if( !content )
    {
	 content={}; 
    }
    if( form[ submitName ] )
    {
	 content[ submitName ] = form[ submitName ].value;
    }
  }
  // handle submissions from input buttons
  if( !dj_undef("clickedButton", this.forms[ formId ] ) ) 
  {
    if( !content ) 
    { 
      content = {}; 	  
    }
    content[ this.forms[ formId ].clickedButton.getAttribute("name") ] = 
      this.forms[ formId ].clickedButton.getAttribute("value");
  }
  var kwArgs = 
  {
    formNode: form,
    useCache: true,
    content: content,
    encoding: "UTF-8",
    error: ( function() { tapestry.error.apply( this, arguments ); } )
  };
  // check for override
  if( parms )
  {
	if( !dj_undef("url", parms ) ) 
	{ 
	  kwArgs.url = parms.url;
	}
  }
  if( this.forms[ formId ].json || parms && parms.json )
  {
    kwArgs.mimetype = "text/json";
    kwArgs.headers = { "json":true };
  } 
  else 
  {
    kwArgs.mimetype = "text/xml";
    kwArgs.headers = { "dojo-ajax-request":true };
    kwArgs.load = ( function() { tapestry.load.apply( this, arguments ); }
);
  }
	
  dojo.log.debug("##### creating history entry...");
  var state = 
  {
    back: function() 
    {
	 dojo.log.debug("##### back-button clicked..."); 
	 self.tapestry.form.submitAsync( form, content, submitName, parms );

    },
    forward: function() 
    { 
      dojo.log.debug("##### forward-button clicked...");
	 self.tapestry.form.submitAsync( form, content, submitName, parms );
    }
  }; 
  dojo.undo.browser.addToHistory( state );
  dojo.io.queueBind( kwArgs );
  dojo.log.debug("Binding Form Ajax-request finished...");

 Questions:

 1. Every Klick creates a history entry in the browser, but the back()
function is not called 
    correctly (missing the debug statement after the first form commit) Why?
 2. Why is the form state with all form elements incorrect?
 3. What my problem implemeting the back/foward button thing?

 Sorry for my bad english, hope that anybody knows what i mean?

 Best regards,

 Thomas
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org