Added automatic checkbox handling code that detect an unchecked checkbox and

add it as a parameter with a default (usually 'false') value.  Uses a specially
named hidden field to detect unsubmitted checkboxes.  The default unchecked value
is overridable for non-boolean value'd checkboxes. Minor source formatting and cleaned
out an empty directory.

WW-992 WW-1372 WW-1349


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@442085 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2006-09-11 04:03:24 +00:00
parent 6ed8a90fb1
commit 046059e618
8 changed files with 30 additions and 21 deletions
@@ -59,21 +59,21 @@ import com.opensymphony.xwork2.interceptor.Interceptor;
* <b>Example struts.xml configuration:</b>
*
* <pre>
* &lt;interceptor-ref name=&quot;jsfSetup&quot;&gt;
* &lt;param name=&quot;actionListener&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;defaultRenderKitId&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;supportedLocale&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;defaultLocale&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;messageBundle&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;navigationHandler&quot;&gt;org.apache.struts2.jsf.StrutsNavigationHandler&lt;/param&gt;
* &lt;param name=&quot;propertyResolver&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;stateManager&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;variableResolver&quot;&gt;
* org.apache.myfaces.el.VariableResolverImpl
* ,org.apache.struts2.jsf.StrutsVariableResolver
* &lt;/param&gt;
* &lt;param name=&quot;viewHandler;&quot;&gt;org.apache.shale.tiles.TilesViewHandler&lt;/param&gt;
* &lt;/interceptor-ref&gt;
* &lt;interceptor-ref name=&quot;jsfSetup&quot;&gt;
* &lt;param name=&quot;actionListener&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;defaultRenderKitId&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;supportedLocale&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;defaultLocale&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;messageBundle&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;navigationHandler&quot;&gt;org.apache.struts2.jsf.StrutsNavigationHandler&lt;/param&gt;
* &lt;param name=&quot;propertyResolver&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;stateManager&quot;&gt;&lt;/param&gt;
* &lt;param name=&quot;variableResolver&quot;&gt;
* org.apache.myfaces.el.VariableResolverImpl
* ,org.apache.struts2.jsf.StrutsVariableResolver
* &lt;/param&gt;
* &lt;param name=&quot;viewHandler;&quot;&gt;org.apache.shale.tiles.TilesViewHandler&lt;/param&gt;
* &lt;/interceptor-ref&gt;
* </pre>
*
* <p>
@@ -209,16 +209,16 @@ public class FacesSetupInterceptor extends FacesSupport implements Interceptor {
* The action invocation
*/
public String intercept(ActionInvocation invocation) throws Exception {
if (facesContextFactory != null)
{
if (facesContextFactory != null) {
if (isFacesAction(invocation)) {
invocation.getInvocationContext().put(
FacesInterceptor.FACES_ENABLED, Boolean.TRUE);
FacesContext facesContext = facesContextFactory.getFacesContext(
ServletActionContext.getServletContext(),
ServletActionContext.getRequest(), ServletActionContext
FacesContext facesContext = facesContextFactory
.getFacesContext(ServletActionContext
.getServletContext(), ServletActionContext
.getRequest(), ServletActionContext
.getResponse(), lifecycle);
setLifecycle(lifecycle);
@@ -230,7 +230,8 @@ public class FacesSetupInterceptor extends FacesSupport implements Interceptor {
}
}
} else {
throw new StrutsException("Unable to initialize jsf interceptors probably due missing JSF implementation libraries",
throw new StrutsException(
"Unable to initialize jsf interceptors probably due missing JSF implementation libraries",
invocation.getProxy().getConfig());
}
return invocation.invoke();
@@ -51,6 +51,7 @@
<interceptor name="validation" class="com.opensymphony.xwork2.validator.ValidationInterceptor"/>
<interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>
<interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" />
<interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" />
<!-- JSF interceptors, one per lifecycle phase -->
<interceptor class="org.apache.struts2.jsf.FacesSetupInterceptor" name="jsfSetup" />
@@ -156,6 +157,7 @@
<interceptor-ref name="model-driven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="static-params"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
@@ -26,3 +26,4 @@
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
<input type="hidden" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}"/>
@@ -3,6 +3,7 @@
</td>
<td valign="top" align="left">
<input type="checkbox" name="foo" value="baz" checked="checked" id="someId" title="mytitle" onfocus="test();"/>
<input type="hidden" name="__checkbox_foo" value="baz"/>
<label for="someId" class="checkboxLabel">mylabel</label>
</td>
</tr>
@@ -3,6 +3,7 @@
</td>
<td valign="top" align="left">
<input type="checkbox" name="foo" value="baz" id="foo" title="mytitle"/>
<input type="hidden" name="__checkbox_foo" value="baz"/>
<label for="foo" class="checkboxLabel">mylabel</label>
</td>
</tr>
@@ -10,6 +10,7 @@
</td>
<td valign="top" align="left">
<input type="checkbox" name="foo" value="baz" checked="checked" id="foo" title="mytitle" onclick="test();" ondblclick="test();"/>
<input type="hidden" name="__checkbox_foo" value="baz"/>
<label for="foo" class="checkboxErrorLabel">mylabel</label>
</td>
</tr>
@@ -6,5 +6,6 @@
<tr>
<td colspan="2">
<input type="checkbox" name="foo" value="baz" checked="checked" id="someId" title="mytitle" onfocus="test();"/>
<input type="hidden" name="__checkbox_foo" value="baz"/>
</td>
</tr>
@@ -4,5 +4,6 @@
</td>
<td valign="top" align="left">
<input type="checkbox" name="foo" value="baz" checked="checked" id="someId" title="mytitle" onfocus="test();"/>
<input type="hidden" name="__checkbox_foo" value="baz"/>
</td>
</tr>