You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/01/27 08:11:29 UTC
svn commit: r372773 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/subform/ core/src/main/tld/
examples/src/main/java/org/apache/myfaces/examples/subform/
examples/src/main/webapp/ examples/src/main/webapp/WEB-INF/
Author: mmarinschek
Date: Thu Jan 26 23:11:06 2006
New Revision: 372773
URL: http://svn.apache.org/viewcvs?rev=372773&view=rev
Log:
bug-fixes in subform, added example for the partial validation possible with it
Added:
myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/subform/
myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/subform/SubFormBean.java
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/subForm.jsp
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java?rev=372773&r1=372772&r2=372773&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java Thu Jan 26 23:11:06 2006
@@ -1,11 +1,11 @@
package org.apache.myfaces.custom.subform;
-import javax.faces.component.UIComponentBase;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
/**
* @author Gerald Muellan
@@ -41,10 +41,21 @@
boolean tearDownRequired = setupPartialInfo(context);
- for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
+ Boolean partialEnabled = (Boolean) context.getExternalContext().getRequestMap().get(PARTIAL_ENABLED);
+
+ //todo: boolean childSubmitted = checkUICommandChildren(this,context);
+
+ if(partialEnabled!=null && partialEnabled.booleanValue())
{
- UIComponent childOrFacet = (UIComponent)it.next();
- childOrFacet.processValidators(context);
+ for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processValidators(context);
+ }
+ }
+ else
+ {
+ processSubFormValidators(this,context);
}
if(tearDownRequired)
@@ -53,6 +64,68 @@
}
}
+ public void processUpdates(FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+ if (!isRendered()) return;
+
+ boolean tearDownRequired = setupPartialInfo(context);
+
+ Boolean partialEnabled = (Boolean) context.getExternalContext().getRequestMap().get(PARTIAL_ENABLED);
+
+ if(partialEnabled!=null && partialEnabled.booleanValue())
+ {
+ for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processUpdates(context);
+ }
+ }
+ else
+ {
+ processSubFormUpdates(this,context);
+ }
+
+ if(tearDownRequired)
+ {
+ tearDownPartialInfo(context);
+ }
+ }
+
+ private static void processSubFormUpdates(UIComponent comp, FacesContext context)
+ {
+ for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+
+ if(childOrFacet instanceof SubForm)
+ {
+ childOrFacet.processUpdates(context);
+ }
+ else
+ {
+ processSubFormUpdates(childOrFacet, context);
+ }
+ }
+ }
+
+ private static void processSubFormValidators(UIComponent comp, FacesContext context)
+ {
+ for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+
+ if(childOrFacet instanceof SubForm)
+ {
+ childOrFacet.processValidators(context);
+ }
+ else
+ {
+ processSubFormValidators(childOrFacet, context);
+ }
+ }
+ }
+
/**Sets up information if this component is included in
* the group of components which are associated with the current action.
*
@@ -78,18 +151,9 @@
List li = (List) context.getExternalContext().getRequestMap().get(
ACTION_FOR_LIST);
- //check if the list is existing at all - if not, we want to validate in any case.
- if(li==null || li.size()==0)
- {
- if(!context.getExternalContext().getRequestMap().containsKey(PARTIAL_ENABLED))
- {
- context.getExternalContext().getRequestMap().put(PARTIAL_ENABLED,Boolean.TRUE);
- tearDownRequired = true;
- }
- }
//if there is a list, check if the current client id
//matches an entry of the list
- else if(li.contains(getClientId(context)))
+ if(li != null && li.contains(getClientId(context)))
{
if(!context.getExternalContext().getRequestMap().containsKey(PARTIAL_ENABLED))
{
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=372773&r1=372772&r2=372773&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Thu Jan 26 23:11:06 2006
@@ -934,10 +934,15 @@
<tag-class>org.apache.myfaces.custom.subform.SubFormTag</tag-class>
<body-content>JSP</body-content>
<description>
+ A subform to an existing form. Inputs in this form will
+ only be validated and updated, if a t:commandButton or t:commandLink has been clicked
+ with an actionFor attribute which references the client-id of this subform.
+ Optionally, the validation will trigger if a commandButton or commandLink embedded in this
+ subform has been clicked, except if this command is a t:commandButton or t:commandLink with an
+ actionFor attribute which doesn't reference the client-id of this subform.
</description>
-
-
+ &ui_form_attributes;
</tag>
<!-- <tag>
Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/subform/SubFormBean.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/subform/SubFormBean.java?rev=372773&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/subform/SubFormBean.java (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/subform/SubFormBean.java Thu Jan 26 23:11:06 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.subform;
+
+/**
+ *
+ * @author Martin Marinschek
+ * @version $Revision$ $Date$
+ */
+public class SubFormBean
+{
+ private String _firstName;
+ private String _lastName;
+ private String _type;
+ private String _make;
+
+ public String getFirstName()
+ {
+ return _firstName;
+ }
+
+ public void setFirstName(String firstName)
+ {
+ _firstName = firstName;
+ }
+
+ public String getLastName()
+ {
+ return _lastName;
+ }
+
+ public void setLastName(String lastName)
+ {
+ _lastName = lastName;
+ }
+
+ public String getType()
+ {
+ return _type;
+ }
+
+ public void setType(String type)
+ {
+ _type = type;
+ }
+
+ public String getMake()
+ {
+ return _make;
+ }
+
+ public void setMake(String make)
+ {
+ _make = make;
+ }
+}
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml?rev=372773&r1=372772&r2=372773&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml Thu Jan 26 23:11:06 2006
@@ -8,6 +8,13 @@
<faces-config>
+ <!-- managed bean for subForm-->
+
+ <managed-bean>
+ <managed-bean-name>subFormBean</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.examples.subform.SubFormBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
<!-- managed bean for autoUpdateDataTable-->
@@ -20,7 +27,7 @@
<!-- managed bean for ajaxInputSuggest-->
- <managed-bean>
+ <managed-bean>
<managed-bean-name>inputSuggestAjax</managed-bean-name>
<managed-bean-class>org.apache.myfaces.examples.inputSuggestAjax.InputSuggestAjaxBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
@@ -28,11 +35,11 @@
<!-- Managed Beans for inputSuggest.jsp -->
- <managed-bean>
- <managed-bean-name>user</managed-bean-name>
- <managed-bean-class>org.apache.myfaces.examples.inputsuggest.User</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
+ <managed-bean>
+ <managed-bean-name>user</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.examples.inputsuggest.User</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
<!-- managed bean for inputAjax components -->
<managed-bean>
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml?rev=372773&r1=372772&r2=372773&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml Thu Jan 26 23:11:06 2006
@@ -6,7 +6,7 @@
(e.g. /WEB-INF/my-config.xml)
See JSF 1.0 PRD2, 10.3.2</description>
<param-name>javax.faces.CONFIG_FILES</param-name>
- <param-value>/WEB-INF/examples-config.xml</param-value>
+ <param-value>/WEB-INF/examples-config.xml,/WEB-INF/sandbox/faces-config.xml</param-value>
</context-param>
<context-param>
<description>State saving method: "client" or "server" (= default)
Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/subForm.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/subForm.jsp?rev=372773&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/subForm.jsp (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/subForm.jsp Thu Jan 26 23:11:06 2006
@@ -0,0 +1,82 @@
+<%@ 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/tomahawk" prefix="t"%>
+<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
+<html>
+
+<%@include file="inc/head.inc" %>
+
+<!--
+/*
+ * 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.
+ */
+//-->
+
+<body>
+
+<f:view>
+ <h:form>
+ <h:panelGrid>
+ <t:messages showDetail="true" showSummary="false"/>
+ <h:outputText value="Example for partial validation"/>
+ <s:subForm id="personForm">
+ <h:outputText value="Person" style="font-weight:bold;"/>
+ <h:panelGrid columns="2">
+ <h:outputLabel for="firstName" value="First name:"/>
+ <h:inputText id="firstName" value="#{subFormBean.firstName}" required="true"/>
+ <h:outputLabel for="lastName" value="Last name:"/>
+ <h:inputText id="lastName" value="#{subFormBean.lastName}" required="true"/>
+ </h:panelGrid>
+ <h:commandButton value="Show current values of Person"/>
+ </s:subForm>
+
+ <s:subForm id="vehicleForm">
+ <h:outputText value="Vehicle" style="font-weight:bold;"/>
+ <h:panelGrid columns="2">
+ <h:outputLabel for="firstName" value="Type:"/>
+ <h:inputText id="firstName" value="#{subFormBean.type}" required="true"/>
+ <h:outputLabel for="lastName" value="Make:"/>
+ <h:inputText id="lastName" value="#{subFormBean.make}" required="true"/>
+ </h:panelGrid>
+ <h:commandButton value="Show current values of Vehicle"/>
+ </s:subForm>
+
+ <t:commandButton value="Show current values of Person" actionFor="personForm"/>
+ <t:commandButton value="Show current values of Vehicle" actionFor="vehicleForm"/>
+ <t:commandButton value="Show current values of Person and Vehicle (actionFor for both forms set)" actionFor="personForm,vehicleForm"/>
+ <h:commandButton value="Show current values of Person and Vehicle (no actionFor set), standard button"/>
+ <t:commandButton value="Show current values of Person and Vehicle (no actionFor set), extended button"/>
+
+ <h:panelGrid columns="2">
+ <h:outputText value="First name of Person:"/>
+ <h:outputText value="#{subFormBean.firstName}"/>
+ <h:outputText value="Last name of Person:"/>
+ <h:outputText value="#{subFormBean.lastName}"/>
+ <h:outputText value="Type of vehicle:"/>
+ <h:outputText value="#{subFormBean.type}"/>
+ <h:outputText value="Make of vehicle:"/>
+ <h:outputText value="#{subFormBean.make}"/>
+ </h:panelGrid>
+ </h:panelGrid>
+
+ </h:form>
+</f:view>
+
+<%@include file="inc/page_footer.jsp" %>
+
+</body>
+
+</html>