Mostrando entradas con la etiqueta gwt. Mostrar todas las entradas
Mostrando entradas con la etiqueta gwt. Mostrar todas las entradas

Download file with GWT

Esta es una manera fácil de enviar desde GWT archivos al navegador para que los usuarios se los puedan descargar.

1. Hay que agregar un frame oculto en el HTML de la hosted page:
<div id="__gwt_downloadFrame" tabIndex='-1'></div>

2. Para iniciar la descarga poner este código en la parte cliente (código GWT):
public static void download(String p_uuid, String p_filename) { 
        String fileDownloadURL = "/fileDownloadServlet" 
                               + "?id=" + p_uuid 
                               + "&filename=" + 
URL.encode(p_filename); 
        Frame fileDownloadFrame = new Frame(fileDownloadURL); 
        fileDownloadFrame.setSize("0px", "0px"); 
        fileDownloadFrame.setVisible(false); 
        RootPanel panel = RootPanel.get("__gwt_downloadFrame"); 
        while (panel.getWidgetCount() > 0) 
            panel.remove(0); 
        panel.add(fileDownloadFrame); 
} 

3. Poner esto en el servlet que va a servir el archivo a descargar:
@Override 
protected void doGet(HttpServletRequest p_request, 
                         HttpServletResponse p_response) 
        throws ServletException, IOException { 
        String filename = p_request.getParameter("filename"); 
        if (filename == null) 
        { 
            p_response.sendError(SC_BAD_REQUEST, "Missing filename"); 
            return; 
        } 

        File file = /* however you choose to go about resolving 
filename */ 

        long length = file.length(); 
        FileInputStream fis = new FileInputStream(file); 
        p_response.addHeader("Content-Disposition", 
                             "attachment; filename=\"" + filename + 
"\""); 
        p_response.setContentType("application/octet-stream"); 
        if (length > 0 && length <= Integer.MAX_VALUE); 
            p_response.setContentLength((int)length); 
        ServletOutputStream out = p_response.getOutputStream(); 
        p_response.setBufferSize(32768); 
        int bufSize = p_response.getBufferSize(); 
        byte[] buffer = new byte[bufSize]; 
        BufferedInputStream bis = new BufferedInputStream(fis, 
bufSize); 
        int bytes; 
        while ((bytes = bis.read(buffer, 0, bufSize)) >= 0) 
            out.write(buffer, 0, bytes); 
        bis.close(); 
        fis.close(); 
        out.flush(); 
        out.close(); 
} 


GWT Hosted mode compilation no es compatible con Java 1.5

En un proyecto que estamos haciendo con GWT, en el cual tenemos que usar el Hosted Mode de GWT, pero sin Appengine estaba explotando la primera vez que se compilaba una jsp.

La solución la encontramos acá y básicamente hay que crear una clase que extienda de JDTCompiler y agregarla como argumento de la VM en la Run Configuration.

Entonces, primero hay que crear la siguiente clase:


public class JDTCompiler15 extends JDTCompilerAdapter {
       @Override
       public void setJavac(Javac attributes) {
               if (attributes.getTarget() == null) {
                       attributes.setTarget("1.5");
               }
               if (attributes.getSource() == null) {
                       attributes.setSource("1.5");
               }
               super.setJavac(attributes);
       }
}

Y luego hay que hacer click derecho sobre el proyecto > Run As > Run Configurations > seleccionar una de ellas y en VM arguments agregar lo siguiente:


-Dbuild.compiler="com.mypackage.JDTCompiler15"

GWT Celltable ContextMenu in a Column

// create your column class
private class ContextMenuColumn extends Column<UserModel, String>{

  public ContextMenuColumn(Cell<String> cell) {
   super(cell);
  }

  @Override
  public String getValue(UserModel object) {
   return "/img/icons/contextual-menu.jpg";
  }
  
  @Override
  public void onBrowserEvent(Context context, Element elem, UserModel object, NativeEvent event) {
   final UserModel user = object;
   
   int left = elem.getParentElement().getAbsoluteLeft();
      int top = elem.getParentElement().getAbsoluteTop();
      
      final DialogBox dialog = new DialogBox();
      dialog.setText(constants.Actions());
      
      Anchor lnkEdit = new Anchor(constants.Edit());
      lnkEdit.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     placeController.goTo(new ControlPanelUsersEditPlace(user.getUserId()));
     dialog.hide();
    }
   });
      
      Anchor lnkUpdateState = new Anchor(user.getEnable() == false ? constants.Enable() : constants.Disable());
      lnkUpdateState.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     presenter.setEnabled(user.getUserId(), !user.getEnable());
     dialog.hide();
    }
   });
      
      Anchor lnkResetPassword = new Anchor(constants.ChangePassword());
      lnkResetPassword.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     presenter.resetPassword(user.getUserId());
     dialog.hide();
    }
   });
      
      Anchor lnkDelete = new Anchor(constants.Delete());
      lnkDelete.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     presenter.delete(user.getUserId());
     dialog.hide();
    }
   });
      
      VerticalPanel pnl = new VerticalPanel();
      pnl.add(lnkEdit);
      pnl.add(lnkUpdateState);
      pnl.add(lnkResetPassword);
      pnl.add(lnkDelete);
      
      dialog.setWidget(pnl);
      dialog.setPopupPosition(left - 20, top + 10);
      dialog.setAutoHideEnabled(true);
      dialog.show();
  }
 }

// create your column and add it to your table
Column<UserModel, String> contextMenuColumn = new ContextMenuColumn(new MyImageCell());

table.addColumn(contextMenuColumn);

GWT Celltable add a Row Handler

Handler<UserModel> rowHandler = new Handler<UserModel>() {
@Override
public void onCellPreview(CellPreviewEvent<UserModel> event) {
if (event.getColumn() != 0 && event.getNativeEvent().getType().equals("click")) {
placeController.goTo(new CompanyUsersEditPlace(event.getValue().getUserId(), user.getCompanyId()));
}
}
};

table.addCellPreviewHandler(rowHandler);

GWT Celltable and Checkbox Column

// you need a selection model
private final MultiSelectionModel<usermodel> selectionModel = new MultiSelectionModel<usermodel>(operatorKeyProvider);

// you need a selection manager
private final DefaultSelectionEventManager<usermodel> selectionManager = DefaultSelectionEventManager.createCheckboxManager();

// you need the table ;)
@UiField CellTable<usermodel> table;

// then ...
selectionModel.addSelectionChangeHandler(
new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
StringBuilder sb = new StringBuilder();
boolean first = true;
List&lt;UserModel&gt; selected = new ArrayList&lt;UserModel&gt;(selectionModel.getSelectedSet());

Collections.sort(selected);
for (UserModel value : selected) {
if (first) {
first = false;
} else {
sb.append(&quot;, &quot;);
}
sb.append(value.getFirstName());
}
}
});

table.setSelectionModel(selectionModel, selectionManager);

// create your column
Column<UserModel, Boolean> checkBoxColumn = new Column<UserModel, Boolean>(new CheckboxCell()) {

   @Override
   public Boolean getValue(UserModel object) {
    return selectionModel.isSelected(object);
   }
   
   @Override
   public FieldUpdater<UserModel, Boolean> getFieldUpdater() {
       return null;
      } 
   
  };

GWT UiBinder.useSafeHtmlTemplates warning

Add in the module descriptor this property:

How to delete a GWT module.

1. Google -> Web Toolkit Settings -> remove the module.
2. Run As -> Run Configurations -> Arguments, and remove the deleted

How to test GWT apps in Hosted Mode with a Tomcat Server

http://code.google.com/intl/es-AR/webtoolkit/doc/latest/FAQ_DebuggingAndCompiling.html#How_do_I_use_my_own_server_in_hosted_mode_instead_of_GWT%27s

How to capture GET parameters in GWT

String param = Window.Location.getParameter("param");

NumberFormat in GWT

String vat = NumberFormat.getFormat("0.00").format(country.getVAT());

I'm trying to learn english, if you find some mistakes in my redaction, please make a comment with my error

appengine hot deploy on mac

1. Install JRebel
2. In Eclipse go to Help -> Install New Software... and download JRebel plugin http://www.zeroturnaround.com/update-site
3. Specified jrebel.jar jar in Eclipse / JRebel.
4. Modify dev_appserver.sh and let it something like this:

java -ea -cp "$JAR_FILE" \
com.google.appengine.tools.KickStart
--jvm_flag=-javaagent:$REBEL_HOME/jrebel.jar --jvm_flag=-noverify \
com.google.appengine.tools.development.DevAppServerMain $*

5. Add to the Run Configuration this VM Argument

-javaagent:/path/to/jrebel/jrebel.jar -noverify

6. Now it must works!

Taken from this steps for Windows http://androidisland.blogspot.com/2010/09/appengine-jrebel-and-eclipse-getting.html