@@ -256,6 +256,7 @@ public String getAsText() {
256
256
assertTrue (output .startsWith ("<select " ));
257
257
assertTrue (output .endsWith ("</select>" ));
258
258
assertFalse (output .contains ("selected=\" selected\" " ));
259
+ assertFalse (output .contains ("multiple=\" multiple\" " ));
259
260
}
260
261
261
262
public void testNestedPathWithListAndEditor () throws Exception {
@@ -731,7 +732,7 @@ public String getAsText() {
731
732
}
732
733
}
733
734
734
- public void testMultiForCollection () throws Exception {
735
+ public void testMultipleForCollection () throws Exception {
735
736
this .bean .setSomeList (new ArrayList ());
736
737
737
738
this .tag .setPath ("someList" );
@@ -760,7 +761,35 @@ public void testMultiForCollection() throws Exception {
760
761
assertNotNull (inputElement );
761
762
}
762
763
763
- public void testMultiExplicit () throws Exception {
764
+ public void testMultipleWithStringValue () throws Exception {
765
+ this .tag .setPath ("name" );
766
+ this .tag .setItems (Country .getCountries ());
767
+ this .tag .setItemValue ("isoCode" );
768
+ this .tag .setMultiple ("multiple" );
769
+ int result = this .tag .doStartTag ();
770
+ assertEquals (Tag .SKIP_BODY , result );
771
+
772
+ String output = getOutput ();
773
+ output = "<doc>" + output + "</doc>" ;
774
+
775
+ SAXReader reader = new SAXReader ();
776
+ Document document = reader .read (new StringReader (output ));
777
+ Element rootElement = document .getRootElement ();
778
+ assertEquals (2 , rootElement .elements ().size ());
779
+
780
+ Element selectElement = rootElement .element ("select" );
781
+ assertEquals ("select" , selectElement .getName ());
782
+ assertEquals ("name" , selectElement .attribute ("name" ).getValue ());
783
+ assertEquals ("multiple" , selectElement .attribute ("multiple" ).getValue ());
784
+
785
+ List children = selectElement .elements ();
786
+ assertEquals ("Incorrect number of children" , 4 , children .size ());
787
+
788
+ Element inputElement = rootElement .element ("input" );
789
+ assertNotNull (inputElement );
790
+ }
791
+
792
+ public void testMultipleExplicitlyTrue () throws Exception {
764
793
this .tag .setPath ("name" );
765
794
this .tag .setItems (Country .getCountries ());
766
795
this .tag .setItemValue ("isoCode" );
@@ -788,6 +817,84 @@ public void testMultiExplicit() throws Exception {
788
817
assertNotNull (inputElement );
789
818
}
790
819
820
+ public void testMultipleExplicitlyFalse () throws Exception {
821
+ this .tag .setPath ("name" );
822
+ this .tag .setItems (Country .getCountries ());
823
+ this .tag .setItemValue ("isoCode" );
824
+ this .tag .setMultiple ("false" );
825
+ int result = this .tag .doStartTag ();
826
+ assertEquals (Tag .SKIP_BODY , result );
827
+
828
+ String output = getOutput ();
829
+ output = "<doc>" + output + "</doc>" ;
830
+
831
+ SAXReader reader = new SAXReader ();
832
+ Document document = reader .read (new StringReader (output ));
833
+ Element rootElement = document .getRootElement ();
834
+ assertEquals (1 , rootElement .elements ().size ());
835
+
836
+ Element selectElement = rootElement .element ("select" );
837
+ assertEquals ("select" , selectElement .getName ());
838
+ assertEquals ("name" , selectElement .attribute ("name" ).getValue ());
839
+ assertNull (selectElement .attribute ("multiple" ));
840
+
841
+ List children = selectElement .elements ();
842
+ assertEquals ("Incorrect number of children" , 4 , children .size ());
843
+ }
844
+
845
+ public void testMultipleWithBooleanTrue () throws Exception {
846
+ this .tag .setPath ("name" );
847
+ this .tag .setItems (Country .getCountries ());
848
+ this .tag .setItemValue ("isoCode" );
849
+ this .tag .setMultiple (true );
850
+ int result = this .tag .doStartTag ();
851
+ assertEquals (Tag .SKIP_BODY , result );
852
+
853
+ String output = getOutput ();
854
+ output = "<doc>" + output + "</doc>" ;
855
+
856
+ SAXReader reader = new SAXReader ();
857
+ Document document = reader .read (new StringReader (output ));
858
+ Element rootElement = document .getRootElement ();
859
+ assertEquals (2 , rootElement .elements ().size ());
860
+
861
+ Element selectElement = rootElement .element ("select" );
862
+ assertEquals ("select" , selectElement .getName ());
863
+ assertEquals ("name" , selectElement .attribute ("name" ).getValue ());
864
+ assertEquals ("multiple" , selectElement .attribute ("multiple" ).getValue ());
865
+
866
+ List children = selectElement .elements ();
867
+ assertEquals ("Incorrect number of children" , 4 , children .size ());
868
+
869
+ Element inputElement = rootElement .element ("input" );
870
+ assertNotNull (inputElement );
871
+ }
872
+
873
+ public void testMultipleWithBooleanFalse () throws Exception {
874
+ this .tag .setPath ("name" );
875
+ this .tag .setItems (Country .getCountries ());
876
+ this .tag .setItemValue ("isoCode" );
877
+ this .tag .setMultiple (false );
878
+ int result = this .tag .doStartTag ();
879
+ assertEquals (Tag .SKIP_BODY , result );
880
+
881
+ String output = getOutput ();
882
+ output = "<doc>" + output + "</doc>" ;
883
+
884
+ SAXReader reader = new SAXReader ();
885
+ Document document = reader .read (new StringReader (output ));
886
+ Element rootElement = document .getRootElement ();
887
+ assertEquals (1 , rootElement .elements ().size ());
888
+
889
+ Element selectElement = rootElement .element ("select" );
890
+ assertEquals ("select" , selectElement .getName ());
891
+ assertEquals ("name" , selectElement .attribute ("name" ).getValue ());
892
+ assertNull (selectElement .attribute ("multiple" ));
893
+
894
+ List children = selectElement .elements ();
895
+ assertEquals ("Incorrect number of children" , 4 , children .size ());
896
+ }
897
+
791
898
792
899
private void assertStringArray () throws JspException , DocumentException {
793
900
int result = this .tag .doStartTag ();
0 commit comments