0

Handling POST Content-Length (PHP) Warning

I got problem when the file upload make the POST size exceed post_max_size setting.
I had disable the error report but the warning kept appearing.
Finally I found a solution.

In my case, I disabled all the PHP warning message using .htaccess.
To disable all errors from .htaccess use :
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
From http://ca2.php.net/manual/en/ini.core.php#ini.post-max-size
If the size of post data is greater than post_max_size, 
the $_POST and $_FILES superglobals are empty. 
This can be tracked in various ways, e.g. by passing
the $_GET variable to the script processing the data,
i.e. , and then checking if $_GET['processed'] is 
set.


Here is the example to handle it in PHP:
if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
  return $this->returnErrorMessage("File size exceed limit !!!");
}

Source : 
1. http://stackoverflow.com/questions/12872515/php-warning-demolishes-json-response
2.http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size
0

Multi Form Button Binding

I have to break the form into 2 columns that need to use a separate form panels.
But FormButtonBinding not support more than 1 form panels. So I decided to write a new one based on GXT FormButtonBinding

package com.vcari.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.google.gwt.user.client.Timer;

/**
 * Monitors the valid state of a form and enabled / disabled all buttons.
 */
public class MultiFormButtonBinding {

  // private FormPanel panel;
  private List<FormPanel> panels = new ArrayList<FormPanel>();
  private Timer timer;
  private int interval = 500;
  private Listener<ComponentEvent> listener;
  private List<Button> buttons;

  public MultiFormButtonBinding(List<FormPanel> panels) {
    this.panels = panels;

    buttons = new ArrayList<Button>();
    timer = new Timer() {
      @Override
      public void run() {
        MultiFormButtonBinding.this.checkPanel();
      }
    };
    listener = new Listener<ComponentEvent>() {
      public void handleEvent(ComponentEvent be) {
        if (be.getType() == Events.Attach) {
          MultiFormButtonBinding.this.startMonitoring();
        } else if (be.getType() == Events.Detach) {
          MultiFormButtonBinding.this.stopMonitoring();
        }
      }
    };

    for (FormPanel formPanel : panels) {
      formPanel.addListener(Events.Attach, listener);
      formPanel.addListener(Events.Detach, listener);
      if (formPanel.isAttached()) {
        startMonitoring();
      }
    }

    // panel.addListener(Events.Attach, listener);
    // panel.addListener(Events.Detach, listener);

  }

  public void addButton(Button button) {
    buttons.add(button);
  }

  public int getInterval() {
    return interval;
  }

  public void removeButton(Button button) {
    buttons.remove(button);
  }

  public void setInterval(int interval) {
    this.interval = interval;
  }

  public void startMonitoring() {
    for (FormPanel formPanel : panels) {
      if (formPanel.isAttached()) {
        timer.run();
        timer.scheduleRepeating(interval);
        break;
      }      
    }    
  }

  public void stopMonitoring() {
    timer.cancel();
  }

  protected boolean checkPanel() {
    boolean v=true;
    for (FormPanel formPanel : panels) {
      boolean v1 = formPanel.isValid(true);
      v=v && v1;
      
    }  
    
    for (Button button : buttons) {
      if (v != button.isEnabled()) {
        button.setEnabled(v);
      }
    }
    return v;
  }

}

Example :

List<FormPanel> panels=new ArrayList<FormPanel>();
panels.add(form);
panels.add(form2);
MultiFormButtonBinding buttonBinding=new MultiFormButtonBinding(panels);
buttonBinding.addButton(btnSubmit);
0

GXT Form AutoFocus

I have a login form and want it focus on the username textfield when it loads.
The solution is very simple, just need to set an event (onFocus) for the container.


 addListener(Events.OnFocus, new Listener<ComponentEvent>() {
    public void handleEvent(ComponentEvent e) {
        txtFldUsername.focus();
    }
});


Source : http://code.google.com/p/topcat/source/browse/trunk/Code/TopCAT/src/main/java/uk/ac/stfc/topcat/gwt/client/widget/LoginWidget.java?r=74
0

GWT/GXT UTF-8

One of my project require to use Thai character (UTF-8).
The solution is very simple. In order to use internationalized characters, make sure that the host HTML file contains the charset=utf8 content type in the meta tag in the header:

<meta http-equiv="content-type" content="text/html;charset=utf-8" />


Source : https://developers.google.com/web-toolkit/doc/latest/DevGuideI18n#DevGuideStaticStringInternationalization
0

GXT Grid Column Word Wrap

I would like to apply word wrap to a single column.
Just need to set a custom renderer.  
 
cm.getColumnById("proddesc").setRenderer(new GridCellRenderer<ModelData>() {
  @Override
  public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
    return "<div style=\"white-space:normal !important;\">"+ model.get(property) +"</div>";
  }
});
Source : http://stackoverflow.com/questions/2106104/word-wrap-grid-cells-in-ext-js
 
Copyright © peyotest