1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:h5="http://java.sun.com/jsf/composite/html5"> <script> function dragenter(event) { /* Implement as desired */ } function dragleave(event) { /* Implement as desired */ } function dragover(event) { /* Implement as desired */ } function drop(event) { /* Implement as desired */ } </script> <h5:drop id="dropzone" payload="#{dragDrop.payload}" render="@this" ondragover="dragover(event)" ondragenter="dragenter(event)" ondragleave="dragleave(event)" ondrop="drop(event)"> <div class="welcomeImage"> <h:graphicImage id="welcomeImage" library="images" name="cloudy.gif"/> </div> <br /> <div class="savedItems"> <ui:repeat value="#{rssFeed.savedItems}" var="item"> <div class="savedLink"> <a href="#{item.link}"> #{ fn:substring(item.title, 0, 25) } ... </a> <br/> </div> </ui:repeat> </div> </h5:drop> </ui:composition> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:composite="http://java.sun.com/jsf/composite"> <composite:interface> <composite:attribute name="ondragenter"/> <composite:attribute name="ondragover"/> <composite:attribute name="ondragleave"/> <composite:attribute name="ondrop"/> <composite:attribute name="render"/> <composite:attribute name="payload"/> <composite:attribute name="payloadType"/> </composite:interface> <composite:implementation> <hutputScript library="javax.faces" name="jsf.js" target="head" /> <hutputScript library="html5" name="drop.js" target="head" /> <div id="#{cc.id}" ondragenter="#{cc.attrs.ondragenter}" ondrop="#{cc.attrs.ondrop}" ondragover="#{cc.attrs.ondragover}" ondragleave="#{cc.attrs.ondragleave}"> <composite:insertChildren /> <h:form id="form"> <h:inputText id="payload" value="#{cc.attrs.payload}" style="display: none"/> </h:form> </div> <script> html5.jsf.init("#{cc.id}", "#{cc.attrs.payloadType}", "#{cc.attrs.render}"); </script> </composite:implementation> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | if (!html5) var html5 = {} if (!html5.jsf) { html5.jsf = { init : function(ccid, payloadType, renderIds) { var dropzone = $(ccid); dropzone.payloadInput = $(ccid + ":form:payload"); dropzone.addEventListener("drop", function(event) { if (payloadType == "") payloadType = "text"; if (renderIds == "" || renderIds == "@this") renderIds = ccid; dropzone.payloadInput.value = event.dataTransfer .getData(payloadType);jsf.ajax.request(dropzone.payloadInput, event, { render : renderIds, onevent : function(data) { if (data.status == "success") html5.jsf.init(ccid, payloadType, renderIds); } }); }, false); dropzone.addEventListener("dragenter", function(event) { event.preventDefault(); }, false); dropzone.addEventListener("dragover", function(event) { event.preventDefault(); }, false); } }; } |
1 | <h5:drop...payload="#{dragDrop.payload}"> |
1 | <h:inputText id="payload" value="#{cc.attrs.payload}" style="display: none"/> |
1 | jsf.ajax.request(dropzone.payloadInput, event, {...}); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | package com.clarity; import java.util.Iterator; import java.util.LinkedList; import java.util.StringTokenizer; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; import javax.inject.Named; import org.gnu.stealthp.rsslib.RSSItem; @Named @SessionScoped public class DragDrop implements Serializable { @Inject private RSSFeed rssFeed; public DragDrop() { } public String getPayload() { // JSF requires both getters and setters for input properties return ""; } public void setPayload(String payload) { // creates a new saved item, based on the payload. Payload // was set in the drop event listener for the h5:drop component // in /sections/feeds/menuLeft.xhtml StringTokenizer st = new StringTokenizer(payload); RSSItem item = new RSSItem(); item.setTitle(st.nextToken("|")); st.nextToken(" "); item.setLink(st.nextToken(" ")); rssFeed.getSavedItems().add(item); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |