Tapestry数据校验-修改Body.java和Body.js

1,Body.java:
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
        TapestryUtils.storePageRenderSupport(cycle, this);

        this.addExternalScript(TapestryUtil.getResource(
          "/com/web/tapestry/html/Body.js",cycle));

        IMarkupWriter nested = writer.getNestedWriter();

        renderBody(nested, cycle);

        // Start the body tag.
        writer.println();
        writer.begin(getElement());
        renderInformalParameters(writer, cycle);

        writer.println();

        // Write the page's scripting. This is included scripts
        // and dynamic javascript.

        _pageRenderSupport.writeBodyScript(writer, cycle);

        // Close the nested writer, which dumps its buffered content
        // into its parent.

        nested.close();

        // Any initialization should go at the very end of the document
        // just before the close body tag. Older version of Tapestry
        // would create a window.onload event handler, but this is better
        // (it doesn't have to wait for external images to load).
        // add init script code
        XtradeBasePage page = (XtradeBasePage) this.getPage();
        if (page.getDefaultSubmit() != null)           _pageRenderSupport.addInitializationScript(  Script.getDefaultSubmitScript(page.getDefaultSubmit()));


        _pageRenderSupport.writeInitializationScript(writer);

        writer.end(); // <body>
    }

2,Body.js:
var TapestryEx = new Object();

TapestryEx.set_focus = function (field)
{
    if (typeof field == "string")
      field = this.find(field);
    
    if (field.focus)
        field.focus();
    
    if (field.select)
        field.select();
}

TapestryEx.default_invalid_field_handler = function(event, field, message)
{
  if (!event.abort && !field.disabled)
  {
    TapestryEx.set_focus(field);
    
    window.alert(message);
    
    event.abort = true;
    event.cancel_handlers = true;
  }
}

TapestryEx.find = function(elementId)
{
  return document.getElementById(elementId);
}

TapestryEx.register_button = function(buttonId)
{
  var button = this.find(buttonId);  
  if(!button.events)
    button.events = new ButtonEventManager(button);
 
}

TapestryEx.onclick  = function(buttonId, handler)
{
  TapestryEx.register_button(buttonId);
  var button = this.find(buttonId);  
  button.events.add_click_handler(handler);
 
}

// ButtonClickEvent
function ButtonClickEvent(button,type,invalid_field_handler)
{
  this.button = button;
  this.type = type;
  this.invalid_field_handler = invalid_field_handler;
}

ButtonClickEvent.prototype.invalid_field = function(field, message)
{
  this.invalid_field_handler.call(window, this, field, message);
}

// ButtonEventManager
function ButtonEventManager(button)
{
  this.button = button;     
  this.handlers = {};  
  button.onclick = function() { return this.events.onclick_handler(); };
  this.invalid_field_handler = TapestryEx.default_invalid_field_handler;
}

// add_handler(type, handler)
ButtonEventManager.prototype.add_handler = function(type, handler)
{
  var array = this.handlers[type];
  if (array == null)
  {
    array = [];
    this.handlers[type] = array;
  }
  array[array.length]=handler;
}

// invoke_handlers(type, eventObject)
ButtonEventManager.prototype.invoke_handlers = function(type, eventObj)
{  
  var array = this.handlers[type];   
  if (array == null) return;  
  var length = array.length;
  for (var i = 0; i < length; i++)
  {
    var handler = array[i];
    handler.call(window, eventObj);
  }
}

// click()
ButtonEventManager.prototype.click = function(name)
{
    if (this.onclick_handler())
    {
      this.button.onclick = null;
    }
}

// onclick_handler()
ButtonEventManager.prototype.onclick_handler = function()
{
    var event = new ButtonClickEvent(this.button, "click",this.invalid_field_handler);

    this.invoke_handlers("click", event);
    
    if (event.abort)
      return false;

    return true;
}

// add_click_handler(handler)
ButtonEventManager.prototype.add_click_handler = function(handler)
{
  this.add_handler("click", handler);
}

function defaultSubmit(evt,submitName){
  if(evt == null){
     evt = window.event;
     browser="IE";
     srcElement=evt.srcElement;
  }
  else{
     browser="FF";
     srcElement=evt.target;
  }
  if(evt.which && evt.which == 13 || evt.keyCode && evt.keyCode==13){
      var form = document.forms[0];
      if(form != null){
        if(srcElement.type!='submit'&&srcElement.type!='image')
          if(browser == "IE")
              evt.returnValue=false;         
          else if(browser == "FF")
            evt.preventDefault();
          if(document.getElementById(submitName)){
               document.getElementById(submitName).click();
          }
          else
            return document.forms[0].submit();
      }
    }
}

function addEventListener(obj,eventName,eventHandler){
    if(eval(obj+".addEventListener")){
          eval(obj+".addEventListener('"+eventName+"',"+eventHandler+",false);");
    }
    else if(eval(obj+".attachEvent")){
        eval(obj+".attachEvent('on"+eventName+"',"+eventHandler+");");
    }
    else if(eval(obj+".on"+eventName)){
          eval(obj+".on"+eventName+"="+eventHandler);
    }  
}
 

你可能感兴趣的:(function,null,tapestry,button,browser,nested)