Strict Standards: Non-static method CodeColorerLoader::Enable() should not be called statically in /home/k6000169/public_html/wp-content/plugins/codecolorer/codecolorer.php on line 254
Gwt | Programador freelance argentina

gwt

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'>

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 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{

public ContextMenuColumn(Cell 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
table.addColumn(contextMenuColumn);

GWT Celltable add a Row Handler

Handler rowHandler = new Handler() {
@Override
public void onCellPreview(CellPreviewEvent 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 selectionModel = new MultiSelectionModel(operatorKeyProvider);

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

// you need the table ;)
@UiField CellTable table;

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

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

table.setSelectionModel(selectionModel, selectionManager);

// create your column
Column checkBoxColumn = new Column(new CheckboxCell()) {

@Override
public Boolean getValue(UserModel object) {
return selectionModel.isSelected(object);
}

@Override
public FieldUpdater 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 create a GWT library

http://swe-strongsteve.blogspot.com/2010/11/creating-re-usable-composites-using-gwt.html

GWT 2.1 MVP and Composite

http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2812e1b15a2a98a6

GWT Places Tuto

http://tbroyer.posterous.com/gwt-21-places
http://www.methodknowledgy.com/2010/09/using-gwts-application-framework-judiciously/