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
Index: sandbox/home.jsp
===================================================================
--- sandbox/home.jsp (revision 233158)
+++ sandbox/home.jsp (working copy)
@@ -24,7 +24,7 @@
<h:outputLink value="inputSuggestAjax.jsf"
><f:verbatim>InputSuggestAjax</f:verbatim></h:outputLink> <br/>
<h:outputLink value="inputSuggest.jsf" ><f:verbatim>Input
Suggest</f:verbatim></h:outputLink> <br/>
<h:outputLink value="schedule.jsf"
><f:verbatim>Schedule</f:verbatim></h:outputLink> <br/>
-
+ <h:outputLink value="inputparam.jsf" ><f:verbatim>Param
Value</f:verbatim></h:outputLink> <br/>
</f:view>
</html>
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 @@
</managed-property>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>employeeSearch</managed-bean-name>
+
<managed-bean-class>org.apache.myfaces.examples.inputparam.EmployeeSearch</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
+ <navigation-rule>
+ <from-view-id>/inputparam.jsp</from-view-id>
+ <navigation-case>
+ <from-outcome>search</from-outcome>
+ <to-view-id>/inputparam.jsp</to-view-id>
+ </navigation-case>
+ </navigation-rule>
+
</faces-config>
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"%>
+
+<!--
+/*
+ * 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.
+ */
+//-->
+<html>
+
+ <[EMAIL PROTECTED] file="inc/head.inc" %>
+
+ <body>
+ <f:view>
+ <h:form>
+ <br/>
+ <x:inputparam value="#{employeeSearch.employeeTypeFilter}"
paramValue="MANAGER" />
+ <h:commandLink
action="#{employeeSearch.filterEmployeesByType}">
+ <h:outputText value="Search for employees of type
'Manager'"/>
+ </h:commandLink>
+ </h:form>
+
+ <h:form>
+ <br/>
+ <x:inputparam value="#{employeeSearch.employeeTypeFilter}"
paramValue="CONSULTANT" />
+ <h:commandLink
action="#{employeeSearch.filterEmployeesByType}">
+ <h:outputText value="Search for employees of type
'Consultant'"/>
+ </h:commandLink>
+ </h:form>
+
+
+ <h:outputText value="Results:"/>
+ <h:dataTable value="#{employeeSearch.filteredEmployees}"
var="emp">
+ <h:column>
+ <h:outputText value="#{emp.name}"/>
+ </h:column>
+ <h:column>
+ <h:outputText value="#{emp.type}"/>
+ </h:column>
+ </h:dataTable>
+
+ </f:view>
+
+
+<br><br>
+
+<table cellpadding=2 cellspacing=0 border=0 width=100% align=center>
+<tr>
+ <td bgcolor=bbbbbb width=1% nowrap align=center>
+ <font color=ffffff><b>Description</b></font>
+ </td>
+ <td> </td>
+</tr>
+</table>
+
+<table cellpadding=2 cellspacing=0 border=1 width=100%>
+<tr>
+ <td bgcolor=ffffff valign=top>
+ 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.
+<br>
+<h:form> <br>
+ <x:inputParam value="#{employeeSearch.employeeTypeFilter}"
paramValue="MANAGER"/><br>
+<h:commandLink
action="#{employeeSearch.filterEmployeesByType}"/><br>
+</h:form><br>
+<br>
+renders:<br>
+<br>
+ <input type="hidden" value="MANAGER"/><br>
+<br>
+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.
+ <br>
+ </td>
+</tr>
+</table>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ </body>
+
+ <[EMAIL PROTECTED] file="inc/page_footer.jsp" %>
+
+</html>
Index: tld/myfaces_sandbox.tld
===================================================================
--- tld/myfaces_sandbox.tld (revision 233136)
+++ tld/myfaces_sandbox.tld (working copy)
@@ -578,5 +578,24 @@
</attribute>
</tag>
+ <!-- inputparam -->
+ <tag>
+ <name>inputparam</name>
+
<tag-class>org.apache.myfaces.custom.inputparam.HtmlInputParamTag</tag-class>
+ <body-content>JSP</body-content>
+ <description>
+ Extends the functionality provided by myfaces inputHidden
+ </description>
+ &ui_input_attributes;
+ &ext_forceId_attribute;
+ <attribute>
+ <name>paramValue</name>
+ <required>true</required>
+ <rtexprvalue>false</rtexprvalue>
+ <type>java.lang.String</type>
+ <description>Value to bind to the 'Value' attribute</description>
+ </attribute>
+ </tag>
+
</taglib>
Index: conf/faces-config.xml
===================================================================
--- conf/faces-config.xml (revision 233136)
+++ conf/faces-config.xml (working copy)
@@ -49,6 +49,11 @@
<component-class>org.apache.myfaces.custom.form.HtmlForm</component-class>
</component>
+ <component>
+ <component-type>org.apache.myfaces.HtmlInputParam</component-type>
+
<component-class>org.apache.myfaces.custom.inputparam.HtmlInputParam</component-class>
+ </component>
+
<!-- sandbox renderkit -->
<render-kit>
@@ -95,6 +100,12 @@
<renderer-class>org.apache.myfaces.custom.form.HtmlFormRenderer</renderer-class>
</renderer>
+ <renderer>
+ <component-family>javax.faces.Hidden</component-family>
+ <renderer-type>org.apache.myfaces.Param</renderer-type>
+
<renderer-class>org.apache.myfaces.custom.inputparam.HtmlInputParamRenderer</renderer-class>
+ </renderer>
+
</render-kit>
<lifecycle>
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:
+ * <p>
+ * <code>
+ * <x:inputParam value="#{searchBean.lastModified}"
paramValue="04/05/2005">
+ * <f:convertDateTime type="date" dateStyle="short"/>
+ * </x:inputParam>
+ * </code>
+ * </p>
+ *
+ * @author [EMAIL PROTECTED] (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:
+ * <p>
+ * <code>
+ * <x:inputParam value="#{searchBean.lastModified}"
paramValue="04/05/2005">
+ * <f:convertDateTime type="date" dateStyle="short"/>
+ * </x:inputParam>
+ * </code>
+ * </p>
+ *
+ * @author [EMAIL PROTECTED] (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 [EMAIL PROTECTED] (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);
+ }
+
+}