You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/01/21 13:27:01 UTC

svn commit: r1436302 - in /myfaces/tobago/trunk: tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ tobago-example/tobago-example-test/src/main/webapp/WEB-INF/ tobago-example/tobago-example-test/src/main/webapp/tes...

Author: lofwyr
Date: Mon Jan 21 12:27:01 2013
New Revision: 1436302

URL: http://svn.apache.org/viewvc?rev=1436302&view=rev
Log:
TOBAGO-1225: Minor enhancements to selectManyShuttle

Added:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/Shuttle.java
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-layout.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-value.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle.xhtml
Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/Shuttle.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/Shuttle.java?rev=1436302&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/Shuttle.java (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/Shuttle.java Mon Jan 21 12:27:01 2013
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.example.test;
+
+import org.apache.myfaces.tobago.internal.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Shuttle {
+
+  List<String> value;
+
+  public Shuttle() {
+    this.value = new ArrayList<String>();
+  }
+
+  public List<String> getValue() {
+    return value;
+  }
+
+  public void setValue(List<String> value) {
+    this.value = value;
+  }
+
+  public String getResult() {
+    return StringUtils.joinWithSurroundingSeparator(value).substring(1, Math.max(value.size() * 2, 1));
+  }
+}

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml?rev=1436302&r1=1436301&r2=1436302&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml Mon Jan 21 12:27:01 2013
@@ -179,6 +179,12 @@
     <managed-bean-scope>none</managed-bean-scope>
   </managed-bean>
 
+  <managed-bean>
+    <managed-bean-name>shuttle</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.tobago.example.test.Shuttle</managed-bean-class>
+    <managed-bean-scope>session</managed-bean-scope>
+  </managed-bean>
+
   <navigation-rule>
     <navigation-case>
       <from-outcome>navigation</from-outcome>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-layout.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-layout.xhtml?rev=1436302&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-layout.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-layout.xhtml Mon Jan 21 12:27:01 2013
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<f:view
+    xmlns:tc="http://myfaces.apache.org/tobago/component"
+    xmlns:tx="http://myfaces.apache.org/tobago/extension"
+    xmlns:f="http://java.sun.com/jsf/core">
+
+  <tc:page id="page">
+    <tc:gridLayoutConstraint width="700px" height="600px"/>
+    <f:facet name="layout">
+      <tc:gridLayout columns="*;2*" rows="auto;auto"/>
+    </f:facet>
+
+    <tc:label value="tc"/>
+    <tc:label value="tx"/>
+
+    <tc:selectManyShuttle id="s1">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tc:selectManyShuttle>
+    <tx:selectManyShuttle label="normal" fieldId="s2">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tx:selectManyShuttle>
+
+    <tc:script file="script/tobago-assert.js"/>
+
+    <tc:script onload="TobagoAssert.assertLayout('page:s1', 0, 25, 200, 40);"/>
+    <tc:script onload="TobagoAssert.assertLayout('page:s2', 330, 25, 200, 40);"/>
+
+  </tc:page>
+</f:view>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-value.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-value.xhtml?rev=1436302&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-value.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle-value.xhtml Mon Jan 21 12:27:01 2013
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<f:view
+    xmlns:tc="http://myfaces.apache.org/tobago/component"
+    xmlns:tx="http://myfaces.apache.org/tobago/extension"
+    xmlns:ui="http://java.sun.com/jsf/facelets"
+    xmlns:f="http://java.sun.com/jsf/core">
+
+  <tc:page>
+    <tc:gridLayoutConstraint width="700px" height="400px"/>
+    <f:facet name="layout">
+      <tc:gridLayout rows="auto;*;auto;auto"/>
+    </f:facet>
+
+    <tc:messages/>
+
+    <tc:selectManyShuttle value="#{shuttle.value}">
+      <tc:selectItem itemValue="a" itemLabel="A (disabled)" itemDisabled="true"/>
+      <tc:selectItem itemValue="b" itemLabel="B"/>
+      <tc:selectItem itemValue="c" itemLabel="C"/>
+      <tc:selectItem itemValue="d" itemLabel="D"/>
+      <tc:selectItem itemValue="e" itemLabel="E (disabled)" itemDisabled="true"/>
+      <tc:selectItem itemValue="f" itemLabel="F"/>
+      <tc:selectItem itemValue="g" itemLabel="G"/>
+      <tc:selectItem itemValue="h" itemLabel="H"/>
+      <tc:selectItem itemValue="i" itemLabel="I (disabled)" itemDisabled="true"/>
+      <tc:selectItem itemValue="j" itemLabel="J"/>
+      <tc:selectItem itemValue="k" itemLabel="K"/>
+      <tc:selectItem itemValue="l" itemLabel="L"/>
+      <tc:selectItem itemValue="m" itemLabel="M"/>
+      <tc:selectItem itemValue="n" itemLabel="N"/>
+      <tc:selectItem itemValue="o" itemLabel="O (disabled)" itemDisabled="true"/>
+      <tc:selectItem itemValue="p" itemLabel="P"/>
+      <tc:selectItem itemValue="q" itemLabel="Q"/>
+      <tc:selectItem itemValue="r" itemLabel="R"/>
+      <tc:selectItem itemValue="s" itemLabel="S"/>
+      <tc:selectItem itemValue="t" itemLabel="T"/>
+      <tc:selectItem itemValue="u" itemLabel="U (disabled)" itemDisabled="true"/>
+      <tc:selectItem itemValue="v" itemLabel="V"/>
+      <tc:selectItem itemValue="w" itemLabel="W"/>
+      <tc:selectItem itemValue="x" itemLabel="X"/>
+      <tc:selectItem itemValue="y" itemLabel="Y"/>
+      <tc:selectItem itemValue="z" itemLabel="Z"/>
+    </tc:selectManyShuttle>
+
+    <tc:button label="submit"/>
+
+    <tx:in label="on server" value="#{shuttle.result}" readonly="true"/>
+
+  </tc:page>
+</f:view>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle.xhtml?rev=1436302&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectManyShuttle/selectManyShuttle.xhtml Mon Jan 21 12:27:01 2013
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<f:view
+    xmlns:tc="http://myfaces.apache.org/tobago/component"
+    xmlns:tx="http://myfaces.apache.org/tobago/extension"
+    xmlns:ui="http://java.sun.com/jsf/facelets"
+    xmlns:f="http://java.sun.com/jsf/core">
+
+  <tc:page>
+    <tc:gridLayoutConstraint width="700px" height="600px"/>
+    <f:facet name="layout">
+      <!-- fixme: rows="20px" -->
+      <tc:gridLayout columns="*;2*" rows="auto;20px;auto;auto;auto;auto;auto;auto" columnSpacing="30px"/>
+    </f:facet>
+
+    <tc:messages>
+      <tc:gridLayoutConstraint columnSpan="2"/>
+    </tc:messages>
+
+    <tc:label value="tc"/>
+    <tc:label value="tx"/>
+
+    <tc:selectManyShuttle>
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tc:selectManyShuttle>
+    <tx:selectManyShuttle label="normal">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tx:selectManyShuttle>
+
+    <tc:selectManyShuttle readonly="true">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tc:selectManyShuttle>
+    <tx:selectManyShuttle readonly="true" label="readonly">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tx:selectManyShuttle>
+
+    <tc:selectManyShuttle disabled="true">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tc:selectManyShuttle>
+    <tx:selectManyShuttle disabled="true" label="disabled">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tx:selectManyShuttle>
+
+    <tc:selectManyShuttle tip="tip">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tc:selectManyShuttle>
+    <tx:selectManyShuttle tip="tip" label="tip">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tx:selectManyShuttle>
+
+    <tc:selectManyShuttle required="true">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tc:selectManyShuttle>
+    <tx:selectManyShuttle required="true" label="required">
+      <tc:selectItem itemValue="a" itemLabel="A Value"/>
+      <tc:selectItem itemValue="b" itemLabel="An Alternative"/>
+    </tx:selectManyShuttle>
+
+
+    <tc:button label="submit"/>
+
+  </tc:page>
+</f:view>

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1436302&r1=1436301&r2=1436302&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Mon Jan 21 12:27:01 2013
@@ -2716,20 +2716,25 @@ Tobago.SelectManyShuttle.init = function
 Tobago.SelectManyShuttle.moveSelectedItems = function(shuttle, direction, all) {
   var unselected = shuttle.find(".tobago-selectManyShuttle-unselected");
   var selected = shuttle.find(".tobago-selectManyShuttle-selected");
+  var count = selected.children().size();
   var source = direction ? unselected : selected;
   var target = direction ? selected : unselected;
-  source.find(all ? "option" : "option:selected").remove().appendTo(target);
-  Tobago.SelectManyShuttle.copyValues(shuttle);
-};
+  var shifted = source.find(all ? "option:not(:disabled)" : "option:selected").remove().appendTo(target);
 
-Tobago.SelectManyShuttle.copyValues = function(shuttle) {
+  // synchronize the hidden select
   var hidden = shuttle.find(".tobago-selectManyShuttle-hidden");
-  hidden.find("option").remove();
-  shuttle.find(".tobago-selectManyShuttle-selected option").clone()
-      .attr('selected', 'selected').appendTo(hidden);
-  var e = jQuery.Event("change");
-  // trigger an change event for command facets
-  hidden.trigger( e );
+  var hiddenOptions = hidden.find("option");
+  // todo: may be optimized: put values in a hash map?
+  shifted.each(function() {
+    var option = jQuery(this);
+    hiddenOptions.filter("[value='" + option.val() + "']").prop("selected", direction);
+  });
+
+  if (count != selected.children().size()) {
+    var e = jQuery.Event("change");
+    // trigger an change event for command facets
+    hidden.trigger( e );
+  }
 };
 
 Tobago.registerListener(Tobago.SelectManyShuttle.init, Tobago.Phase.DOCUMENT_READY);