Seam SVN: r11909 - modules/remoting/trunk/examples/model/src/main/webapp.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-04 07:58:34 -0500 (Mon, 04 Jan 2010)
New Revision: 11909
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
Log:
replace hard coded actions with user driven actions
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 12:33:46 UTC (rev 11908)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 12:58:34 UTC (rev 11909)
@@ -17,33 +17,81 @@
<script type="text/javascript">
//<![CDATA[
-
+
+ // Turn on debug logging so we can see the request and response packets
Seam.debug = true;
-
+
var model = null;
- function fetch() {
- alert("fetch");
+ // A helper function that returns the value of an element
+ function getElementValue(elementName) {
+ var value = document.getElementById(elementName).value;
+ return (value.trim().length > 0) ? value : null;
}
- function apply() {
- alert("apply");
- }
-
- function loadPerson() {
- var personId = document.getElementById("personId").value;
+ // Fetch the model
+ function fetch() {
+ var fetchActionBean = getElementValue("fetchActionBean");
+ var fetchActionQualifiers = getElementValue("fetchActionQualifiers");
+ var fetchActionMethod = getElementValue("fetchActionMethod");
+ var fetchActionParams = getElementValue("fetchActionParams");
+ var action = null;
+
+ if (fetchActionBean) {
+ action = new Seam.Action();
+ action.setBeanType(fetchActionBean);
+ if (fetchActionQualifiers) action.setQualifiers(fetchActionQualifiers);
+ action.setMethod(fetchActionMethod);
+ if (fetchActionParams) {
+ var params = fetchActionParams.split(",");
+ for (var i = 0; i < params.length; i++) {
+ action.addParam(params[i].trim());
+ }
+ }
+ }
+
model = new Seam.Model();
-
- var callback = function(model) { var p = model.getValue("person"); alert(p.getFirstName() + " " + p.getLastName()); };
+ var callback = function(model) { alert("model fetched"); };
model.addBeanProperty("person", "org.jboss.seam.remoting.examples.model.PersonAction", "person");
- model.fetch(new Seam.Action()
- .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
- .setMethod("editPerson")
- .addParam(personId), callback);
+
+ if (action)
+ model.fetch(action, callback);
+ else
+ model.fetch(callback);
}
+ // Apply changes to the model
+ function apply() {
+ var applyActionBean = getElementValue("applyActionBean");
+ var applyActionQualifiers = getElementValue("applyActionQualifiers");
+ var applyActionMethod = getElementValue("applyActionMethod");
+ var applyActionParams = getElementValue("applyActionParams");
+
+ var action = null;
+
+ if (applyActionBean) {
+ action = new Seam.Action();
+ action.setBeanType(applyActionBean);
+ if (applyActionQualifiers) action.setQualifiers(applyActionQualifiers);
+ action.setMethod(applyActionMethod);
+ if (applyActionParams) {
+ var params = applyActionParams.split(",");
+ for (var i = 0; i < params.length; i++) {
+ action.addParam(params[i].trim());
+ }
+ }
+ }
+
+ var callback = function(model) { alert("model updates applied"); };
+
+ if (action)
+ model.applyUpdates(action, callback);
+ else
+ model.applyUpdates(callback);
+ }
+
function expandModel() {
var callback = function(model) { alert("Got addresses: " + model.getValue("person").getAddresses().length); };
@@ -54,26 +102,13 @@
model.getValue("person").setFirstName("bob");
}
- function applyUpdates() {
- var callback = function(model) { alert("updates applied"); };
-
- model.applyUpdates(new Seam.Action()
- .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
- .setMethod("savePerson"),
- callback);
- }
-
var tm = new xw.controls.TreeModel(new xw.controls.TreeNode("Root"));
-
var abc = new xw.controls.TreeNode("ABC");
tm.getRoot().add(abc);
-
abc.add(new xw.controls.TreeNode("123", true));
abc.add(new xw.controls.TreeNode("456", true));
-
var def = new xw.controls.TreeNode("DEF");
tm.getRoot().add(def);
-
def.add(new xw.controls.TreeNode("xxx", true));
def.add(new xw.controls.TreeNode("yyy", true));
def.add(new xw.controls.TreeNode("zzz", true));
@@ -86,7 +121,7 @@
<div class="sectionForm">
<div class="formRow">
<label for="fetchActionBean">Bean</label>
- <input type="text" id="fetchActionBean" value="org.jboss.seam.remoting.example.model.PersonAction"/>
+ <input type="text" id="fetchActionBean" value="org.jboss.seam.remoting.examples.model.PersonAction"/>
</div>
<div class="formRow">
<label for="fetchActionQualifiers">Qualifiers</label>
@@ -114,7 +149,7 @@
<div class="sectionForm">
<div class="formRow">
<label for="applyActionBean">Bean</label>
- <input type="text" id="applyActionBean" value="org.jboss.seam.remoting.example.model.PersonAction"/>
+ <input type="text" id="applyActionBean" value="org.jboss.seam.remoting.examples.model.PersonAction"/>
</div>
<div class="formRow">
<label for="applyActionQualifiers">Qualifiers</label>
@@ -138,18 +173,19 @@
</div>
<div class="section">
- <div class="sectionHeader">Model values</div>
+ <div class="sectionHeader">Model properties</div>
+
+
<br class="clear"/>
</div>
- <label for="personId">Person ID</label><input type="text" id="personId" value="1"/>
-
- <button onclick="javascript:loadPerson()">Load person</button>
+
+
+
<button onclick="javascript:expandModel()">expand model</button>
<button onclick="javascript:modifyPerson()">Modify person</button>
- <button onclick="javascript:applyUpdates()">Apply updates</button>
<div id="tree" style="position:absolute;left:10px;width:300px;height:400px;border:1px solid #999999;overflow:auto"></div>
14 years, 12 months
Seam SVN: r11908 - modules/remoting/trunk/examples/model/src/main/webapp.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-04 07:33:46 -0500 (Mon, 04 Jan 2010)
New Revision: 11908
Added:
modules/remoting/trunk/examples/model/src/main/webapp/style.css
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
Log:
updated example UI
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 06:13:21 UTC (rev 11907)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 12:33:46 UTC (rev 11908)
@@ -4,6 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Seam Remoting - Model Example</title>
+ <link href="style.css" rel="stylesheet" type="text/css"/>
<link href="tree.css" rel="stylesheet" type="text/css"/>
</head>
@@ -20,6 +21,14 @@
Seam.debug = true;
var model = null;
+
+ function fetch() {
+ alert("fetch");
+ }
+
+ function apply() {
+ alert("apply");
+ }
function loadPerson() {
var personId = document.getElementById("personId").value;
@@ -70,8 +79,71 @@
def.add(new xw.controls.TreeNode("zzz", true));
// ]]>
- </script>
+ </script>
+ <div class="section">
+ <div class="sectionHeader">Fetch model action</div>
+ <div class="sectionForm">
+ <div class="formRow">
+ <label for="fetchActionBean">Bean</label>
+ <input type="text" id="fetchActionBean" value="org.jboss.seam.remoting.example.model.PersonAction"/>
+ </div>
+ <div class="formRow">
+ <label for="fetchActionQualifiers">Qualifiers</label>
+ <input type="text" id="fetchActionQualifiers"/>
+ </div>
+ <div class="formRow">
+ <label for="fetchActionMethod">Method</label>
+ <input type="text" id="fetchActionMethod" value="editPerson"/>
+ </div>
+ <div class="formRow">
+ <label for="fetchActionParams">Params</label>
+ <input type="text" id="fetchActionParams" value="1"/>
+ </div>
+ </div>
+
+ <div class="sectionCommand">
+ <button onclick="javascript:fetch()">Fetch</button>
+ </div>
+
+ <br class="clear"/>
+ </div>
+
+ <div class="section">
+ <div class="sectionHeader">Apply model action</div>
+ <div class="sectionForm">
+ <div class="formRow">
+ <label for="applyActionBean">Bean</label>
+ <input type="text" id="applyActionBean" value="org.jboss.seam.remoting.example.model.PersonAction"/>
+ </div>
+ <div class="formRow">
+ <label for="applyActionQualifiers">Qualifiers</label>
+ <input type="text" id="applyActionQualifiers"/>
+ </div>
+ <div class="formRow">
+ <label for="applyActionMethod">Method</label>
+ <input type="text" id="applyActionMethod" value="savePerson"/>
+ </div>
+ <div class="formRow">
+ <label for="applyActionParams">Params</label>
+ <input type="text" id="applyActionParams"/>
+ </div>
+ </div>
+
+ <div class="sectionCommand">
+ <button onclick="javascript:fetch()">Apply</button>
+ </div>
+
+ <br class="clear"/>
+ </div>
+
+ <div class="section">
+ <div class="sectionHeader">Model values</div>
+
+ <br class="clear"/>
+ </div>
+
+
<label for="personId">Person ID</label><input type="text" id="personId" value="1"/>
<button onclick="javascript:loadPerson()">Load person</button>
@@ -79,7 +151,7 @@
<button onclick="javascript:modifyPerson()">Modify person</button>
<button onclick="javascript:applyUpdates()">Apply updates</button>
- <div id="tree" style="position:absolute;left:10;width:300px;height:400px;border:1px solid #999999;overflow:auto"></div>
+ <div id="tree" style="position:absolute;left:10px;width:300px;height:400px;border:1px solid #999999;overflow:auto"></div>
<script type="text/javascript">
//<![CDATA[
Added: modules/remoting/trunk/examples/model/src/main/webapp/style.css
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/style.css (rev 0)
+++ modules/remoting/trunk/examples/model/src/main/webapp/style.css 2010-01-04 12:33:46 UTC (rev 11908)
@@ -0,0 +1,50 @@
+body {
+ background-color: #ffffff;
+ font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
+ font-size: 12px;
+ color: #663009;
+}
+
+.sectionHeader {
+ font-size: 12px;
+ font-weight: bold;
+}
+
+div.section {
+ background-color: #eeeeee;
+ margin: 6px;
+ padding: 4px;
+}
+
+div.sectionForm {
+ float: left;
+ width: 390px;
+ padding: 4px;
+ border-right: 1px solid #cccccc;
+}
+
+div.sectionCommand {
+ float: left;
+ width: 120px;
+ padding: 4px;
+}
+
+div.formRow {
+ padding: 2px 4px 2px 2px;
+ clear: both;
+}
+
+div.formRow label {
+ float: left;
+ width: 70px;
+ padding: 2px 2px 2px 2px;
+}
+
+div.formRow input[type='text'] {
+ width: 300px;
+}
+
+.clear {
+ clear: both;
+ font-size: 0px;
+}
\ No newline at end of file
14 years, 12 months
Seam SVN: r11907 - in modules/remoting/trunk/examples/model/src/main: webapp and 1 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-04 01:13:21 -0500 (Mon, 04 Jan 2010)
New Revision: 11907
Added:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Address.java
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
modules/remoting/trunk/examples/model/src/main/webapp/tree.css
modules/remoting/trunk/examples/model/src/main/webapp/tree.js
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/folder-closed.png
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/folder-open.png
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/leafnode.png
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_branch.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_end.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_middle.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_end.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_middle.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_none.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_start.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_end.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_middle.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_none.gif
modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_start.gif
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
Log:
add resources for example
Added: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Address.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Address.java (rev 0)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Address.java 2010-01-04 06:13:21 UTC (rev 11907)
@@ -0,0 +1,96 @@
+package org.jboss.seam.remoting.examples.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class Address implements Serializable
+{
+ private static final long serialVersionUID = 6871342053292770838L;
+
+ private Integer addressId;
+ private Person person;
+ private Integer streetNo;
+ private String streetName;
+ private String suburb;
+ private String postCode;
+ private String country;
+
+ @Id @GeneratedValue
+ public Integer getAddressId()
+ {
+ return addressId;
+ }
+
+ public void setAddressId(Integer addressId)
+ {
+ this.addressId = addressId;
+ }
+
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "PERSON_ID")
+ public Person getPerson()
+ {
+ return person;
+ }
+
+ public void setPerson(Person person)
+ {
+ this.person = person;
+ }
+
+ public Integer getStreetNo()
+ {
+ return streetNo;
+ }
+
+ public void setStreetNo(Integer streetNo)
+ {
+ this.streetNo = streetNo;
+ }
+
+ public String getStreetName()
+ {
+ return streetName;
+ }
+
+ public void setStreetName(String streetName)
+ {
+ this.streetName = streetName;
+ }
+
+ public String getSuburb()
+ {
+ return suburb;
+ }
+
+ public void setSuburb(String suburb)
+ {
+ this.suburb = suburb;
+ }
+
+ public String getPostCode()
+ {
+ return postCode;
+ }
+
+ public void setPostCode(String postCode)
+ {
+ this.postCode = postCode;
+ }
+
+ public String getCountry()
+ {
+ return country;
+ }
+
+ public void setCountry(String country)
+ {
+ this.country = country;
+ }
+}
Added: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java (rev 0)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java 2010-01-04 06:13:21 UTC (rev 11907)
@@ -0,0 +1,76 @@
+package org.jboss.seam.remoting.examples.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Person implements Serializable
+{
+ private static final long serialVersionUID = 5652755541082449920L;
+
+ private Integer personId;
+ private String firstName;
+ private String lastName;
+ private Date dateOfBirth;
+
+ private Collection<Address> addresses;
+
+ @Id @GeneratedValue
+ public Integer getPersonId()
+ {
+ return personId;
+ }
+
+ public void setPersonId(Integer personId)
+ {
+ this.personId = personId;
+ }
+
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName)
+ {
+ this.firstName = firstName;
+ }
+
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+ public void setLastName(String lastName)
+ {
+ this.lastName = lastName;
+ }
+
+ public Date getDateOfBirth()
+ {
+ return dateOfBirth;
+ }
+
+ public void setDateOfBirth(Date dateOfBirth)
+ {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
+ public Collection<Address> getAddresses()
+ {
+ return addresses;
+ }
+
+ public void setAddresses(Collection<Address> addresses)
+ {
+ this.addresses = addresses;
+ }
+}
Added: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java (rev 0)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java 2010-01-04 06:13:21 UTC (rev 11907)
@@ -0,0 +1,55 @@
+package org.jboss.seam.remoting.examples.model;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.seam.remoting.annotations.WebRemote;
+
+@ConversationScoped
+public class PersonAction implements Serializable
+{
+ private static final long serialVersionUID = -1923705862231821692L;
+ @PersistenceContext EntityManager entityManager;
+ @Inject Conversation conversation;
+
+ private Person person;
+
+ @WebRemote
+ public void createPerson()
+ {
+ conversation.begin();
+ person = new Person();
+ }
+
+ @WebRemote
+ public void editPerson(Integer personId)
+ {
+ conversation.begin();
+ person = entityManager.find(Person.class, personId);
+ }
+
+ @WebRemote
+ public void savePerson() throws Exception
+ {
+ if (person.getPersonId() == null)
+ {
+ entityManager.persist(person);
+ }
+ else
+ {
+ person = entityManager.merge(person);
+ }
+
+ conversation.end();
+ }
+
+ public Person getPerson()
+ {
+ return person;
+ }
+}
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 02:09:18 UTC (rev 11906)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 06:13:21 UTC (rev 11907)
@@ -4,6 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Seam Remoting - Model Example</title>
+ <link href="tree.css" rel="stylesheet" type="text/css"/>
</head>
<body>
@@ -11,6 +12,7 @@
<h1>Seam Remoting - Model Example</h1>
<script type="text/javascript" src="seam/resource/remoting/resource/remote.js?compress=true"></script>
+ <script type="text/javascript" src="tree.js"></script>
<script type="text/javascript">
//<![CDATA[
@@ -52,6 +54,21 @@
callback);
}
+ var tm = new xw.controls.TreeModel(new xw.controls.TreeNode("Root"));
+
+ var abc = new xw.controls.TreeNode("ABC");
+ tm.getRoot().add(abc);
+
+ abc.add(new xw.controls.TreeNode("123", true));
+ abc.add(new xw.controls.TreeNode("456", true));
+
+ var def = new xw.controls.TreeNode("DEF");
+ tm.getRoot().add(def);
+
+ def.add(new xw.controls.TreeNode("xxx", true));
+ def.add(new xw.controls.TreeNode("yyy", true));
+ def.add(new xw.controls.TreeNode("zzz", true));
+
// ]]>
</script>
@@ -62,7 +79,15 @@
<button onclick="javascript:modifyPerson()">Modify person</button>
<button onclick="javascript:applyUpdates()">Apply updates</button>
+ <div id="tree" style="position:absolute;left:10;width:300px;height:400px;border:1px solid #999999;overflow:auto"></div>
+ <script type="text/javascript">
+ //<![CDATA[
+ var t = new xw.controls.Tree("tree", tm);
+ t.paint();
+ // ]]>
+ </script>
+
</body>
</html>
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree.css
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/tree.css (rev 0)
+++ modules/remoting/trunk/examples/model/src/main/webapp/tree.css 2010-01-04 06:13:21 UTC (rev 11907)
@@ -0,0 +1,116 @@
+div.treePlusStart {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/plus_middle.gif') no-repeat left top;
+}
+
+div.treePlusMiddle {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/plus_middle.gif') no-repeat left top;
+}
+
+div.treePlusEnd {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/plus_end.gif') no-repeat left top;
+}
+
+div.treePlusNone {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/plus_none.gif') no-repeat left top;
+}
+
+div.treeMinusStart {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/minus_start.gif') no-repeat left top;
+}
+
+div.treeMinusMiddle {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/minus_middle.gif') no-repeat left top;
+}
+
+div.treeMinusEnd {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/minus_end.gif') no-repeat left top;
+}
+
+div.treeMinusNone {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/minus_none.gif') no-repeat left top;
+}
+
+div.treeLeaf {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/leafnode.png') no-repeat left top;
+}
+
+div.treeFolderOpen {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/folder-open.png') no-repeat left top;
+}
+
+div.treeFolderClosed {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/folder-closed.png') no-repeat left top;
+}
+
+div.treeLineMiddle {
+ width: 18px;
+ height: 100%;
+ position: static;
+ border: 0px;
+ background: url('tree_images/line_middle.gif') repeat-y left top;
+}
+
+div.treeLineBranch {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/line_branch.gif') no-repeat left top;
+}
+
+div.treeLineEnd {
+ width: 18px;
+ height: 18px;
+ position: static;
+ background: url('tree_images/line_end.gif') no-repeat left top;
+}
+
+span.selected {
+ font-family: helvetica;
+ font-size: x-small;
+ padding-top: 0px;
+ margin-top: 0px;
+ color: #ffffff;
+ background-color: #000077;
+ text-align: left;
+}
+
+span.unselected {
+ font-family: helvetica;
+ font-size: x-small;
+ padding-top: 0px;
+ margin-top: 0px;
+ text-align: left;
+}
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree.js
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/tree.js (rev 0)
+++ modules/remoting/trunk/examples/model/src/main/webapp/tree.js 2010-01-04 06:13:21 UTC (rev 11907)
@@ -0,0 +1,710 @@
+/**
+ * Tree control
+ *
+ * @author Shane Bryzak
+ */
+
+//Package("xw.controls");
+xw = new Object();
+xw.controls = new Object();
+
+// TODO - fully qualified naming is way too verbose, make it shorter somehow
+
+xw.controls.TreeModel = function(rootNode)
+{
+ this.rootNode = rootNode;
+ this.rootNode.setModel(this);
+ this.tree = null;
+ var p = xw.controls.TreeModel.prototype;
+
+ p.getChild = function(parent, index)
+ {
+ return parent.getChildAt(index);
+ }
+
+ p.getChildCount = function(parent)
+ {
+ return parent.getChildCount();
+ }
+
+ p.getIndexOfChild = function(parent, child)
+ {
+ return parent.getIndex(child);
+ }
+
+ p.getRoot = function()
+ {
+ return this.rootNode;
+ }
+
+ p.isLeaf = function(node)
+ {
+ return node.isLeaf();
+ }
+
+ p.setTree = function(tree)
+ {
+ this.tree = tree;
+ }
+
+ p.findNodeByObject = function(object)
+ {
+ return xw.controls.TreeModel.searchChildrenForObject(this.rootNode, object);
+ }
+
+ xw.controls.TreeModel.searchChildrenForObject = function(node, object)
+ {
+ for (var i = 0; i < node.getChildCount(); i++)
+ {
+ var childNode = node.getChildAt(i);
+ if (childNode.getUserObject() == object)
+ return childNode;
+ else if (childNode.getChildCount() > 0)
+ {
+ grandChild = xw.controls.TreeModel.searchChildrenForObject(childNode, object);
+ if (grandChild != null)
+ return grandChild;
+ }
+ }
+ return null;
+ }
+}
+
+xw.controls.TreeNode = function(value, leaf, userObject)
+{
+ this.value = value;
+ this.leaf = leaf ? leaf : false;
+ this.userObject = userObject ? userObject : null;
+ this.children = new Array();
+ this.parent = null;
+ this.expanded = false;
+ this.model = null;
+
+ xw.controls.TreeNode.prototype.getUserObject = function()
+ {
+ return this.userObject;
+ }
+
+ xw.controls.TreeNode.prototype.setUserObject = function(obj)
+ {
+ this.userObject = obj;
+ }
+
+ xw.controls.TreeNode.prototype.setModel = function(model)
+ {
+ this.model = model;
+ }
+
+ xw.controls.TreeNode.prototype.add = function(node)
+ {
+ node.parent = this;
+ this.children.push(node);
+ node.setModel(this.model);
+ }
+
+ xw.controls.TreeNode.prototype.children = function()
+ {
+ return this.children;
+ }
+
+ xw.controls.TreeNode.prototype.getChildAt = function(index)
+ {
+ return this.children[index];
+ }
+
+ xw.controls.TreeNode.prototype.getChildCount = function()
+ {
+ return this.children.length;
+ }
+
+ xw.controls.TreeNode.prototype.getIndex = function(node)
+ {
+ for (var i = 0; i < this.children.length; i++)
+ {
+ if (this.children[i] == node)
+ return i;
+ }
+ return -1;
+ }
+
+ xw.controls.TreeNode.prototype.getParent = function()
+ {
+ return this.parent;
+ }
+
+ xw.controls.TreeNode.prototype.isLeaf = function()
+ {
+ return this.leaf;
+ }
+
+ xw.controls.TreeNode.prototype.remove = function(node)
+ {
+ var found = false;
+ for (var i = 0; i < this.children.length; i++)
+ {
+ if (this.children[i] == node)
+ found = true;
+ if (found && i < this.children.length - 1)
+ this.children[i] = this.children[i + 1];
+ }
+ if (found)
+ {
+ this.children.length = this.children.length - 1;
+ this.model.tree.renderer.removeNode(node);
+ }
+ }
+}
+
+xw.controls.Tree = function(container, model)
+{
+ this.container = (typeof(container) == "object") ? container : document.getElementById(container);
+ this.rootVisible = false;
+ this.model = model;
+ model.setTree(this);
+ this.renderer = new xw.controls.DefaultCellRenderer();
+ this.onSelect = null;
+ this.onDragDrop = null;
+ this.selectedNode = null;
+
+ xw.controls.Tree.prototype.isRootVisible = function()
+ {
+ return this.rootVisible;
+ }
+
+ xw.controls.Tree.prototype.setRootVisible = function(visible)
+ {
+ this.rootVisible = visible;
+ }
+
+ xw.controls.Tree.prototype.paint = function()
+ {
+ this.renderer.render(this.container, this.model.getRoot(), true);
+ }
+
+ xw.controls.Tree.prototype.repaintNode = function(node)
+ {
+ this.renderer.render(null, node, true);
+ }
+
+ xw.controls.Tree.prototype.getModel = function()
+ {
+ return this.model;
+ }
+
+ xw.controls.Tree.prototype.selectNode = function(node)
+ {
+ if (this.selectedNode)
+ this.renderer.renderSelected(this.selectedNode, false);
+ this.selectedNode = node;
+ this.renderer.renderSelected(node, true);
+ if (this.onSelect)
+ this.onSelect(node);
+ }
+
+ xw.controls.Tree.prototype.initiateDragDrop = function(sourceNode, targetNode)
+ {
+ if ((this.onDragDrop && this.onDragDrop(sourceNode, targetNode)) || !this.onDragDrop)
+ this.moveNode(sourceNode, targetNode);
+ }
+
+ xw.controls.Tree.prototype.moveNode = function(sourceNode, targetNode)
+ {
+ var sourceParent = sourceNode.getParent();
+ if (sourceParent != targetNode)
+ {
+ sourceParent.remove(sourceNode);
+
+ targetNode.add(sourceNode);
+
+ targetNode.childrenCell.appendChild(sourceNode.tableCtl);
+ this.repaintNode(sourceParent);
+
+ targetNode.expanded = true;
+ this.repaintNode(targetNode);
+ }
+ }
+}
+
+xw.controls.Tree.mouseDownNode = null;
+xw.controls.Tree.draggedNode = null;
+xw.controls.Tree.mouseDownStartPos = null;
+xw.controls.Tree.dragThreshold = 5;
+xw.controls.Tree.dragDiv = null;
+xw.controls.Tree.targetNode = null;
+
+xw.controls.Tree.util = new Object();
+xw.controls.Tree.util.addEvent = function(ctl, event, func)
+{
+ if (navigator.userAgent.indexOf("MSIE") != -1)
+ ctl.attachEvent("on" + event, func);
+ else
+ ctl.addEventListener(event, func, true);
+}
+
+xw.controls.Tree.util.removeEvent = function(ctl, event, func)
+{
+ if (navigator.userAgent.indexOf("MSIE") != -1)
+ ctl.detachEvent("on" + event, func);
+ else
+ ctl.removeEventListener(event, func, true);
+}
+
+xw.controls.Tree.util.cancelEventBubble = function(event)
+{
+ if (navigator.userAgent.indexOf("MSIE") != -1)
+ {
+ window.event.cancelBubble = true;
+ window.event.returnValue = false;
+ }
+ else
+ event.preventDefault();
+}
+
+xw.controls.Tree.util.setOpacity = function(ctl, percent)
+{
+ if (navigator.userAgent.indexOf("MSIE") != -1)
+ ctl.style.filter = "alpha(opacity=" + percent + ")";
+ else
+ ctl.style.MozOpacity = percent / 100;
+}
+
+xw.controls.Tree.util.fades = new Array();
+xw.controls.Tree.util.fading = false;
+
+xw.controls.Tree.util.startFade = function(fade)
+{
+ fade.valid = true;
+
+ if (fade.value == 0)
+ fade.control.style.display = "";
+
+ xw.controls.Tree.util.fades.push(fade);
+
+ if (!xw.controls.Tree.util.fading)
+ xw.controls.Tree.util.processFades();
+}
+
+xw.controls.Tree.util.fadeIn = function(ctl, step)
+{
+ xw.controls.Tree.util.setOpacity(ctl, 0);
+ xw.controls.Tree.util.startFade({control:ctl,value:0,step:step});
+}
+
+xw.controls.Tree.util.fadeOut = function(ctl, step, onComplete)
+{
+ xw.controls.Tree.util.setOpacity(ctl, 100);
+ xw.controls.Tree.util.startFade({control:ctl,value:100,step:-1 * step,onComplete:onComplete});
+}
+
+xw.controls.Tree.util.processFades = function()
+{
+ xw.controls.Tree.util.fading = true;
+
+ for (var i = 0; i < xw.controls.Tree.util.fades.length; i++)
+ {
+ var fade = xw.controls.Tree.util.fades[i];
+ var done = false;
+
+ if (fade.step < 0) // Fade out
+ {
+ xw.controls.Tree.util.setOpacity(fade.control, Math.max(fade.value, 0));
+ if (fade.value < 0)
+ done = true;
+ }
+ else if (fade.step > 0) // Fade in
+ {
+ xw.controls.Tree.util.setOpacity(fade.control, Math.min(fade.value, 100));
+ if (fade.value > 100)
+ done = true;
+ }
+
+ if (done)
+ {
+ xw.controls.Tree.util.fades.splice(i, 1);
+ if (fade.onComplete)
+ fade.onComplete();
+ }
+ fade.value += fade.step;
+ }
+
+ if (xw.controls.Tree.util.fades.length > 0)
+ setTimeout("xw.controls.Tree.util.processFades()", 50);
+ else
+ xw.controls.Tree.util.fading = false;
+}
+
+xw.controls.Tree.util.getMousePos = function(event)
+{
+ var x, y;
+ if (navigator.userAgent.indexOf("MSIE") != -1)
+ {
+ x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
+ y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
+ }
+ else
+ {
+ x = event.clientX + window.scrollX;
+ y = event.clientY + window.scrollY;
+ }
+ return { x:x, y:y };
+};
+
+xw.controls.Tree.util.calcDistance = function(pos1, pos2)
+{
+ var deltaX = Math.abs(pos1.x - pos2.x);
+ var deltaY = Math.abs(pos1.y - pos2.y);
+ return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
+}
+
+xw.controls.Tree.onMouseDown = function(event, node)
+{
+ xw.controls.Tree.mouseDownStartPos = xw.controls.Tree.util.getMousePos(event);
+ xw.controls.Tree.mouseDownNode = node;
+ xw.controls.Tree.util.addEvent(document, "mousemove", xw.controls.Tree.onMouseMove);
+ xw.controls.Tree.util.addEvent(document, "mouseup", xw.controls.Tree.onMouseUp);
+
+ xw.controls.Tree.util.cancelEventBubble(event);
+}
+
+xw.controls.Tree.onMouseMove = function(event)
+{
+ if (xw.controls.Tree.draggedNode == null)
+ {
+ var distance = xw.controls.Tree.util.calcDistance(xw.controls.Tree.util.getMousePos(event), xw.controls.Tree.mouseDownStartPos);
+ if (distance > xw.controls.Tree.dragThreshold)
+ {
+ xw.controls.Tree.draggedNode = xw.controls.Tree.mouseDownNode;
+ if (xw.controls.Tree.dragDiv == null)
+ {
+ xw.controls.Tree.targetNode = null;
+ xw.controls.Tree.dragDiv = document.createElement("div");
+ xw.controls.Tree.dragDiv.style.position = "absolute";
+ xw.controls.Tree.util.setOpacity(xw.controls.Tree.dragDiv, 40);
+ window.document.body.appendChild(xw.controls.Tree.dragDiv);
+ }
+
+ xw.controls.Tree.draggedNode.renderer.renderClone(xw.controls.Tree.dragDiv, xw.controls.Tree.draggedNode);
+ xw.controls.Tree.dragDiv.style.display = "";
+ var pos = xw.controls.Tree.util.getMousePos(event);
+ xw.controls.Tree.dragDiv.style.left = (pos.x + 10) + "px";
+ xw.controls.Tree.dragDiv.style.top = pos.y + "px";
+ }
+ }
+ else
+ {
+ var pos = xw.controls.Tree.util.getMousePos(event);
+ xw.controls.Tree.dragDiv.style.left = (pos.x + 10) + "px";
+ xw.controls.Tree.dragDiv.style.top = pos.y + "px";
+ }
+}
+
+xw.controls.Tree.onMouseUp = function(event)
+{
+ xw.controls.Tree.util.removeEvent(document, "mousemove", xw.controls.Tree.onMouseMove);
+ xw.controls.Tree.util.removeEvent(document, "mouseup", xw.controls.Tree.onMouseUp);
+
+ xw.controls.Tree.mouseDownStartPos = null;
+
+ if (xw.controls.Tree.dragDiv)
+ xw.controls.Tree.dragDiv.style.display = "none";
+
+ if (xw.controls.Tree.targetNode)
+ {
+ xw.controls.Tree.targetNode.renderer.renderSelected(xw.controls.Tree.targetNode, false);
+ xw.controls.Tree.draggedNode.model.tree.initiateDragDrop(xw.controls.Tree.draggedNode, xw.controls.Tree.targetNode);
+ }
+ else if (xw.controls.Tree.mouseDownNode.model && xw.controls.Tree.mouseDownNode.model.tree && !xw.controls.Tree.draggedNode)
+ xw.controls.Tree.mouseDownNode.model.tree.selectNode(xw.controls.Tree.mouseDownNode);
+
+ xw.controls.Tree.targetNode = null;
+ xw.controls.Tree.draggedNode = null;
+
+ xw.controls.Tree.util.cancelEventBubble(event);
+}
+
+xw.controls.Tree.onMouseOver = function(event, node)
+{
+ if (xw.controls.Tree.draggedNode && xw.controls.Tree.draggedNode != node && !node.isLeaf() && xw.controls.Tree.draggedNode.getParent() != node)
+ {
+ node.renderer.renderSelected(node, true);
+ xw.controls.Tree.targetNode = node;
+ }
+}
+
+xw.controls.Tree.onMouseOut = function(event, node)
+{
+ if (xw.controls.Tree.draggedNode && xw.controls.Tree.draggedNode != node && !node.isLeaf())
+ {
+ node.renderer.renderSelected(node, false);
+ if (xw.controls.Tree.targetNode == node)
+ xw.controls.Tree.targetNode = null;
+ }
+}
+
+xw.controls.DefaultCellRenderer = function()
+{
+ this.plusStartClass = "treePlusStart";
+ this.plusMiddleClass = "treePlusMiddle";
+ this.plusEndClass = "treePlusEnd";
+ this.plusNoneClass = "treePlusNone";
+
+ this.minusStartClass = "treeMinusStart";
+ this.minusMiddleClass = "treeMinusMiddle";
+ this.minusEndClass = "treeMinusEnd";
+ this.minusNoneClass = "treeMinusNone";
+
+ this.lineMiddleClass = "treeLineMiddle";
+ this.lineEndClass = "treeLineEnd";
+ this.lineBranchClass = "treeLineBranch";
+
+ this.leafClass = "treeLeaf";
+ this.folderOpenClass = "treeFolderOpen";
+ this.folderClosedClass = "treeFolderClosed";
+
+ this.onRender = false;
+
+ xw.controls.DefaultCellRenderer.prototype.removeNode = function(node)
+ {
+ node.parent.childrenCell.removeChild(node.tableCtl);
+ }
+
+ xw.controls.DefaultCellRenderer.prototype.render = function(container, node, renderChildren)
+ {
+ if (!node.tableCtl)
+ {
+ node.renderer = this;
+
+ node.tableCtl = document.createElement("table");
+ node.tableCtl.cellSpacing = 0;
+ node.tableCtl.cellPadding = 0;
+
+ node.headerRow = node.tableCtl.insertRow(-1);
+
+ node.branchCell = node.headerRow.insertCell(-1);
+ node.iconCell = node.headerRow.insertCell(-1);
+ node.contentCell = node.headerRow.insertCell(-1);
+
+ node.contentCell.style.textAlign = "left";
+ node.contentCell.style.whiteSpace = "nowrap";
+ node.contentCell.style.cursor = "pointer";
+ node.contentCell.style.verticalAlign = "middle";
+
+ node.branchDiv = document.createElement("div");
+
+ var toggleFunction = function(event) { node.expanded = !node.expanded; node.renderer.toggle(node); };
+
+ xw.controls.Tree.util.addEvent(node.branchDiv, "mousedown", toggleFunction);
+
+ node.branchCell.appendChild(node.branchDiv);
+
+ node.iconDiv = document.createElement("div");
+ node.iconDiv.style.position = "static";
+
+ node.iconCell.style.width = "1px";
+ node.iconCell.appendChild(node.iconDiv);
+
+ node.content = document.createElement("span");
+ node.content.className = "unselected";
+ node.contentText = document.createTextNode(node.value);
+ node.content.appendChild(node.contentText);
+
+ node.contentCell.appendChild(node.content);
+
+ node.childrenRow = node.tableCtl.insertRow(-1);
+ node.childBranchCell = node.childrenRow.insertCell(-1);
+
+ node.childBranchDiv = document.createElement("div");
+ node.childBranchCell.appendChild(node.childBranchDiv);
+
+ node.childrenCell = node.childrenRow.insertCell(-1);
+ node.childrenCell.colSpan = 2;
+
+ var mouseDownFunction = function(event) { xw.controls.Tree.onMouseDown(event, node); };
+ xw.controls.Tree.util.addEvent(node.iconDiv, "mousedown", mouseDownFunction);
+ xw.controls.Tree.util.addEvent(node.contentCell, "mousedown", mouseDownFunction);
+
+ var mouseOverFunction = function(event) { xw.controls.Tree.onMouseOver(event, node); };
+ xw.controls.Tree.util.addEvent(node.iconDiv, "mouseover", mouseOverFunction);
+ xw.controls.Tree.util.addEvent(node.contentCell, "mouseover", mouseOverFunction);
+
+ var mouseOutFunction = function(event) { xw.controls.Tree.onMouseOut(event, node); };
+ xw.controls.Tree.util.addEvent(node.iconDiv, "mouseout", mouseOutFunction);
+ xw.controls.Tree.util.addEvent(node.contentCell, "mouseout", mouseOutFunction);
+ }
+
+ node.contentText.nodeValue = node.value;
+
+ if (container)
+ {
+ var inContainer = false;
+ for (var i = 0; i < container.childNodes.length; i++)
+ {
+ if (container.childNodes[i] == node.tableCtl)
+ {
+ inContainer = true;
+ break;
+ }
+ }
+
+ if (!inContainer)
+ container.appendChild(node.tableCtl);
+ }
+
+ if (!node.isLeaf() && renderChildren)
+ {
+ for (var i = 0; i < node.getChildCount(); i++)
+ this.render(node.childrenCell, node.getChildAt(i), true);
+ }
+
+ // Reset the child branch div height
+ node.childBranchDiv.style.height = "100%";
+
+ var expanded = node.expanded && (node.getChildCount() > 0);
+// node.childrenRow.style.display = expanded ? "" : "none";
+
+ if (node.isLeaf())
+ {
+ if (node.getParent() == null)
+ node.branchDiv.className = this.lineBranchClass;
+ else if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1)
+ node.branchDiv.className = this.lineEndClass;
+ else
+ node.branchDiv.className = this.lineBranchClass;
+
+ node.iconDiv.className = this.leafClass;
+ }
+ else
+ {
+ if (node.getParent() == null)
+ {
+ if (node.getChildCount() > 0)
+ node.branchDiv.className = expanded ? this.minusNoneClass : this.plusNoneClass;
+ else
+ node.branchDiv.className = "";
+ }
+ else if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1)
+ {
+ if (node.getChildCount() > 0)
+ {
+ node.branchDiv.className = expanded ? this.minusEndClass : this.plusEndClass;
+ node.childBranchDiv.className = "";
+ node.childBranchDiv.style.width = "100%";
+ }
+ else
+ node.branchDiv.className = this.lineEndClass;
+ }
+ else
+ {
+ if (node.getChildCount() > 0)
+ {
+ node.childBranchDiv.className = this.lineMiddleClass;
+ node.childBranchDiv.style.height = node.childBranchCell.offsetHeight + "px";
+
+ node.branchDiv.className = expanded ? this.minusMiddleClass : this.plusMiddleClass;
+ }
+ else
+ node.branchDiv.className = this.lineBranchClass;
+ }
+ node.iconDiv.className = expanded ? this.folderOpenClass : this.folderClosedClass;
+ }
+
+ if (node.getParent())
+ node.renderer.render(null, node.getParent());
+
+ if (this.onRender)
+ this.onRender(node);
+
+ node.childrenRow.style.display = expanded ? "" : "none";
+ }
+
+ xw.controls.DefaultCellRenderer.prototype.toggle = function(node)
+ {
+ if (node.expanded)
+ {
+ // Reset the child branch div height
+ node.childrenRow.style.display = "";
+ xw.controls.Tree.util.fadeIn(node.childrenCell, 25);
+ this.decorateNode(node, true);
+ }
+ else
+ {
+ this.decorateNode(node, false);
+ var onComplete = function() { node.childrenRow.style.display = "none"; node.renderer.decorateNode(node, true); };
+ xw.controls.Tree.util.fadeOut(node.childrenCell, 34, onComplete);
+ }
+ }
+
+ xw.controls.DefaultCellRenderer.prototype.decorateNode = function(node, recurseUp)
+ {
+ node.childBranchDiv.style.height = "0px";
+
+ if (node.isLeaf())
+ {
+ if (node.getParent() == null)
+ node.branchDiv.className = this.lineBranchClass;
+ else if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1)
+ node.branchDiv.className = this.lineEndClass;
+ else
+ node.branchDiv.className = this.lineBranchClass;
+
+ node.iconDiv.className = this.leafClass;
+ }
+ else
+ {
+ if (node.getParent() == null)
+ {
+ if (node.getChildCount() > 0)
+ node.branchDiv.className = node.expanded ? this.minusNoneClass : this.plusNoneClass;
+ else
+ node.branchDiv.className = "";
+ }
+ else if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1)
+ {
+ if (node.getChildCount() > 0)
+ {
+ node.branchDiv.className = node.expanded ? this.minusEndClass : this.plusEndClass;
+ node.childBranchDiv.className = "";
+ node.childBranchDiv.style.width = "100%";
+ }
+ else
+ node.branchDiv.className = this.lineEndClass;
+ }
+ else
+ {
+ if (node.getChildCount() > 0)
+ {
+ node.childBranchDiv.className = this.lineMiddleClass;
+ node.childBranchDiv.style.height = node.childBranchCell.offsetHeight + "px";
+
+ node.branchDiv.className = node.expanded ? this.minusMiddleClass : this.plusMiddleClass;
+ }
+ else
+ node.branchDiv.className = this.lineBranchClass;
+ }
+ node.iconDiv.className = node.expanded ? this.folderOpenClass : this.folderClosedClass;
+ }
+
+ if (node.getParent() && recurseUp)
+ node.renderer.decorateNode(node.getParent(), true);
+ }
+
+ xw.controls.DefaultCellRenderer.prototype.renderSelected = function(node, selected)
+ {
+ node.content.className = selected ? "selected" : "unselected";
+ }
+
+ xw.controls.DefaultCellRenderer.prototype.renderClone = function(container, node)
+ {
+ var tbl = document.createElement("table");
+ tbl.cellSpacing = 0;
+ tbl.cellPadding = 0;
+ var row = tbl.insertRow(-1);
+ row.appendChild(node.iconCell.cloneNode(true));
+ row.appendChild(node.contentCell.cloneNode(true));
+
+ if (container.firstChild)
+ container.replaceChild(tbl, container.firstChild);
+ else
+ container.appendChild(tbl);
+ }
+}
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/folder-closed.png
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/folder-closed.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/folder-open.png
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/folder-open.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/leafnode.png
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/leafnode.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_branch.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_branch.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_end.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_end.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_middle.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/line_middle.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_end.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_end.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_middle.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_middle.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_none.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_none.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_start.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/minus_start.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_end.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_end.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_middle.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_middle.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_none.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_none.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_start.gif
===================================================================
(Binary files differ)
Property changes on: modules/remoting/trunk/examples/model/src/main/webapp/tree_images/plus_start.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
14 years, 12 months
Seam SVN: r11906 - in modules/remoting/trunk: src/main/java/org/jboss/seam/remoting and 1 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-03 21:09:18 -0500 (Sun, 03 Jan 2010)
New Revision: 11906
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
add support for resource compression and caching - result of raw size reduction of remote.js from 36.8k to 31k
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-03 23:15:01 UTC (rev 11905)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-04 02:09:18 UTC (rev 11906)
@@ -10,7 +10,7 @@
<h1>Seam Remoting - Model Example</h1>
- <script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script>
+ <script type="text/javascript" src="seam/resource/remoting/resource/remote.js?compress=true"></script>
<script type="text/javascript">
//<![CDATA[
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java 2010-01-03 23:15:01 UTC (rev 11905)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java 2010-01-04 02:09:18 UTC (rev 11906)
@@ -1,5 +1,6 @@
package org.jboss.seam.remoting;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -56,6 +57,8 @@
* one context path.
*/
private Map<String, byte[]> cachedConfig = new HashMap<String, byte[]>();
+
+ private Map<String, byte[]> resourceCache = new HashMap<String, byte[]>();
private static final Logger log = LoggerFactory.getLogger(Remoting.class);
@@ -108,45 +111,91 @@
/**
*
- * @param resourceName
- * String
- * @param out
- * OutputStream
+ * @param resourceName String The name of the resource to serve
+ * @param out OutputStream The OutputStream to write the resource to
*/
- private void writeResource(String resourceName, HttpServletResponse response)
+ private void writeResource(String resourceName, HttpServletResponse response,
+ boolean compress)
throws IOException
{
- // Only allow resource requests for .js files
- if (resourceName.endsWith(".js"))
+ String cacheKey = resourceName + ":" + Boolean.toString(compress);
+ if (!resourceCache.containsKey(cacheKey))
{
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(
- "org/jboss/seam/remoting/" + resourceName);
- try
+ synchronized(resourceCache)
{
- if (in != null)
+ if (!resourceCache.containsKey(cacheKey))
{
- response.setContentType("text/javascript");
-
- byte[] buffer = new byte[1024];
- int read = in.read(buffer);
- while (read != -1)
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ // Only allow resource requests for .js files
+ if (resourceName.endsWith(".js"))
{
- response.getOutputStream().write(buffer, 0, read);
- read = in.read(buffer);
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(
+ "org/jboss/seam/remoting/" + resourceName);
+ try
+ {
+ if (in != null)
+ {
+ response.setContentType("text/javascript");
+
+ byte[] buffer = new byte[1024];
+ int read = in.read(buffer);
+ while (read != -1)
+ {
+ out.write(buffer, 0, read);
+ read = in.read(buffer);
+ }
+
+ resourceCache.put(cacheKey, compress ?
+ compressResource(out.toByteArray()) : out.toByteArray());
+
+ response.getOutputStream().write(resourceCache.get(cacheKey));
+ }
+ else
+ {
+ log.error(String.format("Resource [%s] not found.", resourceName));
+ }
+ }
+ finally
+ {
+ if (in != null) in.close();
+ }
}
- } else
- {
- log.error(String
- .format("Resource [%s] not found.", resourceName));
}
- } finally
- {
- if (in != null)
- in.close();
}
}
+ else
+ {
+ response.getOutputStream().write(resourceCache.get(cacheKey));
+ }
}
+
+ /**
+ * Compresses JavaScript resources by removing comments, cr/lf, leading and
+ * trailing white space.
+ *
+ * @param resourceData The resource data to compress.
+ * @return
+ */
+ private byte[] compressResource(byte[] resourceData)
+ {
+ String resource = new String(resourceData);
+ // Remove comments
+ resource = resource.replaceAll("//[^\\n\\r]*[\\n\\r]", "");
+
+ // Remove leading and trailing space and CR/LF's for lines with a statement terminator
+ resource = resource.replaceAll(";\\s*[\\n\\r]+\\s*", ";");
+
+ // Remove leading and trailing space and CR/LF's for lines with a block terminator
+ resource = resource.replaceAll("}\\s*[\\n\\r]+\\s*", "}");
+
+ // Replace any remaining leading/trailing space and CR/LF with a single space
+ resource = resource.replaceAll("\\s*[\\n\\r]+\\s*", " ");
+
+ return resource.getBytes();
+ }
+
public int getPollTimeout()
{
return pollTimeout;
@@ -231,7 +280,10 @@
if (REMOTING_RESOURCE_PATH.equals(path))
{
- writeResource(resource, response);
+ String compressParam = request.getParameter("compress");
+ boolean compress = compressParam != null && "true".equals(compressParam);
+
+ writeResource(resource, response, compress);
if ("remote.js".equals(resource))
{
appendConfig(response.getOutputStream(), request
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 23:15:01 UTC (rev 11905)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-04 02:09:18 UTC (rev 11906)
@@ -6,7 +6,7 @@
PATH_SUBSCRIPTION: "/subscription",
PATH_MODEL: "/model",
PATH_POLL: "/poll"
-}
+};
Seam.createBean = function(name) {
if (!Seam.beans[name]) return null;
@@ -18,31 +18,31 @@
}
}
return b;
-}
+};
Seam.getBeanType = function(obj) {
for (var b in Seam.beans) {
if (obj instanceof Seam.beans[b]) return Seam.beans[b];
}
return undefined;
-}
+};
Seam.getBeanName = function(obj) {
var t = Seam.getBeanType(obj);
return t ? t.__name : undefined;
-}
+};
Seam.isBeanRegistered = function(name) {
return Seam.beans[name] != null;
-}
+};
Seam.createSetterMethod = function(fieldName) {
return function(value) { this[fieldName] = value; };
-}
+};
Seam.createGetterMethod = function(fieldName) {
return function() { return this[fieldName]; };
-}
+};
Seam.registerBean = function(name, metadata, methods) {
if (Seam.isBeanRegistered(name)) return;
@@ -72,7 +72,7 @@
}
}
Seam.beans[name] = t;
-}
+};
Seam.importBeans = function() {
var names = [];
@@ -95,7 +95,7 @@
var envelope = Seam.createEnvelope(Seam.createHeader(c.id), c.data);
Seam.pendingCalls.put(c.id, c);
Seam.sendAjaxRequest(envelope, Seam.PATH_EXECUTE, Seam.processResponse, false);
-}
+};
Seam.createImportBeansCall = function(names, callback, originalCall) {
var n = "org.jboss.seam.remoting.BeanMetadata";
@@ -108,12 +108,12 @@
c.handler = Seam.processImportBeansResponse;
if (originalCall) c.originalCall = originalCall;
return c;
-}
+};
Seam.getBeanMetadata = function(obj) {
var b = Seam.getBeanType(obj);
return b ? b.__metadata : undefined;
-}
+};
Seam.Xml = {
childNode: function(e, tag) {
@@ -128,7 +128,7 @@
}
return n;
}
-}
+};
Seam.extractEncodedSessionId = function(url) {
if (url.indexOf(';jsessionid=') >= 0) {
@@ -136,7 +136,7 @@
return url.substring(url.indexOf(';jsessionid=') + 12, qpos >= 0 ? qpos : url.length);
}
return null;
-}
+};
Seam.encodedSessionId = Seam.extractEncodedSessionId(window.location.href);
@@ -155,16 +155,16 @@
if (Seam.debugWindow) {
Seam.debugWindow.document.write("<pre>" + (new Date()) + ": " + msg.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + "</pre><br/>");
}
-}
+};
Seam.Context = function() {
this.conversationId = null;
this.callId = null;
- Seam.Context.prototype.setConversationId = function(conversationId) { this.conversationId = conversationId; }
- Seam.Context.prototype.getConversationId = function() { return this.conversationId; }
- Seam.Context.prototype.setCallId = function(callId) { this.callId = callId; }
- Seam.Context.prototype.getCallId = function() { return this.callId; }
-}
+ Seam.Context.prototype.setConversationId = function(conversationId) { this.conversationId = conversationId; };
+ Seam.Context.prototype.getConversationId = function() { return this.conversationId; };
+ Seam.Context.prototype.setCallId = function(callId) { this.callId = callId; };
+ Seam.Context.prototype.getCallId = function() { return this.callId; };
+};
Seam.context = new Seam.Context();
Seam.Exception = function(msg) {
@@ -172,44 +172,50 @@
Seam.Exception.prototype.getMessage = function() {
return this.message;
}
-}
+};
Seam.equals = function(v1, v2) {
if (v1 == v2) return true;
if (v1 instanceof Date && v2 instanceof Date &&
v1.getTime() == v2.getTime()) return true;
return false;
-}
+};
Seam.Map = function() {
this.elements = [];
+
Seam.Map.prototype.size = function() {
return this.elements.length;
- }
+ };
+
Seam.Map.prototype.isEmpty = function() {
return this.elements.length == 0;
- }
+ };
+
Seam.Map.prototype.keySet = function() {
var keySet = [];
for (var i=0; i<this.elements.length; i++) {
keySet[keySet.length] = this.elements[i].key;
}
return keySet;
- }
+ };
+
Seam.Map.prototype.values = function() {
var vals = [];
for (var i=0; i<this.elements.length; i++) {
vals.push(this.elements[i].value);
}
return vals;
- }
+ };
+
Seam.Map.prototype.get = function(key) {
for (var i=0; i<this.elements.length; i++) {
var e = this.elements[i];
if (Seam.equals(e.key, key)) return e.value;
}
return null;
- }
+ };
+
Seam.Map.prototype.put = function(key, value) {
for (var i=0; i<this.elements.length; i++) {
if (Seam.equals(this.elements[i].key, key)) {
@@ -218,7 +224,8 @@
}
}
this.elements.push({key:key,value:value});
- }
+ };
+
Seam.Map.prototype.remove = function(key) {
for (var i=0; i<this.elements.length; i++) {
if (Seam.equals(this.elements[i].key, key)) {
@@ -226,14 +233,15 @@
break;
}
}
- }
+ };
+
Seam.Map.prototype.contains = function(key) {
for (var i=0; i<this.elements.length; i++) {
if (Seam.equals(this.elements[i].key, key)) return true;
}
return false;
- }
-}
+ };
+};
Seam.serializeValue = function(v, type, refs) {
if (v == null) return "<null/>";
@@ -266,7 +274,7 @@
return "<str>" + encodeURIComponent(v) + "</str>";
}
}
-}
+};
Seam.serializeBag = function(v, refs) {
var d = "<bag>";
@@ -275,7 +283,7 @@
}
d += "</bag>";
return d;
-}
+};
Seam.serializeMap = function(v, refs) {
var d = "<map>";
@@ -286,14 +294,14 @@
}
d += "</map>";
return d;
-}
+};
Seam.serializeDate = function(v) {
var zeroPad = function(val, digits) { while (("" + val).length < digits) val = "0" + val; return val; };
return "<date>" + v.getFullYear() + zeroPad(v.getMonth() + 1, 2) + zeroPad(v.getDate(), 2) +
zeroPad(v.getHours(), 2) + zeroPad(v.getMinutes(), 2) + zeroPad(v.getSeconds(), 2) +
zeroPad(v.getMilliseconds(), 3) +"</date>";
-}
+};
Seam.getTypeRef = function(obj, refs) {
var refId = -1;
@@ -308,7 +316,7 @@
refs[refId] = obj;
}
return "<ref id=\"" + refId + "\"/>";
-}
+};
Seam.serializeType = function(obj, refs) {
var t = Seam.getBeanType(obj);
@@ -324,7 +332,7 @@
}
d += "</bean>";
return d;
-}
+};
Seam.createCall = function(component, methodName, params, callback, exceptionHandler) {
var callId = "" + Seam.__callId++;
@@ -349,7 +357,7 @@
}
d += "</refs></call>";
return {data: d, id: callId, callback: callback, exceptionHandler: exceptionHandler, handler: Seam.preProcessCallResponse};
-}
+};
Seam.createHeader = function(callId) {
var h = "<context><callId>" + callId + "</callId>";
@@ -358,7 +366,7 @@
}
h += "</context>";
return h;
-}
+};
Seam.createEnvelope = function(header, body) {
var d = "<envelope>";
@@ -366,7 +374,7 @@
if (body) d += "<body>" + body + "</body>";
d += "</envelope>";
return d;
-}
+};
Seam.__callId = 0;
Seam.pendingCalls = new Seam.Map();
@@ -381,7 +389,7 @@
}, 0);
c.asyncReq.abort();
}
-}
+};
Seam.execute = function(component, methodName, params, callback, exceptionHandler) {
var c = Seam.createCall(component, methodName, params, callback, exceptionHandler);
@@ -389,7 +397,7 @@
Seam.pendingCalls.put(c.id, c);
Seam.sendAjaxRequest(envelope, Seam.PATH_EXECUTE, Seam.processResponse, false);
return c;
-}
+};
Seam.sendAjaxRequest = function(env, path, callback, silent) {
Seam.log("Request packet:\n" + env);
@@ -439,13 +447,13 @@
Seam.displayError(r.status);
}
}
- }
+ };
if (Seam.encodedSessionId) {
path += ';jsessionid=' + Seam.encodedSessionId;
}
r.open("POST", Seam.resourcePath + path, true);
r.send(env);
-}
+};
Seam.processImportBeansResponse = function(call) {
var cn = Seam.Xml.childNode;
@@ -483,7 +491,7 @@
call.originalCall.handler(call.originalCall);
}
}
-}
+};
Seam.preProcessCallResponse = function(call) {
var cn = Seam.Xml.childNode;
@@ -504,7 +512,7 @@
}
}
}
-}
+};
Seam.processCallResponse = function(call) {
var cn = Seam.Xml.childNode;
@@ -522,7 +530,7 @@
var v = Seam.unmarshalValue(valueNode.firstChild, refs);
call.callback(v, call.context);
}
-}
+};
Seam.preProcessModelResponse = function(call) {
var cn = Seam.Xml.childNode;
@@ -543,7 +551,7 @@
}
}
}
-}
+};
Seam.preProcessModelExpandResponse = function(call) {
var cn = Seam.Xml.childNode;
@@ -564,7 +572,7 @@
}
}
}
-}
+};
Seam.processModelExpandResponse = function(call) {
Seam.pendingCalls.remove(call.callId);
@@ -574,7 +582,7 @@
var n = cn(b, "model");
if (call.model) call.model.processExpandResponse(n, call.refId, call.property, call.callback);
}
-}
+};
Seam.processModelResponse = function(call) {
Seam.pendingCalls.remove(call.callId);
@@ -584,15 +592,15 @@
var n = cn(b, "model");
if (call.model) call.model.processResponse(n, call.callback);
}
-}
+};
Seam.displayError = function(code) {
alert("There was an error processing your request. Error code: " + code);
-}
+};
Seam.setCallback = function(component, methodName, callback) {
component.__callback[methodName] = callback;
-}
+};
Seam.processResponse = function(doc) {
var cn = Seam.Xml.childNode;
@@ -613,14 +621,14 @@
}
}
}
-}
+};
Seam.unmarshalContext = function(ctxNode, context) {
var c = Seam.Xml.childNode(ctxNode, "conversationId");
if (c) context.setConversationId(c.firstChild.nodeValue);
c = Seam.Xml.childNode(ctxNode, "callId");
if (c) context.setCallId(c.firstChild.nodeValue);
-}
+};
Seam.validateRefs = function(refsNode) {
var unknowns = [];
@@ -635,7 +643,7 @@
}
}
return unknowns;
-}
+};
Seam.unmarshalRefs = function(refsNode, refs) {
if (!refsNode) return;
@@ -664,7 +672,7 @@
}
}
return refs;
-}
+};
Seam.unmarshalValue = function(element, refs) {
switch (element.tagName) {
@@ -702,7 +710,7 @@
case "undefined": return undefined;
default: return null;
}
-}
+};
Seam.cloneObject = function(obj, refMap) {
if (refMap && refMap.contains(obj)) return refMap.get(obj);
@@ -726,7 +734,7 @@
return c;
}
return obj;
-}
+};
Seam.deserializeDate = function(val) {
var d = new Date();
@@ -738,7 +746,7 @@
d.setSeconds(parseInt(val.substring(12,14), 10));
d.setMilliseconds(parseInt(val.substring(14,17), 10));
return d;
-}
+};
Seam.loadingMsgDiv = null;
Seam.loadingMessage = "Please wait...";
@@ -764,11 +772,11 @@
Seam.loadingMsgDiv.innerHTML = Seam.loadingMessage;
Seam.loadingMsgDiv.style.visibility = 'visible';
}
-}
+};
Seam.hideLoadingMessage = function() {
if (Seam.loadingMsgDiv) Seam.loadingMsgDiv.style.visibility = 'hidden';
-}
+};
Seam.Action = function() {
this.beanType = null;
@@ -776,34 +784,39 @@
this.method = null;
this.params = [];
this.expression = null;
+
Seam.Action.prototype.setBeanType = function(beanType) {
this.beanType = beanType;
return this;
- }
+ };
+
Seam.Action.prototype.setQualifiers = function(qualifiers) {
this.qualifiers = qualifiers;
return this;
- }
+ };
+
Seam.Action.prototype.setMethod = function(method) {
this.method = method;
return this;
- }
+ };
+
Seam.Action.prototype.addParam = function(param) {
this.params.push(param);
return this;
- }
+ };
+
Seam.Action.prototype.setExpression = function(expr) {
this.expression = expr;
return this;
- }
-}
+ };
+};
Seam.Changeset = function() {
this.propertyChange = new Seam.Map();
Seam.Changeset.prototype.addProperty = function(name, val) {
this.propertyChange.put(name, val);
- }
-}
+ };
+};
Seam.Delta = function(model) {
this.model = model;
@@ -843,7 +856,7 @@
}
}
return false;
- }
+ };
Seam.Delta.prototype.registerPropertyChange = function(obj, prop) {
var cs = this.refs.get(obj);
@@ -852,7 +865,7 @@
this.refs.put(obj, cs);
}
cs.addProperty(prop, obj[prop]);
- }
+ };
Seam.Delta.prototype.scanForChanges = function(obj) {
if (obj == null || this.refs.contains(obj)) return;
@@ -886,14 +899,14 @@
}
}
}
- }
+ };
Seam.Delta.prototype.getSourceObject = function(obj) {
for (var i=0;i<this.model.workingRefs.length; i++) {
if (obj == this.model.workingRefs[i]) return this.model.sourceRefs[i];
}
return null;
- }
+ };
Seam.Delta.prototype.buildRefs = function() {
var refs = [];
@@ -901,8 +914,8 @@
refs.push(this.refs.elements[i]);
}
return refs;
- }
-}
+ };
+};
Seam.Model = function() {
this.id = null;
@@ -914,7 +927,7 @@
Seam.Model.prototype.addExpression = function(alias, expr) {
this.expressions.push({alias: alias, expr: expr});
- }
+ };
Seam.Model.prototype.getValue = function(alias) {
for (var i=0; i<this.values.length; i++) {
@@ -923,7 +936,7 @@
}
}
return null;
- }
+ };
Seam.Model.prototype.addBean = function(alias, bean) {
var q = null;
@@ -934,7 +947,7 @@
}
}
this.beans.push({alias: alias, bean: bean, qualifiers: q});
- }
+ };
Seam.Model.prototype.addBeanProperty = function(alias, bean, property) {
var q = null;
@@ -945,14 +958,14 @@
}
}
this.beans.push({alias: alias, bean: bean, property: property, qualifiers: q});
- }
+ };
Seam.Model.prototype.fetch = function(action, cb) {
var r = this.createFetchRequest(action, cb);
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
- }
+ };
Seam.Model.prototype.createFetchRequest = function(a, cb) {
var callId = "" + Seam.__callId++;
@@ -1006,7 +1019,7 @@
}
d += "</model>";
return {data:d, id:callId, model:this, handler: Seam.preProcessModelResponse, callback: cb};
- }
+ };
Seam.Model.prototype.processResponse = function(modelNode, cb) {
var refsNode = Seam.Xml.childNode(modelNode, "refs");
@@ -1019,7 +1032,7 @@
this.values.push({alias:valueNodes[i].getAttribute("alias"),value:value, refIndex:i});
}
if (cb) cb(this);
- }
+ };
Seam.Model.prototype.applyUpdates = function(a, cb) {
var d = new Seam.Delta(this);
@@ -1030,7 +1043,7 @@
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
- }
+ };
Seam.Model.prototype.createApplyRequest = function(a, delta, cb) {
var callId = "" + Seam.__callId++;
@@ -1086,14 +1099,14 @@
}
d += "</model>";
return {data:d, id:callId, model:this, handler: Seam.preProcessModelResponse, callback: cb};
- }
+ };
Seam.Model.prototype.getRefId = function(v) {
for (var i=0; i<this.workingRefs.length; i++) {
if (this.workingRefs[i] == v) return i;
}
return -1;
- }
+ };
Seam.Model.prototype.expand = function(v, p, cb) {
if (v[p] != undefined) return;
@@ -1102,14 +1115,14 @@
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
- }
+ };
Seam.Model.prototype.createExpandRequest = function(refId, propName, cb) {
var callId = "" + Seam.__callId++;
var d = "<model id=\"" + this.id + "\" operation=\"expand\">" +
"<ref id=\"" + refId + "\"><member name=\"" + propName + "\"/></ref></model>";
return {data: d, id: callId, model: this, refId: refId, property: propName, handler: Seam.preProcessModelExpandResponse, callback: cb};
- }
+ };
Seam.Model.prototype.processExpandResponse = function(modelNode, refId, propName, cb) {
var refsNode = Seam.Xml.childNode(modelNode, "refs");
@@ -1119,5 +1132,5 @@
this.sourceRefs[refId][propName] = Seam.unmarshalValue(resultNode.firstChild,this.sourceRefs);
this.workingRefs[refId][propName] = Seam.unmarshalValue(resultNode.firstChild,this.workingRefs);
if (cb) cb(this);
- }
-}
\ No newline at end of file
+ };
+};
\ No newline at end of file
14 years, 12 months
Seam SVN: r11905 - modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-03 18:15:01 -0500 (Sun, 03 Jan 2010)
New Revision: 11905
Modified:
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
callbacks should be call-scoped
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 23:01:06 UTC (rev 11904)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 23:15:01 UTC (rev 11905)
@@ -572,7 +572,7 @@
var b = cn(call.response.documentElement, "body");
if (b) {
var n = cn(b, "model");
- if (call.model) call.model.processExpandResponse(n, call.refId, call.property);
+ if (call.model) call.model.processExpandResponse(n, call.refId, call.property, call.callback);
}
}
@@ -582,7 +582,7 @@
var b = cn(call.response.documentElement, "body");
if (b) {
var n = cn(b, "model");
- if (call.model) call.model.processResponse(n);
+ if (call.model) call.model.processResponse(n, call.callback);
}
}
@@ -911,7 +911,6 @@
this.values = [];
this.sourceRefs = [];
this.workingRefs = [];
- this.callback = null;
Seam.Model.prototype.addExpression = function(alias, expr) {
this.expressions.push({alias: alias, expr: expr});
@@ -948,15 +947,14 @@
this.beans.push({alias: alias, bean: bean, property: property, qualifiers: q});
}
- Seam.Model.prototype.fetch = function(action, callback) {
- this.callback = callback;
- var r = this.createFetchRequest(action);
+ Seam.Model.prototype.fetch = function(action, cb) {
+ var r = this.createFetchRequest(action, cb);
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
}
- Seam.Model.prototype.createFetchRequest = function(a) {
+ Seam.Model.prototype.createFetchRequest = function(a, cb) {
var callId = "" + Seam.__callId++;
var d = "<model operation=\"fetch\">";
var refs = [];
@@ -1007,10 +1005,10 @@
}
}
d += "</model>";
- return {data:d, id:callId, model:this, handler: Seam.preProcessModelResponse};
+ return {data:d, id:callId, model:this, handler: Seam.preProcessModelResponse, callback: cb};
}
- Seam.Model.prototype.processResponse = function(modelNode) {
+ Seam.Model.prototype.processResponse = function(modelNode, cb) {
var refsNode = Seam.Xml.childNode(modelNode, "refs");
this.id = modelNode.getAttribute("id");
var valueNodes = Seam.Xml.childNodes(modelNode, "value");
@@ -1020,21 +1018,21 @@
var value = Seam.unmarshalValue(valueNodes[i].firstChild,this.workingRefs);
this.values.push({alias:valueNodes[i].getAttribute("alias"),value:value, refIndex:i});
}
- if (this.callback) this.callback(this);
+ if (cb) cb(this);
}
- Seam.Model.prototype.applyUpdates = function(a) {
+ Seam.Model.prototype.applyUpdates = function(a, cb) {
var d = new Seam.Delta(this);
for (var i=0; i<this.values.length; i++) {
d.scanForChanges(this.values[i].value);
}
- var r = this.createApplyRequest(a, d);
+ var r = this.createApplyRequest(a, d, cb);
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
}
- Seam.Model.prototype.createApplyRequest = function(a, delta) {
+ Seam.Model.prototype.createApplyRequest = function(a, delta, cb) {
var callId = "" + Seam.__callId++;
var d = "<model id=\"" + this.id + "\" operation=\"apply\">";
var refs = delta.buildRefs();
@@ -1087,7 +1085,7 @@
d += "</refs>";
}
d += "</model>";
- return {data:d, id:callId, model:this, handler: Seam.preProcessModelResponse};
+ return {data:d, id:callId, model:this, handler: Seam.preProcessModelResponse, callback: cb};
}
Seam.Model.prototype.getRefId = function(v) {
@@ -1097,30 +1095,29 @@
return -1;
}
- Seam.Model.prototype.expand = function(v, p, callback) {
+ Seam.Model.prototype.expand = function(v, p, cb) {
if (v[p] != undefined) return;
var refId = this.getRefId(v);
- var r = this.createExpandRequest(refId, p);
+ var r = this.createExpandRequest(refId, p, cb);
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
- this.callback = callback;
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
}
- Seam.Model.prototype.createExpandRequest = function(refId, propName) {
+ Seam.Model.prototype.createExpandRequest = function(refId, propName, cb) {
var callId = "" + Seam.__callId++;
var d = "<model id=\"" + this.id + "\" operation=\"expand\">" +
"<ref id=\"" + refId + "\"><member name=\"" + propName + "\"/></ref></model>";
- return {data: d, id: callId, model: this, refId: refId, property: propName, handler: Seam.preProcessModelExpandResponse};
+ return {data: d, id: callId, model: this, refId: refId, property: propName, handler: Seam.preProcessModelExpandResponse, callback: cb};
}
- Seam.Model.prototype.processExpandResponse = function(modelNode, refId, propName) {
+ Seam.Model.prototype.processExpandResponse = function(modelNode, refId, propName, cb) {
var refsNode = Seam.Xml.childNode(modelNode, "refs");
var resultNode = Seam.Xml.childNode(modelNode, "result");
Seam.unmarshalRefs(refsNode, this.sourceRefs);
Seam.unmarshalRefs(refsNode, this.workingRefs);
this.sourceRefs[refId][propName] = Seam.unmarshalValue(resultNode.firstChild,this.sourceRefs);
this.workingRefs[refId][propName] = Seam.unmarshalValue(resultNode.firstChild,this.workingRefs);
- if (this.callback) this.callback(this);
+ if (cb) cb(this);
}
}
\ No newline at end of file
14 years, 12 months
Seam SVN: r11904 - modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-03 18:01:06 -0500 (Sun, 03 Jan 2010)
New Revision: 11904
Modified:
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
fix apply request marshalling
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 14:44:48 UTC (rev 11903)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 23:01:06 UTC (rev 11904)
@@ -320,7 +320,7 @@
var meta = Seam.getBeanMetadata(obj);
for (var i=0; i<meta.length; i++) {
d += "<member name=\"" + meta[i].field + "\">" +
- Seam.serializeValue(obj[meta[i].field], meta[i].type, refs) + "</member>\n";
+ Seam.serializeValue(obj[meta[i].field], meta[i].type, refs) + "</member>";
}
d += "</bean>";
return d;
@@ -857,8 +857,8 @@
Seam.Delta.prototype.scanForChanges = function(obj) {
if (obj == null || this.refs.contains(obj)) return;
this.refs.put(obj, null);
+ var src = this.getSourceObject(obj);
if (Seam.getBeanType(obj)) {
- var src = this.getSourceObject(obj);
var m = Seam.getBeanMetadata(obj);
for (var i=0; i<m.length; i++) {
var f=m[i].field;
@@ -867,16 +867,14 @@
if (t == "bag" || t == "map" || t == "bean") this.scanForChanges(obj[f]);
}
} else if (obj instanceof Array) {
- var src = this.getSourceObject(obj);
- if (!this.testEqual(obj, src)) this.refs.put(obj, true);
+ if (src && !this.testEqual(obj, src)) this.refs.put(obj, true);
for (var i=0; i<obj.length; i++) {
if (Seam.getBeanType(obj[i]) || obj[i] instanceof Array || obj[i] instanceof Seam.Map) {
this.scanForChanges(obj[i]);
}
}
} else if (obj instanceof Seam.Map) {
- var src = this.getSourceObject(obj);
- if (!this.testEqual(obj, src)) this.refs.put(obj, true);
+ if (src && !this.testEqual(obj, src)) this.refs.put(obj, true);
for (var i=0; i<obj.elements.length; i++) {
var k = obj.elements[i].key;
var v = obj.elements[i].value;
14 years, 12 months
Seam SVN: r11903 - in modules/remoting/trunk/src/main: resources/org/jboss/seam/remoting and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-03 09:44:48 -0500 (Sun, 03 Jan 2010)
New Revision: 11903
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
uninitialized collections should be undefined
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java 2010-01-03 13:52:56 UTC (rev 11902)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java 2010-01-03 14:44:48 UTC (rev 11903)
@@ -36,6 +36,8 @@
private static final byte[] ELEMENT_TAG_OPEN = "<element>".getBytes();
private static final byte[] ELEMENT_TAG_CLOSE = "</element>".getBytes();
+ private static final byte[] UNDEFINED_TAG = "<undefined/>".getBytes();
+
private boolean loadLazy = false;
public void setLoadLazy(boolean loadLazy)
@@ -46,18 +48,18 @@
@SuppressWarnings("unchecked")
public void marshal(OutputStream out) throws IOException
{
- out.write(BAG_TAG_OPEN);
-
// Fix to prevent uninitialized lazy loading in Hibernate
if (value instanceof PersistentCollection && !loadLazy)
{
if (!((PersistentCollection) value).wasInitialized())
{
- out.write(BAG_TAG_CLOSE);
+ out.write(UNDEFINED_TAG);
return;
}
}
+ out.write(BAG_TAG_OPEN);
+
Collection<Object> vals = null;
// If the value is an array, convert it to a Collection
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 13:52:56 UTC (rev 11902)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 14:44:48 UTC (rev 11903)
@@ -699,6 +699,7 @@
}
return m;
case "date": return Seam.deserializeDate(element.firstChild.nodeValue);
+ case "undefined": return undefined;
default: return null;
}
}
@@ -809,7 +810,6 @@
this.refs = new Seam.Map();
Seam.Delta.prototype.testEqual = function(v1, v2) {
- var eq = this.testEqual;
if (v1 == null) return v2 == null;
switch (typeof(v1)) {
case "number":
@@ -827,7 +827,7 @@
if (!(v2 instanceof Array)) return false;
if (v1.length != v2.length) return false;
for (var i=0; i<v1.length; i++) {
- if (!eq(v1[i], v2[i])) return false;
+ if (!this.testEqual(v1[i], v2[i])) return false;
}
return true;
} else if (v1 instanceof Seam.Map) {
@@ -835,8 +835,8 @@
if (v1.size() != v2.size()) return false;
for (var i=0; i<v1.size(); i++) {
var e = v1.elements[i];
- if (Seam.getBeanType(e.key) && eq(e.value, v2.get(this.getSourceObject(e.key)))) break;
- if (eq(e.value, v2.get(e.key)) && (e.value != null || v2.contains(e.key))) break;
+ if (Seam.getBeanType(e.key) && this.testEqual(e.value, v2.get(this.getSourceObject(e.key)))) break;
+ if (this.testEqual(e.value, v2.get(e.key)) && (e.value != null || v2.contains(e.key))) break;
return false;
}
return true;
@@ -1100,6 +1100,7 @@
}
Seam.Model.prototype.expand = function(v, p, callback) {
+ if (v[p] != undefined) return;
var refId = this.getRefId(v);
var r = this.createExpandRequest(refId, p);
var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
@@ -1117,11 +1118,11 @@
Seam.Model.prototype.processExpandResponse = function(modelNode, refId, propName) {
var refsNode = Seam.Xml.childNode(modelNode, "refs");
- var valueNode = Seam.Xml.childNode(modelNode, "value");
+ var resultNode = Seam.Xml.childNode(modelNode, "result");
Seam.unmarshalRefs(refsNode, this.sourceRefs);
Seam.unmarshalRefs(refsNode, this.workingRefs);
- this.sourceRefs[refId][propName] = Seam.unmarshalValue(valueNode.firstChild,this.sourceRefs);
- this.workingRefs[refId][propName] = Seam.unmarshalValue(valueNode.firstChild,this.workingRefs);
+ this.sourceRefs[refId][propName] = Seam.unmarshalValue(resultNode.firstChild,this.sourceRefs);
+ this.workingRefs[refId][propName] = Seam.unmarshalValue(resultNode.firstChild,this.workingRefs);
if (this.callback) this.callback(this);
}
}
\ No newline at end of file
14 years, 12 months
Seam SVN: r11902 - in sandbox/trunk/modules/scheduling: src/main/java/org/jboss/seam/scheduling/events and 2 other directories.
by seam-commits@lists.jboss.org
Author: peteroyle
Date: 2010-01-03 08:52:56 -0500 (Sun, 03 Jan 2010)
New Revision: 11902
Modified:
sandbox/trunk/modules/scheduling/pom.xml
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/AbstractTimeEvent.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Hour.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Minute.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Second.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/QuartzStarter.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/AbstractTimeEventJob.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/HourJob.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/MinuteJob.java
sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/SecondJob.java
Log:
Second, Minute and Hour events record which second, minute or hour they were fired on as the 'value' property. Also included some new dependencies of the weld-core-test project for use during testing only.
Modified: sandbox/trunk/modules/scheduling/pom.xml
===================================================================
--- sandbox/trunk/modules/scheduling/pom.xml 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/pom.xml 2010-01-03 13:52:56 UTC (rev 11902)
@@ -112,6 +112,20 @@
<version>1.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ <!-- required by weld-core-test ... -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- ... required by weld-core-test -->
</dependencies>
</project>
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/AbstractTimeEvent.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/AbstractTimeEvent.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/AbstractTimeEvent.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -31,6 +31,8 @@
{
private long timeFired;
+ // the value of the second, miute or hour, as the case may be
+ protected int value;
/**
* Create an instance of some subclass of AbstractTimeEvent using the given timeFired.
@@ -51,6 +53,14 @@
}
/**
+ * @return The value of the second, minute or hour fired.
+ */
+ public int getValue()
+ {
+ return value;
+ }
+
+ /**
*
* @return a String representation of this instance, showing the event type and the
* time at which the event was fired (epoch).
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Hour.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Hour.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Hour.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -27,9 +27,10 @@
* Creates an instance of Hour using the given value of timeFired.
* @param timeFired The time at which the event was fired.
*/
- public Hour(long timeFired)
+ public Hour(long timeFired, int second)
{
super(timeFired);
+ this.value = second;
}
}
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Minute.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Minute.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Minute.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -27,8 +27,9 @@
* Creates an instance of Minute using the given value of timeFired.
* @param timeFired The time at which the event was fired.
*/
- public Minute(long timeFired)
+ public Minute(long timeFired, int second)
{
super(timeFired);
+ this.value = second;
}
}
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Second.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Second.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/events/Second.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -27,9 +27,10 @@
* Creates an instance of Second using the given value of timeFired.
* @param timeFired The time at which the event was fired.
*/
- public Second(long timeFired)
+ public Second(long timeFired, int second)
{
super(timeFired);
+ this.value = second;
}
-
+
}
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/QuartzStarter.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/QuartzStarter.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/QuartzStarter.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -131,17 +131,17 @@
// Start scheduler for Second every second
final Trigger secondTrigger = new SimpleTrigger("jcdiTickerTrigger", TICKER_JOB_GROUP, startTime, null, SimpleTrigger.REPEAT_INDEFINITELY, 1000);
- Set tickObservers = manager.resolveObserverMethods(new Second(0), new EveryBinding());
+ Set tickObservers = manager.resolveObserverMethods(new Second(0, 0), new EveryBinding());
scheduleTicks(tickObservers, "second-trigger", manager, secondTrigger, SecondJob.class);
// Start scheduler for Minute every minute
- Set minTickObservers = manager.resolveObserverMethods(new Minute(0), new EveryBinding());
+ Set minTickObservers = manager.resolveObserverMethods(new Minute(0, 0), new EveryBinding());
final CronTrigger minTrigger = new CronTrigger("jcdiMinutelyTickerTrigger", TICKER_JOB_GROUP, "0 * * ? * *");
minTrigger.setStartTime(startTime);
scheduleTicks(minTickObservers, "minute-trigger", manager, minTrigger, MinuteJob.class);
// Start scheduler for Hour every hour
- Set hrlyTickObservers = manager.resolveObserverMethods(new Hour(0), new EveryBinding());
+ Set hrlyTickObservers = manager.resolveObserverMethods(new Hour(0, 0), new EveryBinding());
final CronTrigger hrTrigger = new CronTrigger("jcdiHourlyTickerTrigger", TICKER_JOB_GROUP, "0 0 * ? * *");
hrTrigger.setStartTime(startTime);
scheduleTicks(hrlyTickObservers, "hour-trigger", manager, hrTrigger, HourJob.class);
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/AbstractTimeEventJob.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/AbstractTimeEventJob.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/AbstractTimeEventJob.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -17,6 +17,8 @@
package org.jboss.seam.scheduling.quartz.jobs;
import java.lang.annotation.Annotation;
+import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.Set;
import javax.enterprise.inject.spi.BeanManager;
import org.jboss.seam.scheduling.quartz.*;
@@ -37,6 +39,8 @@
public abstract class AbstractTimeEventJob implements Job
{
+ protected int value = 0;
+ protected final GregorianCalendar gc = new GregorianCalendar();
private Log log = LogFactory.getLog(SecondJob.class);
/**
@@ -56,6 +60,7 @@
public void execute(JobExecutionContext context) throws JobExecutionException
{
BeanManager manager = (BeanManager) context.getJobDetail().getJobDataMap().get(QuartzStarter.MANAGER_NAME);
+ gc.setTime(new Date());
final AbstractTimeEvent eventPayload = createEventPayload();
for (Annotation binding : (Set<Annotation>)context.getJobDetail().getJobDataMap().get(QuartzStarter.BINDINGS)) {
log.trace("Firing time event for " + eventPayload + " with binding " + binding);
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/HourJob.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/HourJob.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/HourJob.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -16,6 +16,7 @@
*/
package org.jboss.seam.scheduling.quartz.jobs;
+import java.util.GregorianCalendar;
import org.jboss.seam.scheduling.events.AbstractTimeEvent;
import org.jboss.seam.scheduling.events.Hour;
@@ -33,6 +34,6 @@
*/
protected AbstractTimeEvent createEventPayload()
{
- return new Hour(System.currentTimeMillis());
+ return new Hour(System.currentTimeMillis(), gc.get(GregorianCalendar.MINUTE));
}
}
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/MinuteJob.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/MinuteJob.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/MinuteJob.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -16,6 +16,7 @@
*/
package org.jboss.seam.scheduling.quartz.jobs;
+import java.util.GregorianCalendar;
import org.jboss.seam.scheduling.events.AbstractTimeEvent;
import org.jboss.seam.scheduling.events.Minute;
@@ -32,6 +33,6 @@
*/
protected AbstractTimeEvent createEventPayload()
{
- return new Minute(System.currentTimeMillis());
+ return new Minute(System.currentTimeMillis(), gc.get(GregorianCalendar.MINUTE));
}
}
Modified: sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/SecondJob.java
===================================================================
--- sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/SecondJob.java 2010-01-03 12:03:45 UTC (rev 11901)
+++ sandbox/trunk/modules/scheduling/src/main/java/org/jboss/seam/scheduling/quartz/jobs/SecondJob.java 2010-01-03 13:52:56 UTC (rev 11902)
@@ -16,6 +16,7 @@
*/
package org.jboss.seam.scheduling.quartz.jobs;
+import java.util.GregorianCalendar;
import org.jboss.seam.scheduling.events.AbstractTimeEvent;
import org.jboss.seam.scheduling.events.Second;
@@ -32,6 +33,6 @@
*/
protected AbstractTimeEvent createEventPayload()
{
- return new Second(System.currentTimeMillis());
+ return new Second(System.currentTimeMillis(), gc.get(GregorianCalendar.SECOND));
}
}
14 years, 12 months
Seam SVN: r11901 - in modules/remoting/trunk: examples/model/src/main/java/org/jboss/seam/remoting/examples/model and 5 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-03 07:03:45 -0500 (Sun, 03 Jan 2010)
New Revision: 11901
Removed:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java
Modified:
modules/remoting/trunk/examples/model/pom.xml
modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
modules/remoting/trunk/examples/model/src/main/resources/import.sql
modules/remoting/trunk/examples/model/src/main/webapp/model.html
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
updated example to demonstrate lazy loading model expansion
Modified: modules/remoting/trunk/examples/model/pom.xml
===================================================================
--- modules/remoting/trunk/examples/model/pom.xml 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/pom.xml 2010-01-03 12:03:45 UTC (rev 11901)
@@ -35,6 +35,12 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
Deleted: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java 2010-01-03 12:03:45 UTC (rev 11901)
@@ -1,92 +0,0 @@
-package org.jboss.seam.remoting.examples.model;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Entity;
-//import javax.persistence.EnumType;
-//import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-/**
- * Customer entity bean. This class exposes a variety of property types for the
- * purpose of the example.
- *
- * @author Shane Bryzak
- */
-@Entity
-@Table(name = "customer")
-public class Customer implements Serializable
-{
- private static final long serialVersionUID = 4289723352398788625L;
-
-// public static enum Gender { male, female }
-
-
- private Integer customerId;
-
- private String firstName;
- private String lastName;
-
-
- private Date dateOfBirth;
-
- //(a)Enumerated(EnumType.STRING)
- //private Gender gender;
-
- @Id @GeneratedValue
- public Integer getCustomerId()
- {
- return customerId;
- }
-
- public void setCustomerId(Integer customerId)
- {
- this.customerId = customerId;
- }
-
- public String getFirstName()
- {
- return firstName;
- }
-
- public void setFirstName(String firstName)
- {
- this.firstName = firstName;
- }
-
- public String getLastName()
- {
- return lastName;
- }
-
- public void setLastName(String lastName)
- {
- this.lastName = lastName;
- }
-
- @Temporal(TemporalType.DATE)
- public Date getDateOfBirth()
- {
- return dateOfBirth;
- }
-
- public void setDateOfBirth(Date dateOfBirth)
- {
- this.dateOfBirth = dateOfBirth;
- }
-
-/* public Gender getGender()
- {
- return gender;
- }
-
- public void setGender(Gender gender)
- {
- this.gender = gender;
- }*/
-}
Deleted: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java 2010-01-03 12:03:45 UTC (rev 11901)
@@ -1,55 +0,0 @@
-package org.jboss.seam.remoting.examples.model;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.Conversation;
-import javax.enterprise.context.ConversationScoped;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.jboss.seam.remoting.annotations.WebRemote;
-
-@ConversationScoped
-public class CustomerAction implements Serializable
-{
- private static final long serialVersionUID = 8350706339578435242L;
-
- @PersistenceContext EntityManager entityManager;
- @Inject Conversation conversation;
-
- private Customer customer;
-
- @WebRemote
- public void createCustomer()
- {
- conversation.begin();
- customer = new Customer();
- }
-
- @WebRemote
- public void editCustomer(Integer customerId)
- {
- conversation.begin();
- customer = entityManager.find(Customer.class, customerId);
- }
-
- @WebRemote
- public void saveCustomer()
- {
- if (customer.getCustomerId() == null)
- {
- entityManager.persist(customer);
- }
- else
- {
- customer = entityManager.merge(customer);
- }
- conversation.end();
- }
-
- public Customer getCustomer()
- {
- return customer;
- }
-}
Modified: modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml 2010-01-03 12:03:45 UTC (rev 11901)
@@ -5,7 +5,8 @@
version="1.0">
<persistence-unit name="model">
<jta-data-source>modelDatasource</jta-data-source>
- <class>org.jboss.seam.remoting.examples.model.Customer</class>
+ <class>org.jboss.seam.remoting.examples.model.Person</class>
+ <class>org.jboss.seam.remoting.examples.model.Address</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
Modified: modules/remoting/trunk/examples/model/src/main/resources/import.sql
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/import.sql 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/resources/import.sql 2010-01-03 12:03:45 UTC (rev 11901)
@@ -1,3 +1,3 @@
-insert into customer (customerid, firstname, lastname, dateofbirth) values (1, 'Shane', 'Bryzak', '1901-01-01');
-
-
+insert into person (personid, firstname, lastname, dateofbirth) values (1, 'Shane', 'Bryzak', '1901-01-01');
+insert into address (addressid, person_id, streetno, streetname, suburb, postcode, country) values (1, 1, 100, 'Main', 'Pleasantville', '32123', 'Australia');
+insert into address (addressid, person_id, streetno, streetname, suburb, postcode, country) values (2, 1, 57, '1st Avenue', 'Pittsville', '32411', 'Australia');
\ No newline at end of file
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-03 12:03:45 UTC (rev 11901)
@@ -19,40 +19,47 @@
var model = null;
- function loadCustomer() {
- var customerId = document.getElementById("customerId").value;
+ function loadPerson() {
+ var personId = document.getElementById("personId").value;
model = new Seam.Model();
- var callback = function(model) { alert(model.getValue("customer").getFirstName()); };
+ var callback = function(model) { var p = model.getValue("person"); alert(p.getFirstName() + " " + p.getLastName()); };
- model.addBeanProperty("customer", "org.jboss.seam.remoting.examples.model.CustomerAction", "customer");
+ model.addBeanProperty("person", "org.jboss.seam.remoting.examples.model.PersonAction", "person");
model.fetch(new Seam.Action()
- .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
- .setMethod("editCustomer")
- .addParam(customerId), callback);
+ .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+ .setMethod("editPerson")
+ .addParam(personId), callback);
}
- function modifyCustomer() {
- model.getValue("customer").setFirstName("bob");
+ function expandModel() {
+ var callback = function(model) { alert("Got addresses: " + model.getValue("person").getAddresses().length); };
+
+ model.expand(model.getValue("person"), "addresses", callback);
}
+ function modifyPerson() {
+ model.getValue("person").setFirstName("bob");
+ }
+
function applyUpdates() {
var callback = function(model) { alert("updates applied"); };
model.applyUpdates(new Seam.Action()
- .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
- .setMethod("saveCustomer"),
+ .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+ .setMethod("savePerson"),
callback);
}
// ]]>
</script>
- <label for="customerId">Customer ID</label><input type="text" id="customerId" value="1"/>
+ <label for="personId">Person ID</label><input type="text" id="personId" value="1"/>
- <button onclick="javascript:loadCustomer()">Load customer</button>
- <button onclick="javascript:modifyCustomer()">Modify customer</button>
+ <button onclick="javascript:loadPerson()">Load person</button>
+ <button onclick="javascript:expandModel()">expand model</button>
+ <button onclick="javascript:modifyPerson()">Modify person</button>
<button onclick="javascript:applyUpdates()">Apply updates</button>
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-03 12:03:45 UTC (rev 11901)
@@ -339,7 +339,7 @@
throw new IllegalStateException("Invalid request state - no object ref found");
}
- int refId = Integer.parseInt(refElement.attributeValue("refid"));
+ int refId = Integer.parseInt(refElement.attributeValue("id"));
Wrapper target = model.getCallContext().getOutRefs().get(refId);
int newRefIdx = model.getCallContext().getOutRefs().size();
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 12:03:45 UTC (rev 11901)
@@ -624,14 +624,16 @@
Seam.validateRefs = function(refsNode) {
var unknowns = [];
- var cn = Seam.Xml.childNodes(refsNode, "ref");
- for (var i=0; i<cn.length; i++) {
- var n = cn[i].firstChild;
- if (n.tagName == "bean") {
- var name = n.getAttribute("type");
- if (!Seam.isBeanRegistered(name)) unknowns.push(name);
- }
- }
+ if (refsNode) {
+ var cn = Seam.Xml.childNodes(refsNode, "ref");
+ for (var i=0; i<cn.length; i++) {
+ var n = cn[i].firstChild;
+ if (n.tagName == "bean") {
+ var name = n.getAttribute("type");
+ if (!Seam.isBeanRegistered(name)) unknowns.push(name);
+ }
+ }
+ }
return unknowns;
}
14 years, 12 months
Seam SVN: r11900 - in modules/remoting/trunk/src/main: resources/org/jboss/seam/remoting and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-03 06:47:13 -0500 (Sun, 03 Jan 2010)
New Revision: 11900
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MetadataCache.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
move closures out of local variable scope
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MetadataCache.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MetadataCache.java 2010-01-03 09:45:39 UTC (rev 11899)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MetadataCache.java 2010-01-03 11:47:13 UTC (rev 11900)
@@ -120,7 +120,10 @@
private void addBeanDependencies(Class<?> beanClass, Set<BeanMetadata> types)
{
- types.add(getMetadata(beanClass));
+ BeanMetadata meta = getMetadata(beanClass);
+ if (types.contains(meta)) return;
+
+ types.add(meta);
for (Class<?> dependencyClass : getDependencies(beanClass))
{
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 09:45:39 UTC (rev 11899)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-03 11:47:13 UTC (rev 11900)
@@ -36,6 +36,14 @@
return Seam.beans[name] != null;
}
+Seam.createSetterMethod = function(fieldName) {
+ return function(value) { this[fieldName] = value; };
+}
+
+Seam.createGetterMethod = function(fieldName) {
+ return function() { return this[fieldName]; };
+}
+
Seam.registerBean = function(name, metadata, methods) {
if (Seam.isBeanRegistered(name)) return;
var t = function() {};
@@ -43,9 +51,9 @@
if (metadata) {
var m = [];
for (var f in metadata) {
- var s = f.substring(0,1).toUpperCase() + f.substring(1);
- t.prototype["set" + s] = function(value) { this[f] = value; };
- t.prototype["get" + s] = function() { return this[f]; };
+ var s = f.substring(0,1).toUpperCase() + f.substring(1);
+ t.prototype["set" + s] = Seam.createSetterMethod(f);
+ t.prototype["get" + s] = Seam.createGetterMethod(f);
m.push({field:f, type:metadata[f]});
}
t.__metadata = m;
14 years, 12 months