You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sv...@apache.org on 2005/02/09 14:05:21 UTC
cvs commit: incubator-myfaces/webapps/examples/web selectOneCountry.jsp
svieujot 2005/02/09 05:05:21
Modified: webapps/examples/src/org/apache/myfaces/examples/resource
example_messages.properties
tlds myfaces_ext.tld
webapps/examples/web/inc page_header.jsp navigation.jsp
doc release-notes.txt
conf faces-config.xml
Added: src/components/org/apache/myfaces/custom/selectOneCountry
SelectOneCountryTag.java SelectOneCountry.xml
SelectOneCountry.java SelectOneCountryRenderer.java
webapps/examples/src/org/apache/myfaces/examples/misc
Country.java
webapps/examples/web selectOneCountry.jsp
Log:
new x:selectOneCountry component
Revision Changes Path
1.17 +1 -0 incubator-myfaces/webapps/examples/src/org/apache/myfaces/examples/resource/example_messages.properties
Index: example_messages.properties
===================================================================
RCS file: /home/cvs/incubator-myfaces/webapps/examples/src/org/apache/myfaces/examples/resource/example_messages.properties,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- example_messages.properties 10 Jan 2005 08:08:14 -0000 1.16
+++ example_messages.properties 9 Feb 2005 13:05:20 -0000 1.17
@@ -35,6 +35,7 @@
nav_newspaperTable = Newspaper Table
nav_HtmlEditor = Html Editor
nav_forceId = ForceId
+nav_selectOneCountry= Select a country box
nav_swapimage = SwapImage
# buttons
1.164 +23 -0 incubator-myfaces/tlds/myfaces_ext.tld
Index: myfaces_ext.tld
===================================================================
RCS file: /home/cvs/incubator-myfaces/tlds/myfaces_ext.tld,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -r1.163 -r1.164
--- myfaces_ext.tld 6 Feb 2005 19:45:33 -0000 1.163
+++ myfaces_ext.tld 9 Feb 2005 13:05:20 -0000 1.164
@@ -1392,6 +1392,29 @@
</attribute>
</tag>
+ <!-- selectOneCountry -->
+ <tag>
+ <name>selectOneCountry</name>
+ <tag-class>org.apache.myfaces.custom.selectOneCountry.SelectOneCountryTag</tag-class>
+ <body-content>JSP</body-content>
+ <description>
+ A localized list of countries choose box.
+ The value binds to the country ISO 3166 code.
+ The official codes list is available here :
+ http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
+ </description>
+ <attribute>
+ <name>maxLength</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Integer equals to the maximum number of characters in the country name.
+ </description>
+ </attribute>
+ &standard_select_one_menu_attributes;
+ &user_role_attributes;
+ &ext_forceId_attribute;
+ </tag>
<!-- stylesheet -->
1.49 +1 -0 incubator-myfaces/webapps/examples/web/inc/page_header.jsp
Index: page_header.jsp
===================================================================
RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/inc/page_header.jsp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- page_header.jsp 10 Jan 2005 08:39:19 -0000 1.48
+++ page_header.jsp 9 Feb 2005 13:05:20 -0000 1.49
@@ -45,6 +45,7 @@
<x:navigationMenuItem id="nav_2_4_16" itemLabel="#{example_messages['nav_newspaperTable']}" action="go_newspaperTable" icon="images/myfaces.gif" />
<x:navigationMenuItem id="nav_2_4_17" itemLabel="#{example_messages['nav_swapimage']}" action="go_swapimage" icon="images/myfaces.gif" />
<x:navigationMenuItem id="nav_2_4_18" itemLabel="#{example_messages['nav_forceId']}" action="go_forceId" icon="images/myfaces.gif" />
+ <x:navigationMenuItem id="nav_2_4_19" itemLabel="#{example_messages['nav_selectOneCountry']}" action="go_selectOneCountry" icon="images/myfaces.gif" />
</x:navigationMenuItem>
</x:navigationMenuItem>
<x:navigationMenuItem id="nav_3" itemLabel="#{example_messages['nav_Documentation']}" >
1.49 +1 -0 incubator-myfaces/webapps/examples/web/inc/navigation.jsp
Index: navigation.jsp
===================================================================
RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/inc/navigation.jsp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- navigation.jsp 10 Jan 2005 08:08:21 -0000 1.48
+++ navigation.jsp 9 Feb 2005 13:05:20 -0000 1.49
@@ -35,6 +35,7 @@
<x:commandNavigation id="nav_2_4_16" value="#{example_messages['nav_newspaperTable']}" action="go_newspaperTable" />
<x:commandNavigation id="nav_2_4_17" value="#{example_messages['nav_swapimage']}" action="go_swapimage" />
<x:commandNavigation id="nav_2_4_18" value="#{example_messages['nav_forceId']}" action="go_forceId" />
+ <x:commandNavigation id="nav_2_4_19" value="#{example_messages['nav_selectOneCountry']}" action="go_selectOneCountry" />
</x:commandNavigation>
</x:commandNavigation>
<x:commandNavigation id="nav_3" value="#{example_messages['nav_Documentation']}" >
1.1 incubator-myfaces/src/components/org/apache/myfaces/custom/selectOneCountry/SelectOneCountryTag.java
Index: SelectOneCountryTag.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed 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.custom.selectOneCountry;
import javax.faces.component.UIComponent;
import org.apache.myfaces.taglib.html.ext.HtmlSelectOneMenuTag;
/**
* @author Sylvain Vieujot (latest modification by $Author: svieujot $)
* @version $Revision: 1.1 $ $Date: 2005/02/09 13:05:20 $
* $Log: SelectOneCountryTag.java,v $
* Revision 1.1 2005/02/09 13:05:20 svieujot
* new x:selectOneCountry component
*
*
*/
public class SelectOneCountryTag extends HtmlSelectOneMenuTag {
public String getComponentType() {
return SelectOneCountry.COMPONENT_TYPE;
}
public String getRendererType() {
return "org.apache.myfaces.SelectOneCountryRenderer";
}
private String maxLength;
protected void setProperties(UIComponent component) {
super.setProperties(component);
setIntegerProperty(component, "maxLength", maxLength);
}
public void setMaxLength(String maxLength){
this.maxLength = maxLength;
}
}
1.1 incubator-myfaces/src/components/org/apache/myfaces/custom/selectOneCountry/SelectOneCountry.xml
Index: SelectOneCountry.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE component PUBLIC
"-//MyFaces//DTD MyFaces component def 1.0//EN"
"http://myfaces.apache.org/dtd/Component.dtd">
<component>
<component-class>org.apache.myfaces.custom.selectOneCountry.selectOneCountry</component-class>
<base-class>org.apache.myfaces.component.html.ext.HtmlSelectOneMenu</base-class>
<component-type>org.apache.myfaces.SelectOneCountry</component-type>
<component-family>javax.faces.SelectOne</component-family>
<renderer-type>org.apache.myfaces.SelectOneCountry</renderer-type>
<field>
<name>length</name>
<type>java.lang.String</type>
</field>
</component>
1.1 incubator-myfaces/src/components/org/apache/myfaces/custom/selectOneCountry/SelectOneCountry.java
Index: SelectOneCountry.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed 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.custom.selectOneCountry;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TreeMap;
import javax.faces.component.UISelectItem;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.model.SelectItem;
import org.apache.myfaces.component.html.ext.HtmlSelectOneMenu;
/**
* @author Sylvain Vieujot (latest modification by $Author: svieujot $)
* @version $Revision: 1.1 $ $Date: 2005/02/09 13:05:20 $
* $Log: SelectOneCountry.java,v $
* Revision 1.1 2005/02/09 13:05:20 svieujot
* new x:selectOneCountry component
*
*/
public class SelectOneCountry extends HtmlSelectOneMenu {
public static final String COMPONENT_TYPE = "org.apache.myfaces.SelectOneCountry";
private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SelectOneCountryRenderer";
private Integer _maxLength = null;
public SelectOneCountry() {
setRendererType(DEFAULT_RENDERER_TYPE);
}
public Integer getMaxLength() {
if (_maxLength != null) return _maxLength;
ValueBinding vb = getValueBinding("length");
return vb != null ? (Integer)vb.getValue(getFacesContext()) : null;
}
public void setMaxLength(Integer maxLength) {
_maxLength = maxLength;
}
public Object saveState(FacesContext context) {
Object values[] = new Object[2];
values[0] = super.saveState(context);
values[1] = _maxLength;
return values;
}
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
_maxLength = (Integer)values[1];
}
// -------- Over ridden UIComponent methods -----------
public void encodeChildren(FacesContext context){
// noop
}
public int getChildCount(){
return Locale.getISOCountries().length;
}
public List getChildren(){
String[] availableCountries = Locale.getISOCountries();
Locale currentLocale;
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
if( viewRoot != null )
currentLocale = viewRoot.getLocale();
else
currentLocale = facesContext.getApplication().getDefaultLocale();
TreeMap map = new TreeMap();
// TreeMap is sorted according to the keys' natural order
for(int i=0; i<availableCountries.length; i++){
String countryCode = availableCountries[i];
Locale tmp = new Locale(countryCode, countryCode);
map.put(tmp.getDisplayCountry(currentLocale), countryCode);
}
List countriesSelectItems = new ArrayList(availableCountries.length);
int maxDescriptionLength = _maxLength==null ? Integer.MAX_VALUE : _maxLength.intValue();
if( maxDescriptionLength < 5 )
maxDescriptionLength = 5;
for(Iterator i = map.keySet().iterator(); i.hasNext(); ){
String countryName = (String) i.next();
String countryCode = (String) map.get( countryName );
String label;
if( countryName.length() <= maxDescriptionLength )
label = countryName;
else{
label = countryName.substring(0, maxDescriptionLength-3)+"...";
}
UISelectItem selectItem = new UISelectItem();
selectItem.setValue( new SelectItem(countryCode, label) );
countriesSelectItems.add( selectItem );
}
return countriesSelectItems;
}
}
1.1 incubator-myfaces/src/components/org/apache/myfaces/custom/selectOneCountry/SelectOneCountryRenderer.java
Index: SelectOneCountryRenderer.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed 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.custom.selectOneCountry;
import org.apache.myfaces.renderkit.html.ext.HtmlMenuRenderer;
/**
* @author Sylvain Vieujot (latest modification by $Author: svieujot $)
* @version $Revision: 1.1 $ $Date: 2005/02/09 13:05:20 $
* $Log: SelectOneCountryRenderer.java,v $
* Revision 1.1 2005/02/09 13:05:20 svieujot
* new x:selectOneCountry component
*
*/
public class SelectOneCountryRenderer extends HtmlMenuRenderer {
}
1.1 incubator-myfaces/webapps/examples/src/org/apache/myfaces/examples/misc/Country.java
Index: Country.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed 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.examples.misc;
/**
* @author Sylvain Vieujot (latest modification by $Author: svieujot $)
* @version $Revision: 1.1 $ $Date: 2005/02/09 13:05:21 $
*/
public class Country
{
private String code = null;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
1.166 +1 -0 incubator-myfaces/doc/release-notes.txt
Index: release-notes.txt
===================================================================
RCS file: /home/cvs/incubator-myfaces/doc/release-notes.txt,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -r1.165 -r1.166
--- release-notes.txt 8 Feb 2005 17:57:23 -0000 1.165
+++ release-notes.txt 9 Feb 2005 13:05:21 -0000 1.166
@@ -5,6 +5,7 @@
Changes in Release 1.0.9
* added support for portlet api (MYFACES-86). Thanks to Stan Silver (JBoss Group)
* new CollapsiblePanel Component
+* new selectOneCountry component
* added forceId to <x:inputText for better reuse of legacy JavaScript
* added russian i18n.
* closed MYFACES-85 in Jira
1.107 +11 -0 incubator-myfaces/conf/faces-config.xml
Index: faces-config.xml
===================================================================
RCS file: /home/cvs/incubator-myfaces/conf/faces-config.xml,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- faces-config.xml 10 Jan 2005 08:22:17 -0000 1.106
+++ faces-config.xml 9 Feb 2005 13:05:21 -0000 1.107
@@ -257,6 +257,11 @@
</component>
<component>
+ <component-type>org.apache.myfaces.SelectOneCountry</component-type>
+ <component-class>org.apache.myfaces.custom.selectOneCountry.SelectOneCountry</component-class>
+ </component>
+
+ <component>
<component-type>org.apache.myfaces.Stylesheet</component-type>
<component-class>org.apache.myfaces.custom.stylesheet.Stylesheet</component-class>
</component>
@@ -508,6 +513,12 @@
<renderer-class>org.apache.myfaces.renderkit.html.ext.HtmlRadioRenderer</renderer-class>
</renderer>
+ <renderer>
+ <component-family>javax.faces.SelectOne</component-family>
+ <renderer-type>org.apache.myfaces.SelectOneCountryRenderer</renderer-type>
+ <renderer-class>org.apache.myfaces.custom.selectOneCountry.SelectOneCountryRenderer</renderer-class>
+ </renderer>
+
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>org.apache.myfaces.Stylesheet</renderer-type>
1.1 incubator-myfaces/webapps/examples/web/selectOneCountry.jsp
Index: selectOneCountry.jsp
===================================================================
<%@ page session="false" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
<html>
<!--
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed 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.
*/
//-->
<%@include file="inc/head.inc" %>
<body>
<f:view>
<f:loadBundle basename="org.apache.myfaces.examples.resource.example_messages" var="example_messages"/>
<x:panelLayout id="page" layout="#{globalOptions.pageLayout}"
styleClass="pageLayout"
headerClass="pageHeader"
navigationClass="pageNavigation"
bodyClass="pageBody"
footerClass="pageFooter" >
<f:facet name="header">
<f:subview id="header">
<jsp:include page="inc/page_header.jsp" />
</f:subview>
</f:facet>
<f:facet name="navigation">
<f:subview id="menu" >
<jsp:include page="inc/navigation.jsp" />
</f:subview>
</f:facet>
<f:facet name="body">
<h:panelGroup>
<h:form>
<x:selectOneCountry value="#{country.code}" maxLength="25" onchange="this.form.submit();"/>
<f:verbatim><br/></f:verbatim>
<h:outputLabel for="countryCode" value="Code : "/>
<h:outputText id="countryCode" value="#{country.code}"/>
<f:verbatim><br/><br/></f:verbatim>
<h:commandButton value="Update"/>
</h:form>
</h:panelGroup>
</f:facet>
<%@include file="inc/page_footer.jsp" %>
</x:panelLayout>
</f:view>
</body>
</html>