从jsf/primefaces复制文本到剪贴板 [英] Copy text to clipboard from jsf / primefaces

查看:149
本文介绍了从jsf/primefaces复制文本到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/patricklodder/jquery-zclip 来实现复制到剪贴板功能. 它应该复制一些文本,但是现在我希望它可以是任何东西……但它根本无法正常工作.

I am using https://github.com/patricklodder/jquery-zclip to implement copy to clipboard function. it should copy some text, but for now i want it to be anything really... but its not working at all.

我包括在头上:

<h:outputScript name="js/jquery.zclip.min.js" library="test" />

        <script>
            $(document).ready(function(){
                $('a#copy').zclip({
                    path:'#{resource['/test/js/ZeroClipboard.swf']}',
                    copy:$('div#content').text()
                });
            });                
        </script>

在JSF页面中,我有一个普通的:

and in JSF page i have an ordinary :

<a href="#" id="copy">COPY</a> 

Chrome控制台中没有错误,但是单击链接也无济于事. 我真的不知道为什么它不起作用.非常感谢您的任何建议.

there are no errors in Chrome console but clicking the link doesn't do anything too. I really have no idea why it's not working. Big thanks for any suggestion.

----------编辑

---------- EDIT

数据网格:

<p:dataGrid var="item" columns="3" rows="9" value="#{pictureManagementBean.pictures}" id="gallery" paginator="true">  

<p:column>
    <p:panel header="#{item.pictureName}" style="text-align:center; width:230px;">  
         <h:panelGrid styleClass="shortLink"> 
             <p:graphicImage value="#{item.thumbnailDir}" width="200px" />                             
             <a href="#" id="copy#{item.idpicture}">COPY</a>   
             <p id="copy#{item.idpicture}">LOREM IPSUM</p>
             <p:commandLink value="Delete" action="#pictureManagementBean.removePicture(item.idpicture)}" update="@form"/>

</h:panelGrid></p:panel></p:column></p:dataGrid> 

推荐答案

这对我有用:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
   <h:head>
   </h:head>
   <h:body>
         <h:outputScript library="default" name="js/jquery-1.8.1.min.js"/>
         <h:outputScript library="default" name="js/jquery.zclip.min.js"/>
         <script type="text/javascript">
         $(document).ready(function(){

                $('a#copy-description').zclip({
                    path:"#{resource['default:js/ZeroClipboard.swf']}",
                    copy:$('p#description').text()
                });
         });
         </script>
         <a id="copy-description" href="#">Copy Description</a>
         <p id="description">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat venenatis erat 
            eu convallis. Phasellus ut purus dui, in tristique ligula. Fusce a sodales ipsum.
            Proin et commodo lacus. Morbi eget lectus ante, sed interdum orci.
            Nunc rutrum, enim in mattis bibendum, sapien ligula semper nisi, sed ullamcorper justo sem quis felis.
            Duis vehicula arcu non felis convallis eleifend.
         </p>
   </h:body>
</html>

其中的文件夹结构是这样的:

where the folder structure is like this:

-->resources/default/js/jquery.zclip.min.js
-->resources/default/js/ZeroClipboard.swf

这篇关于从jsf/primefaces复制文本到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆