CopyToClipBoard Not Aligned Vaadin with JavaScript

Hi,
I used CopyToClipBoard, but it was not aligning.

StringBuilder js = new StringBuilder();
js.append(“var controlValue = '”);
js.append(stringBuilder.toString());
js.append(“';window.clipboardData.setData(‘Text’, controlValue);”);
System.out.println(“\n”+js.toString());
//JavaScript.getCurrent().execute(js.toString());
JavaScript.getCurrent().execute(js.toString());

Thanks
Sakthi

What do you mean by aligned? Do you have formating in your text which got missing?

Hi,

I have formatted Text using stringBuilder. But it working fine using AWT. But not executing using JavaScript.

StringSelection clipBoardIndicationReport = new StringSelection(stringBuilder.toString());
clipboard.setContents(clipBoardIndicationReport, null);

But When I am trying to execute Javascript. It was not executing. Please suggest me.

Hi,
I have formatted using stringBuilder and finally i am trying to add JavaScript.getCurrent().execute(“window.clipboardData.setData(‘Text’,” +stringBuilder.toString()+“)”);
But it was not working.

Thanks
Sakthi

Could anyone reply on this

Will anyone help me out

Don’t bum your post so often. Don’t expect to always have an answer after a day.
Are you sure that Javascript code works even, or whether you may need another JS library for it?
I tested it by making a simple html file with this JS code and no browser could process it window.clipboardData is undefined.

Sorry, it is working fine. But We had problem how to align the next line.

Thanks
Sakthi

Vaadin with JavaScript:
It is getting copied but not getting aligned.

StringBuilder js = new StringBuilder();
js.append(“var controlValue = '”);
js.append(stringBuilder.toString());
js.append(“';window.clipboardData.setData(‘Text’, controlValue);”);
System.out.println(“\n”+js.toString());
//JavaScript.getCurrent().execute(js.toString());
JavaScript.getCurrent().execute(js.toString());

Hi, what exactly do you mean by “aligned”? What is the expected result, and what is the actual result? I’m afraid we can’t help you without more information.

Hi,
Say for Example:

        I have data in StringBuilder like: I have already formated using \t and \n in Java. I want to output to be ClipBoard.

I am using Vaadin7. But We have addon only Vaadin6. So I tried to use above concept. But not able to integrate vaadin with Javascript. Please look at my below code whici would be helpful.

I

  StringBuilder [b]

js
[/b] = new StringBuilder();
js.append(“var controlValue = '”);
js.append(stringBuilder.toString());
js.append(“';window.clipboardData.setData(‘Text’, controlValue);”);
JavaScript.getCurrent().execute(js.toString());



// I need to use js objects in JavaScript.getCurrent().execute(js.toString());


js
Object would give below output while running java program. But at the same time I want to use CopyToClipboard.

            [b]

Item Details: Pen

Item Name
[/b]: InkPen
Amount
: 10$
[b]
Renolds Amount: 20$
AAAAA Amount: 30$

                                               Total:  60$

[/b]

I have one button "
CopyToClipBoard
" When I click that button. The Above format should be copied and when I click on CTRL+V same will be pasted in WordDocument.

Please help me…

Thanks in Advance.

Hi,

Could you please look into this.

Hi,

Could you please look into this.

I wrote the following test UI that seems to work fine (tried with IE 11, pasted to WordPad):

public class ClipboardTest extends UI {
    @Override
    protected void init(VaadinRequest request) {
        setContent(new Button("Click here", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {

                StringBuilder sb = new StringBuilder();
                // note that we don't use \t and \n directly because
                // the newlines would result in incorrect javascript
                sb.append("FOO\\tBAR\\tBAZ\\n");
                sb.append("1\\t2\\t3\\n");
                sb.append("4\\t5\\t6\\n");

                StringBuilder js = new StringBuilder();
                js.append("var controlValue  = '");
                js.append(sb.toString());
                js.append("';window.clipboardData.setData('Text', controlValue);");
                JavaScript.getCurrent().execute(js.toString());
            }

        }));
    }
}

Johannes:
This is a great solution for IE, but do you know how to make this happen in Firefox and Chrome?

–PK