PDA

View Full Version : calling function



emmas
2 Feb 2010, 6:05 PM
Hi, i have a label on a header bar of my grid which opens 'Save As' popup dialog to load a file,
here is the code:

private LabelField exportReport;
exportReport = new LabelField("Export");
exportReport.setText("<a href= /f_m.csv>Export</a>");
resultPanel.getHeader().addTool(exportReport);

But i need that label to call a function first (that function executes a procedure and creates that f_m.csv file on app server).

How do i make my label to call that function on click event first, before the popup window comes up?

Thank you.

gaspo100
2 Feb 2010, 7:48 PM
I would do it like this:



private LabelField exportReport;
exportReport = new LabelField("Export");
resultPanel.getHeader().addTool(exportReport);

exportReport.addStyleName("html-link");
exportReport.sinkEvents(Event.ONCLICK);
exportReport.addListener(Events.OnClick, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
GWT.create(MyRemService.class).createCSV(new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// show error
}

public void onSuccess(String result) {
Window.open(result, "", "");
}
});
}
});


Put this into your application CSS file and adjust as necessary:


.html-link {
font-size: 12px;
cursor: hand;
cursor: pointer;
vertical-align: middle;
color: navy;
}

Arno.Nyhm
3 Feb 2010, 10:16 AM
or look at this: how to style a button as link
http://www.extjs.com/forum/showthread.php?t=85159&highlight=link