diff --git a/gradleResources/js/bsf.js b/gradleResources/js/bsf.js index 2d50ce379..a005bf233 100644 --- a/gradleResources/js/bsf.js +++ b/gradleResources/js/bsf.js @@ -156,7 +156,7 @@ function jq( myid ) { return "#" + myid.replace( /(:|\.|\[|\]|,)/g, "\\$1" ); } -/* tree support method to convert data object to state string */ +/* tree support method to convert data object to state string function treeDataMapper(data) { var sep = "|#*#|"; if(data && data !== "undefined") { @@ -169,7 +169,7 @@ function treeDataMapper(data) { data.state.selected; } return ""; -} +}*/ BsF.substringMatcher = function(strs) { return function findMatches(q, cb) { diff --git a/mavenResources/META-INF/resources/bsf/js/bsf.js b/mavenResources/META-INF/resources/bsf/js/bsf.js index f01c9ffde..c1f32408d 100644 --- a/mavenResources/META-INF/resources/bsf/js/bsf.js +++ b/mavenResources/META-INF/resources/bsf/js/bsf.js @@ -10,4 +10,4 @@ BsF.ajax.onevent=function(a){if("complete"===a.status){var b=a.source.id.replace BsF.ajax.callAjax=function(a,b,c,d,f,g,h,m){var k=a.id,l=k.replace(/[^a-zA-Z0-9]+/g,"_"),e={};m&&(e.params="BsFEvent="+m);(c=BsF.ajax.resolveJQuery(c))&&null!=c&&(e.render=c);(d=BsF.ajax.resolveJQuery(d))&&null!=d&&(e.execute=d);e[k]=k;BsF.onCompleteCallback[l]=f&&null!=f?f:null;BsF.onErrorCallback[l]=g&&null!=g?g:null;BsF.onSuccessCallback[l]=h&&null!=h?h:null;e.onevent=BsF.ajax.onevent;jsf.ajax.request(a,b,e);$.blockUI&&null!=$.blockUI&&$.blockUI();return!1}; BsF.ajax.resolveJQuery=function(a){if("undefined"==typeof a||null==a)return"";var b="";a=a.split(" ");for(i=0;i[^<]+<\/span>/,'');return a=a.replace(/[^<]+<\/span>/,'')}} -function jq(a){return"#"+a.replace(/(:|\.|\[|\]|,)/g,"\\$1")}function treeDataMapper(a){return a&&"undefined"!==a?a.nodeInternalId+"|#*#|"+a.text+"|#*#|"+("undefined"==typeof a.data?"":a.data)+"|#*#|"+a.state.checked+"|#*#|"+a.state.disabled+"|#*#|"+a.state.expanded+"|#*#|"+a.state.selected:""}BsF.substringMatcher=function(a){return function(b,c){var d;d=[];substrRegex=new RegExp(b,"i");$.each(a,function(a,b){substrRegex.test(b)&&d.push(b)});c(d)}}; \ No newline at end of file +function jq(a){return"#"+a.replace(/(:|\.|\[|\]|,)/g,"\\$1")}BsF.substringMatcher=function(a){return function(b,c){var d;d=[];substrRegex=new RegExp(b,"i");$.each(a,function(a,b){substrRegex.test(b)&&d.push(b)});c(d)}}; \ No newline at end of file diff --git a/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java b/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java index 4dd5e4b5c..d80e35e33 100644 --- a/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java +++ b/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java @@ -63,7 +63,8 @@ public void decode(FacesContext context, UIComponent component) { value = pair[1]; } if (value != null && !"".equals(value.trim())) { - Node n = TreeModelUtils.mapDataToModel(value); + // Node n = TreeModelUtils.mapDataToModel(value); + Node n = (Node) BsfUtils.fromString(value); TreeModelUtils.updateNodeById(tree.getValue(), n.getNodeId(), n); // tree.setSubmittedValue(tree.getValue()); @@ -167,27 +168,33 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce " data: getTreeData(), " + // enable nodeSelected event callback " onNodeSelected: function(event, data) { " + - " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeSelected:' + treeDataMapper(data));" + // @all + //" BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeSelected:' + treeDataMapper(data));" + // @all + " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeSelected:' + data.serialize);" + // @all " }," + // enable nodeUnselected event callback " onNodeUnselected: function(event, data) { " + - " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeUnselected:' + treeDataMapper(data));" + // @all + //" BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeUnselected:' + treeDataMapper(data));" + // @all + " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeUnselected:' + data.serialize);" + // @all " }," + //enable nodeChecked event callback " onNodeChecked: function(event, data) { " + - " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeChecked:' + treeDataMapper(data));" + // @all + //" BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeChecked:' + treeDataMapper(data));" + // @all + " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeChecked:' + data.serialize);" + // @all " }," + //enable nodeUnchecked event callback " onNodeUnchecked: function(event, data) { " + - " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeUnchecked:' + treeDataMapper(data));" + // @all + //" BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeUnchecked:' + treeDataMapper(data));" + // @all + " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeUnchecked:' + data.serialize);" + // @all " }," + // enable nodeCollapsed event callback " onNodeCollapsed: function(event, data) { " + - " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeCollapsed:' + treeDataMapper(data));" + // @all + //" BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeCollapsed:' + treeDataMapper(data));" + // @all + " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeCollapsed:' + data.serialize);" + // @all " }," + // enable nodeExpanded event callback " onNodeExpanded: function(event, data) { " + - " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeExpanded:' + treeDataMapper(data));" + // @all + //" BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeExpanded:' + treeDataMapper(data));" + // @all + " BsF.ajax.callAjax(this, event, '" + updateItems + "', '" + clientId + "', null, null, null, 'nodeExpanded:' + data.serialize);" + // @all " }" + "}); ", null); rw.writeText("});", null); diff --git a/src/main/java/net/bootsfaces/component/tree/model/DefaultNodeImpl.java b/src/main/java/net/bootsfaces/component/tree/model/DefaultNodeImpl.java index de7e4e495..f6b2a8e3a 100644 --- a/src/main/java/net/bootsfaces/component/tree/model/DefaultNodeImpl.java +++ b/src/main/java/net/bootsfaces/component/tree/model/DefaultNodeImpl.java @@ -38,7 +38,7 @@ public class DefaultNodeImpl implements Node, Serializable { private static final long serialVersionUID = -6742025921003033215L; - private final List childs = new ArrayList(); + private final transient List childs = new ArrayList(); private String data; private int nodeId; private String text; diff --git a/src/main/java/net/bootsfaces/component/tree/model/Node.java b/src/main/java/net/bootsfaces/component/tree/model/Node.java index 417be6e24..b418aecb2 100644 --- a/src/main/java/net/bootsfaces/component/tree/model/Node.java +++ b/src/main/java/net/bootsfaces/component/tree/model/Node.java @@ -19,9 +19,11 @@ package net.bootsfaces.component.tree.model; +import java.io.Serializable; import java.util.List; -public interface Node { +public interface Node +extends Serializable { /** * @return the node id */ diff --git a/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java b/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java index 760b3d9a9..d78d9ad9a 100644 --- a/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java +++ b/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java @@ -183,6 +183,8 @@ private static String renderNode(Node node) { sb.append(renderSubnodes(node.getChilds())); sb.append(","); } + // SERIALIZE + sb.append("\"serialize\": \"" + BsfUtils.toString(node) + "\", "); sb.append("\"selectable\": " + node.isSelectable() + ", "); sb.append("\"state\": {"); diff --git a/src/main/java/net/bootsfaces/utils/BsfUtils.java b/src/main/java/net/bootsfaces/utils/BsfUtils.java index 215412e03..e04efe3b8 100644 --- a/src/main/java/net/bootsfaces/utils/BsfUtils.java +++ b/src/main/java/net/bootsfaces/utils/BsfUtils.java @@ -1,8 +1,14 @@ package net.bootsfaces.utils; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Base64; import java.util.Iterator; import java.util.Locale; import java.util.MissingResourceException; @@ -512,4 +518,43 @@ public static String getLabel(FacesContext context, UIComponent comp) { } return (String) o; } + + /** + * Read an object from a base64 string + * @param s + * @return + * @throws IOException + * @throws ClassNotFoundException + */ + public static Object fromString(String s) { + try { + byte [] data = Base64.getDecoder().decode( s ); + ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); + Object o = ois.readObject(); + ois.close(); + return o; + } catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Write an object to base64 string + * @param o + * @return + * @throws IOException + */ + public static String toString(Serializable o) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(o); + oos.close(); + return Base64.getEncoder().encodeToString(baos.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); + return ""; + } + } }