Sto scrivendo un'app GWT che implica l'interazione con un documento esterno in un iframe. Come prova del concetto, sto cercando di collegare un gestore di clic a un pulsante.Collegamento di un evento GWT a un elemento in un iframe esterno
le seguenti opere in javascript
var iframe = document.getElementById("rawJSIFrame");
var doc = iframe.contentDocument;
var body = doc.body;
var button = doc.getElementsByTagName("input").namedItem("submit");
button.onclick = function() {
alert("Clicked!");
};
Cercando di fare l'equivalente in GWT, ho fatto la seguente:
public void addClickHandlerToSubmitButton(String buttonElementName, ClickHandler clickHandler) {
IFrameElement iframe = IFrameElement.as(frame.getElement());
Document frameDocument = getIFrameDocument(iframe);
if (frameDocument != null) {
Element buttonElement = finder(frameDocument).tag("input").name(buttonElementName).findOne();
ElementWrapper wrapper = new ElementWrapper(buttonElement);
HandlerRegistration handlerRegistration = wrapper.addClickHandler(clickHandler);
}
}
private native Document getIFrameDocument(IFrameElement iframe)/*-{
return iframe.contentDocument;
}-*/;
Quello che segue è la classe ElementWrapper:
public class ElementWrapper extends Widget implements HasClickHandlers {
public ElementWrapper(Element theElement) {
setElement(theElement);
}
public HandlerRegistration addClickHandler(ClickHandler handler) {
return addDomHandler(handler, ClickEvent.getType());
}
}
Il codice per trovare il pulsante funziona correttamente ma non viene richiamato il gestore di eventi effettivo. Qualcuno ha avuto un problema simile prima e come lo hai risolto?
Grazie in anticipo,
Tin
Grazie! Sapevo che doveva esserci un modo più pulito :) – triggerNZ