Return-Path: Delivered-To: apmail-myfaces-dev-archive@www.apache.org Received: (qmail 70613 invoked from network); 17 Aug 2005 13:40:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Aug 2005 13:40:01 -0000 Received: (qmail 53340 invoked by uid 500); 17 Aug 2005 13:40:01 -0000 Delivered-To: apmail-myfaces-dev-archive@myfaces.apache.org Received: (qmail 53227 invoked by uid 500); 17 Aug 2005 13:39:58 -0000 Mailing-List: contact dev-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list dev@myfaces.apache.org Received: (qmail 53214 invoked by uid 99); 17 Aug 2005 13:39:58 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Aug 2005 06:39:58 -0700 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=DNS_FROM_RFC_ABUSE X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [68.142.201.241] (HELO web30513.mail.mud.yahoo.com) (68.142.201.241) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 17 Aug 2005 06:40:17 -0700 Received: (qmail 69004 invoked by uid 60001); 17 Aug 2005 13:39:55 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=pF1Mgl1F3yHFsDksLl3ndrH/k7Lp5ZTnSgG78kgAM23joXWbTkOhoye1dzmUBzpS8Xi5qk1/TdZIVlybWrp0Hrl1eyc8ztK0bNzP2vV4lk3Jn/W3aounKp8mH+SWwhRi4+10KA8XCGb34HzndStVhF/KsDbKmUujJNAiO94102M= ; Message-ID: <20050817133955.69002.qmail@web30513.mail.mud.yahoo.com> Received: from [202.88.174.69] by web30513.mail.mud.yahoo.com via HTTP; Wed, 17 Aug 2005 06:39:55 PDT Date: Wed, 17 Aug 2005 06:39:55 -0700 (PDT) From: sharath reddy Subject: patches for MYFACES-192 To: dev@myfaces.apache.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-635839919-1124285995=:68920" Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --0-635839919-1124285995=:68920 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline Hi Sean, Here are 2 SVN patches: 1. 'sandbox' has the files for the new component 2. 'examples' has a demo in the 'sandbox' application. I am a little concerned, though, that the patch 'sandbox' seems to contain '^M' characters. I think this is probably because one of the files I modified, 'myfaces_sandbox.tld', had them in the first place. Let me know if this is a problem. Regards, Sharath __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-635839919-1124285995=:68920 Content-Type: text/plain; name=examples Content-Description: 3826511377-examples Content-Disposition: inline; filename=examples Index: sandbox/home.jsp =================================================================== --- sandbox/home.jsp (revision 233158) +++ sandbox/home.jsp (working copy) @@ -24,7 +24,7 @@ InputSuggestAjax
Input Suggest
Schedule
- + Param Value
Index: sandbox/WEB-INF/examples-config.xml =================================================================== --- sandbox/WEB-INF/examples-config.xml (revision 233158) +++ sandbox/WEB-INF/examples-config.xml (working copy) @@ -281,4 +281,18 @@ + + employeeSearch + org.apache.myfaces.examples.inputparam.EmployeeSearch + request + + + + /inputparam.jsp + + search + /inputparam.jsp + + + Index: sandbox/src/java/org/apache/myfaces/examples/inputparam/Employee.java =================================================================== --- sandbox/src/java/org/apache/myfaces/examples/inputparam/Employee.java (revision 0) +++ sandbox/src/java/org/apache/myfaces/examples/inputparam/Employee.java (revision 0) @@ -0,0 +1,48 @@ +/* + * Copyright 2005 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.inputparam; + +/** + * @author Sharath Reddy (latest modification by $Author$) + * @version $Revision$ $Date$ + */ +public class Employee { + + private String _name; + + private String _type; + + public Employee(String name, String type) { + _name = name; + _type = type; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + this._name = name; + } + + public String getType() { + return _type; + } + + public void setType(String type) { + this._type = type; + } +} \ No newline at end of file Index: sandbox/src/java/org/apache/myfaces/examples/inputparam/EmployeeSearch.java =================================================================== --- sandbox/src/java/org/apache/myfaces/examples/inputparam/EmployeeSearch.java (revision 0) +++ sandbox/src/java/org/apache/myfaces/examples/inputparam/EmployeeSearch.java (revision 0) @@ -0,0 +1,77 @@ +/* + * Copyright 2005 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.inputparam; + +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; + +/** + * Demonstrates use of the 'inputParam' component. + * The method 'filterEmployeesByType' creates a list of all employees, + * filtered by the parameter 'employeeTypeFilter' + * + * @author Sharath Reddy (latest modification by $Author$) + * @version $Revision$ $Date$ + */ +public class EmployeeSearch { + + public static String MANAGER = "MANAGER"; + public static String CONSULTANT = "CONSULTANT"; + + private static List _employees; + + private List _filteredEmployees = new ArrayList(); + private String _employeeTypeFilter = MANAGER; + + public List getFilteredEmployees() + { + return _filteredEmployees; + } + + static { + + _employees = new ArrayList(); + _employees.add(new Employee("John Doe", MANAGER)); + _employees.add(new Employee("Joe Green", CONSULTANT)); + _employees.add(new Employee("James Wood", CONSULTANT)); + _employees.add(new Employee("Tod Gilbert", MANAGER)); + } + + public void setEmployeeTypeFilter(String filter) { + _employeeTypeFilter = filter; + } + + public String getEmployeeTypeFilter() { + return _employeeTypeFilter; + } + + public String filterEmployeesByType() { + List filteredEmployees = new ArrayList(); + Iterator it = _employees.iterator(); + while (it.hasNext()) { + Employee emp = (Employee) it.next(); + if (emp.getType().equals(_employeeTypeFilter)) { + filteredEmployees.add(emp); + } + } + this._filteredEmployees = filteredEmployees; + + return "search"; + } +} + + Index: sandbox/inputparam.jsp =================================================================== --- sandbox/inputparam.jsp (revision 0) +++ sandbox/inputparam.jsp (revision 0) @@ -0,0 +1,111 @@ +<%@ 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/sandbox" prefix="x"%> + + + + + <%@include file="inc/head.inc" %> + + + + +
+ + + + +
+ + +
+ + + + +
+ + + + + + + + + + + + +
+ + +

+ + + + + + +
+  Description  +  
+ + + + + +
+ inputParam extends inputHidden by adding an attribute, paramValue, which allows value binding predefined form values to a managed bean. In our example, we have a managed bean named employeeSearch. We can filter the type of employees to search for with the setEmployeeTypeFilter method on this bean. +
+<h:form>
+ <x:inputParam value="#{employeeSearch.employeeTypeFilter}" paramValue="MANAGER"/>
+<h:commandLink action="#{employeeSearch.filterEmployeesByType}"/>
+</h:form>
+
+renders:
+
+ <input type="hidden" value="MANAGER"/>
+
+Depending on which form/commandLink is clicked, employeeSearch.setEmployeeTypeFilter is called with the appropriate value. There is no need to look in the request for the parameters of the search. If we need to filter by a new employee type, we can create a new form/commandLink and specify the new parameter. +
+
+ + + + + + + + + + + + + + + + + + + + + + <%@include file="inc/page_footer.jsp" %> + + --0-635839919-1124285995=:68920 Content-Type: text/plain; name=sandbox Content-Description: 4257598581-sandbox Content-Disposition: inline; filename=sandbox Index: tld/myfaces_sandbox.tld =================================================================== --- tld/myfaces_sandbox.tld (revision 233136) +++ tld/myfaces_sandbox.tld (working copy) @@ -578,5 +578,24 @@ + + + inputparam + org.apache.myfaces.custom.inputparam.HtmlInputParamTag + JSP + + Extends the functionality provided by myfaces inputHidden + + &ui_input_attributes; + &ext_forceId_attribute; + + paramValue + true + false + java.lang.String + Value to bind to the 'Value' attribute + + + Index: conf/faces-config.xml =================================================================== --- conf/faces-config.xml (revision 233136) +++ conf/faces-config.xml (working copy) @@ -49,6 +49,11 @@ org.apache.myfaces.custom.form.HtmlForm + + org.apache.myfaces.HtmlInputParam + org.apache.myfaces.custom.inputparam.HtmlInputParam + + @@ -95,6 +100,12 @@ org.apache.myfaces.custom.form.HtmlFormRenderer + + javax.faces.Hidden + org.apache.myfaces.Param + org.apache.myfaces.custom.inputparam.HtmlInputParamRenderer + + Index: src/java/org/apache/myfaces/custom/inputparam/HtmlInputParamTag.java =================================================================== --- src/java/org/apache/myfaces/custom/inputparam/HtmlInputParamTag.java (revision 0) +++ src/java/org/apache/myfaces/custom/inputparam/HtmlInputParamTag.java (revision 0) @@ -0,0 +1,74 @@ +/* + * 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.inputparam; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.myfaces.taglib.html.HtmlInputHiddenTagBase; + +/** + * Represents an html input element of type hidden the value of which can be + * used to set a bean method parameter value. This allows predefined form + * parameters to be set on a managed bean. For example, if you have a managed + * bean named searchBean with a setLastModified(Date d) method you can + * create a hidden form element with a preset date: + *

+ * + * <x:inputParam value="#{searchBean.lastModified}" paramValue="04/05/2005"> + * <f:convertDateTime type="date" dateStyle="short"/> + * </x:inputParam> + * + *

+ * + * @author rob@objectsource.org (latest modification by $Author$) + * @version $Revision$ $Date$ + */ +public class HtmlInputParamTag extends HtmlInputHiddenTagBase { + private final Log log = LogFactory.getLog(getClass()); + private String _paramValue; + + public HtmlInputParamTag() { + super(); + } + + public String getComponentType() { + return HtmlInputParam.COMPONENT_TYPE; + } + + public String getRendererType() { + return HtmlInputParam.DEFAULT_RENDERER_TYPE; + } + + public void release() + { + super.release(); + _paramValue = null; + } + + protected void setProperties(UIComponent component) + { + super.setProperties(component); + FacesContext context = getFacesContext(); + setStringProperty(component, "paramValue", _paramValue); + } + + public void setParamValue(String value) { + this._paramValue = value; + } +} Index: src/java/org/apache/myfaces/custom/inputparam/HtmlInputParam.java =================================================================== --- src/java/org/apache/myfaces/custom/inputparam/HtmlInputParam.java (revision 0) +++ src/java/org/apache/myfaces/custom/inputparam/HtmlInputParam.java (revision 0) @@ -0,0 +1,88 @@ +/* + * 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.inputparam; + +import javax.faces.context.FacesContext; +import javax.faces.el.ValueBinding; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.myfaces.component.html.ext.HtmlInputHidden; + +/** + * HtmlInputParam extends HtmlInputHidden by adding an attribute, paramValue, + * which allows value-binding predefined form values to a managed bean. + * For example, if you have a managed bean named searchBean with a + * setLastModified(Date d) method you can create a hidden form element + * with a preset date: + *

+ * + * <x:inputParam value="#{searchBean.lastModified}" paramValue="04/05/2005"> + * <f:convertDateTime type="date" dateStyle="short"/> + * </x:inputParam> + * + *

+ * + * @author rob@objectsource.org (latest modification by $Author$) + * @version $Revision$ $Date$ + + */ +public class HtmlInputParam extends HtmlInputHidden { + + private final Log log = LogFactory.getLog(getClass()); + public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlInputParam"; + static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Param"; + static final String COMPONENT_FAMILY = "javax.faces.Hidden"; + + String _paramValue; + + public HtmlInputParam() { + super(); + setRendererType(DEFAULT_RENDERER_TYPE); + } + + public String getFamily() + { + return COMPONENT_FAMILY; + } + + public String getParamValue() + { + if (_paramValue != null) return _paramValue; + ValueBinding vb = getValueBinding("paramValue"); + return vb != null ? (String) vb.getValue(getFacesContext()) : null; + } + + public void setParamValue(String paramValue) + { + _paramValue = paramValue; + } + + public Object saveState(FacesContext context) + { + Object values[] = new Object[2]; + values[0] = super.saveState(context); + values[1] = _paramValue; + return ((Object) (values)); + } + + public void restoreState(FacesContext context, Object state) + { + Object values[] = (Object[])state; + super.restoreState(context, values[0]); + _paramValue = (String) values[1]; + } +} Index: src/java/org/apache/myfaces/custom/inputparam/HtmlInputParamRenderer.java =================================================================== --- src/java/org/apache/myfaces/custom/inputparam/HtmlInputParamRenderer.java (revision 0) +++ src/java/org/apache/myfaces/custom/inputparam/HtmlInputParamRenderer.java (revision 0) @@ -0,0 +1,70 @@ +/* + * 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.inputparam; + +import java.io.IOException; + +import javax.faces.component.UIComponent; +import javax.faces.component.UIInput; +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; + +import org.apache.myfaces.renderkit.JSFAttr; +import org.apache.myfaces.renderkit.RendererUtils; +import org.apache.myfaces.renderkit.html.HTML; +import org.apache.myfaces.renderkit.html.HtmlHiddenRenderer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +/** + * Renders an html input element of type hidden with a value attribute set to the paramValue + * attribute value of the HtmlInputParam component being rendered. + * + * @author rob@objectsource.org (latest modification by $Author$) + * @version $Revision$ $Date$ + */ +public class HtmlInputParamRenderer extends HtmlHiddenRenderer { + private final Log log = LogFactory.getLog(getClass()); + + public HtmlInputParamRenderer() { + super(); + } + + public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) + throws IOException { + RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class); + + ResponseWriter writer = facesContext.getResponseWriter(); + + writer.startElement(HTML.INPUT_ELEM, uiComponent); + writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null); + + String clientId = uiComponent.getClientId(facesContext); + writer.writeAttribute(HTML.ID_ATTR, clientId, null); + writer.writeAttribute(HTML.NAME_ATTR, clientId, null); + + String value = ((HtmlInputParam) uiComponent).getParamValue(); + + if (value == null) value = RendererUtils.getStringValue(facesContext, uiComponent); + if (value != null) + { + writer.writeAttribute(HTML.VALUE_ATTR, value, JSFAttr.VALUE_ATTR); + } + + writer.endElement(HTML.INPUT_ELEM); + } + +} --0-635839919-1124285995=:68920--