<h1>Web Application Starter Project</h1>
<table align="center">
<tr>
<td colspan="2" style="font-weight:bold;">Please enter your name:</td>
</tr>
<tr>
<td id="nameFieldContainer"></td>
<td id="sendButtonContainer"></td>
</tr>
<tr>
<td colspan="2" style="color:red;" id="errorLabelContainer"></td>
</tr>
<tr>
<td id="readTextField"></td>
<td id="readTextButton"></td>
</tr>
<tr>
<td id="writeTextField"></td>
<td id="writeTextButton"></td>
</tr>
</table>
TextBox readText = new TextBox();
readText.setText("readText");
Button readTextButton = new Button("readText");
TextBox writeText = new TextBox();
writeText.setText("writeText");
Button writeTextButton = new Button("writeText");
RootPanel.get("readTextField").add(readText);
RootPanel.get("readTextButton").add(readTextButton);
RootPanel.get("writeTextField").add(writeText);
RootPanel.get("writeTextButton").add(writeTextButton);
readTextButton.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent event)
{
readText();
}
});
writeTextButton.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent event)
{
writeText(writeText.getText());
}
});
public native void readText()
/*-{
try
{
if (navigator.clipboard)
{
console.log('navigator.clipboard.readText()');
console.log('document.hasFocus()='+document.hasFocus());
console.log('$doc.hasFocus()='+$doc.hasFocus());
var promise = navigator.clipboard.readText();
var resolve = function(text) {
console.log(text);
};
var reject = function(reason) {
console.log('navigator.clipboard.readText failed: '+reason);
};
promise["catch"](reject);
promise.then(resolve,reject)["catch"](reject);
}
else
{
console.log('This browser does not support navigator.clipboard.');
}
}
catch (e)
{
console.error(e,e.stack);
}
}-*/;
public native void writeText(String p_text)
/*-{
try
{
var _this = this;
if (navigator.clipboard)
{
console.log('navigator.clipboard.writeText()');
console.log('document.hasFocus()='+document.hasFocus());
console.log('$doc.hasFocus()='+$doc.hasFocus());
var promise = navigator.clipboard.writeText(p_text);
var resolve = function(text) {
console.log('navigator.clipboard.writeText '+text);
};
var reject = function(reason) {
console.log('navigator.clipboard.writeText failed: '+reason);
};
promise["catch"](reject);
promise.then(resolve,reject)["catch"](reject);
}
else
{
console.log('This browser does not support navigator.clipboard.');
}
}
catch (e)
{
console.error(e,e.stack);
}
}-*/;
navigator.clipboard.readText()
document.hasFocus()=false
$doc.hasFocus()=true
navigator.clipboard.readText failed: NotAllowedError: Document is not focused.
navigator.clipboard.writeText()
document.hasFocus()=false
$doc.hasFocus()=true
navigator.clipboard.writeText failed: NotAllowedError: Document is not focused.
is there any library or anything to be included/imported to get async/await support with GWT?
public static native String readText()/*-{
try
{
var promise = $wnd.navigator.clipboard.readText();
var resolve = function(text){
console.log(text);// I can print text here but not able to return it as String
}
catch (e){
//futher code goes here
}
}-*/;
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/9856ced4-a191-499c-9118-edc72ef6831fn%40googlegroups.com.
promise.then(resolve);
readTextButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event){
//Goal is to receive copied value on readText() function call.
String str =readText(null)// 1. What should I pass as argument over here-I know null argument is not correct, My apologies as I am not well versed with async //callbacks
}
});
public static native String readText(Loaded<String> clipboardText)/*-{
try{
if($wnd.navigator.clipboard){
var promise=$wnd.navigator.clipboard.readText();
var resolve= function(text){
console.log(txt); //2.Here I can see copied text in console
clipboardText.@com.mypackage.Loaded::data(*)(text);
};
var reject=function(reason){
console.log('$wnd.navigator.clipboard.readText failed: + reason'); //3.Getting cannot read properties of null
};
promise["catch"](reject);
promise.then(resolve,reject)["catch"](reject);
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/d0792d02-8185-464b-aa53-89179c2845a7n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/e44b0c23-152d-4a89-ae2a-682275dbf182n%40googlegroups.com.
protected Function pasteFromExcelFunction =new Function(){
public void execute(){
if(readOnly){
return;
}// its false
try{
if(pasteFromExcelHelper.pasteDataIntoGrid(BaseEditorGridPanel.this, getRecordDef()));
doAfterPaste();
}
}
}
public boolean pasteDataIntoGrid(BaseEditorGridPanel grid, BaseGridRecordDef recordDef)
{
boolean pasteSuccessful=true;
String pastedText= readFromClipboard();
// pastedText is further adjusted as per the grid-all java code
} private String readFromClipboard (){ return JavaScriptUtils.getClipboardData(); } public static native String getClipboardData()/*-{
// I want modern clipboard api to return string
if($wnd.clipboardData && clipboardData.setData){
return $wnd.clipboardData.getData('Text');
}-*/;
So with respect to above method i.e. getClipboardData , which returns string , this works fine with IE but not with modern browser, so I tried new clipboard api but i cant return string. Could you please guide me with repect to above code, its been while I am struggling !!
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/f0fa10c9-a5c5-44c4-9d60-4d7acf2401ean%40googlegroups.com.