You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Devine <de...@gmail.com> on 2006/03/29 22:47:05 UTC
[Shale] commons client side validation not working inside a dataList
I tried using the commons validation features of Shale. The application is
using Myfaces 1.1.1. The validation javascript is being written back to the
browser. The server side validation is working fine but a javascript `field
error occurs during the . However there is a problem with the client side
input element Id's that the javascript validation is looking for versus the
client side id's that are generated by the dataList. The page i tried
validation on has a Myfaces dataList inside a form, and for each iteration
through the list there are inputs. Basically a dataList will append the `row
index` to the client side Id to guarantee uniqueness, as in
"myForm:myDataList_0:someRequiredField" for the first row,
"myForm:myDataList_1:someRequiredField" for the second, and so on. But in
the rendering of the javascript by the struts validatorScript tag, the
clientId of the input components lose their row index.
I have created an illustrative example that generates the same problem. The
code is included below and the inline comments hopefully explain what's
happening. To keep things simple there is no backing bean, and I use a
class from shale-core to give me some objects to edit, so all you'd just
need to deploy into a shale-core based "blank" web-app. My application page
is more complex than this but I am running into exact the same problem
withthe validation javascript
Does this look familiar to anyone? Any workarounds, solutions?...
Thanks
-- Paul Devine
<%@ page language="java" import="java.util.*,
org.apache.shale.dialog.impl.DialogImpl"%>
<%@ 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="t"%>
<%@ taglib uri="http://struts.apache.org/shale/core" prefix="s" %>
<%
/* Put a couple of Shale DialogImpl objects into the session (we just need
an object with a getter and a setter
* and this class is readily accessible)
*/
List inputObjects = new ArrayList();
inputObjects.add(new DialogImpl());
inputObjects.add(new DialogImpl());
session.setAttribute("someInputObjects",inputObjects);
%>
<f:view>
<%--
A form with a dataList of inputs. The client side id's of the components
will be
someForm:someDataList_0:someRequiredField and
someForm:someDataList_1:someRequiredField
--%>
<h:form id="someForm" onsubmit="return validateForm(this);">
<t:dataList id="someDataList" value="#{someInputObjects}" var="object"
rowIndexVar="index">
<h:outputLabel value="Name"/>
<h:inputText id="someRequiredField" value="#{object.name}" size="20"
required="true">
<s:commonsValidator type="required" arg="Name" server="true"
client="true"/>
</h:inputText><h:message for="someRequiredField"
errorClass="errorMessage"/>
</t:dataList>
<%--
The dataList is now closed. Before we close out the form, write out the
validator javascript. But
this results in a mismatch on the client side id's in the required function.
Note the uniqueness
indexes _0 and _1 are missing. Because we are outside the
dataList there is no "row index" anymore (and for some reason the
HtmlInputText components `calculate`
their clientId's again when asked for getClientId from Shale's
ValidatorScript findCommonsValidators method
Here's what the validatorScript comes up with:-
function required() {
this[0] = new Array("someForm:someDataList:someRequiredField", "Name is
required.", new Function("x", "return {}[x];"));
}
--%>
<s:validatorScript functionName="validateForm"/>
<h:commandButton action="submit"/>
</h:form>
</f:view>
Re: [Shale] commons client side validation not working inside a dataList
Posted by Paul Devine <de...@gmail.com>.
Thanks Hermod
When I use t:inputText with forceid="true", I still get the javascript
error. In that case, the client side inputs that are generated are:
<label>Name</label><input id="someRequiredField[0]"
name="someRequiredField[0]" type="text" value="" size="20" />
<label>Name</label><input id="someRequiredField[1]"
name="someRequiredField[1]" type="text" value="" size="20" />
and the generated javascript validation routine is still missing the
uniqueness index:-
function required() {
this[0] = new Array("someRequiredField", "Name is required.", new
Function("x", "return {}[x];"));
}
I would think I need the required() function to be something like the
following for all this to work:
function required() {
this[0] = new Array("someRequiredField[0]", "Name is required.", new
Function("x", "return {}[x];"));
this[1] = new Array("someRequiredField[1]", "Name is required.", new
Function("x", "return {}[x];"));
}
?...
Thanks
-- Paul
On 3/29/06, Hermod Opstvedt <he...@opstvedt.com> wrote:
>
> Hi
>
> Did I hear forceId? - You need to use this attribute to force the name to
> be
> what you want.
>
> Hermod
>
>
> -----Opprinnelig melding-----
> Fra: Paul Devine [mailto:devinesy@gmail.com]
> Sendt: 29. mars 2006 22:47
> Til: user@struts.apache.org
> Emne: [Shale] commons client side validation not working inside a dataList
>
> I tried using the commons validation features of Shale. The application is
> using Myfaces 1.1.1. The validation javascript is being written back to
> the
> browser. The server side validation is working fine but a javascript
> `field
> error occurs during the . However there is a problem with the client side
> input element Id's that the javascript validation is looking for versus
> the
> client side id's that are generated by the dataList. The page i tried
> validation on has a Myfaces dataList inside a form, and for each iteration
> through the list there are inputs. Basically a dataList will append the
> `row
> index` to the client side Id to guarantee uniqueness, as in
> "myForm:myDataList_0:someRequiredField" for the first row,
> "myForm:myDataList_1:someRequiredField" for the second, and so on. But in
> the rendering of the javascript by the struts validatorScript tag, the
> clientId of the input components lose their row index.
>
> I have created an illustrative example that generates the same problem.
> The
> code is included below and the inline comments hopefully explain what's
> happening. To keep things simple there is no backing bean, and I use a
> class from shale-core to give me some objects to edit, so all you'd just
> need to deploy into a shale-core based "blank" web-app. My application
> page
> is more complex than this but I am running into exact the same problem
> withthe validation javascript
>
> Does this look familiar to anyone? Any workarounds, solutions?...
>
> Thanks
> -- Paul Devine
>
> <%@ page language="java" import="java.util.*,
> org.apache.shale.dialog.impl.DialogImpl"%>
> <%@ 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="t"%>
> <%@ taglib uri="http://struts.apache.org/shale/core" prefix="s" %>
> <%
> /* Put a couple of Shale DialogImpl objects into the session (we just need
> an object with a getter and a setter
> * and this class is readily accessible)
> */
> List inputObjects = new ArrayList();
> inputObjects.add(new DialogImpl());
> inputObjects.add(new DialogImpl());
> session.setAttribute("someInputObjects",inputObjects);
> %>
> <f:view>
> <%--
> A form with a dataList of inputs. The client side id's of the components
> will be
> someForm:someDataList_0:someRequiredField and
> someForm:someDataList_1:someRequiredField
> --%>
> <h:form id="someForm" onsubmit="return validateForm(this);">
> <t:dataList id="someDataList" value="#{someInputObjects}" var="object"
> rowIndexVar="index">
>
> <h:outputLabel value="Name"/>
> <h:inputText id="someRequiredField" value="#{object.name}" size="20"
> required="true">
> <s:commonsValidator type="required" arg="Name" server="true"
> client="true"/>
> </h:inputText><h:message for="someRequiredField"
> errorClass="errorMessage"/>
>
> </t:dataList>
> <%--
> The dataList is now closed. Before we close out the form, write out the
> validator javascript. But
> this results in a mismatch on the client side id's in the required
> function.
> Note the uniqueness
> indexes _0 and _1 are missing. Because we are outside the
> dataList there is no "row index" anymore (and for some reason the
> HtmlInputText components `calculate`
> their clientId's again when asked for getClientId from Shale's
> ValidatorScript findCommonsValidators method
> Here's what the validatorScript comes up with:-
> function required() {
> this[0] = new Array("someForm:someDataList:someRequiredField", "Name is
> required.", new Function("x", "return {}[x];"));
> }
> --%>
> <s:validatorScript functionName="validateForm"/>
> <h:commandButton action="submit"/>
> </h:form>
> </f:view>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
SV: SV: [Shale] commons client side validation not working inside a
dataList
Posted by Hermod Opstvedt <he...@opstvedt.com>.
Hi
I seem to remember that this issue has come up on the myfaces list, and that
the solution was to use forceId.
Hermod
-----Opprinnelig melding-----
Fra: news [mailto:news@sea.gmane.org] På vegne av Laurie Harper
Sendt: 30. mars 2006 00:07
Til: user@struts.apache.org
Emne: Re: SV: [Shale] commons client side validation not working inside a
dataList
Why would that be needed? The s:commonsValidator tag should render
Javascript referencing the actual rendered ID of the component it's
attached to. I haven't played much with validators, much less validators
for components inside dataLists, but I would have thought this should be
able to work as it is.
Paul, could you include your sample JSP and, if possible, copy/paste the
rendered HTML as well, in a Bugzilla ticket so the issue gets tracked?
L.
Hermod Opstvedt wrote:
> Hi
>
> Did I hear forceId? - You need to use this attribute to force the name to
be
> what you want.
>
> Hermod
>
>
> -----Opprinnelig melding-----
> Fra: Paul Devine [mailto:devinesy@gmail.com]
> Sendt: 29. mars 2006 22:47
> Til: user@struts.apache.org
> Emne: [Shale] commons client side validation not working inside a dataList
>
> I tried using the commons validation features of Shale. The application is
> using Myfaces 1.1.1. The validation javascript is being written back to
the
> browser. The server side validation is working fine but a javascript
`field
> error occurs during the . However there is a problem with the client side
> input element Id's that the javascript validation is looking for versus
the
> client side id's that are generated by the dataList. The page i tried
> validation on has a Myfaces dataList inside a form, and for each iteration
> through the list there are inputs. Basically a dataList will append the
`row
> index` to the client side Id to guarantee uniqueness, as in
> "myForm:myDataList_0:someRequiredField" for the first row,
> "myForm:myDataList_1:someRequiredField" for the second, and so on. But in
> the rendering of the javascript by the struts validatorScript tag, the
> clientId of the input components lose their row index.
>
> I have created an illustrative example that generates the same problem.
The
> code is included below and the inline comments hopefully explain what's
> happening. To keep things simple there is no backing bean, and I use a
> class from shale-core to give me some objects to edit, so all you'd just
> need to deploy into a shale-core based "blank" web-app. My application
page
> is more complex than this but I am running into exact the same problem
> withthe validation javascript
>
> Does this look familiar to anyone? Any workarounds, solutions?...
>
> Thanks
> -- Paul Devine
>
> <%@ page language="java" import="java.util.*,
> org.apache.shale.dialog.impl.DialogImpl"%>
> <%@ 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="t"%>
> <%@ taglib uri="http://struts.apache.org/shale/core" prefix="s" %>
> <%
> /* Put a couple of Shale DialogImpl objects into the session (we just need
> an object with a getter and a setter
> * and this class is readily accessible)
> */
> List inputObjects = new ArrayList();
> inputObjects.add(new DialogImpl());
> inputObjects.add(new DialogImpl());
> session.setAttribute("someInputObjects",inputObjects);
> %>
> <f:view>
> <%--
> A form with a dataList of inputs. The client side id's of the components
> will be
> someForm:someDataList_0:someRequiredField and
> someForm:someDataList_1:someRequiredField
> --%>
> <h:form id="someForm" onsubmit="return validateForm(this);">
> <t:dataList id="someDataList" value="#{someInputObjects}" var="object"
> rowIndexVar="index">
>
> <h:outputLabel value="Name"/>
> <h:inputText id="someRequiredField" value="#{object.name}" size="20"
> required="true">
> <s:commonsValidator type="required" arg="Name" server="true"
> client="true"/>
> </h:inputText><h:message for="someRequiredField"
> errorClass="errorMessage"/>
>
> </t:dataList>
> <%--
> The dataList is now closed. Before we close out the form, write out the
> validator javascript. But
> this results in a mismatch on the client side id's in the required
function.
> Note the uniqueness
> indexes _0 and _1 are missing. Because we are outside the
> dataList there is no "row index" anymore (and for some reason the
> HtmlInputText components `calculate`
> their clientId's again when asked for getClientId from Shale's
> ValidatorScript findCommonsValidators method
> Here's what the validatorScript comes up with:-
> function required() {
> this[0] = new Array("someForm:someDataList:someRequiredField", "Name is
> required.", new Function("x", "return {}[x];"));
> }
> --%>
> <s:validatorScript functionName="validateForm"/>
> <h:commandButton action="submit"/>
> </h:form>
> </f:view>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: SV: [Shale] commons client side validation not working inside
a dataList
Posted by Laurie Harper <la...@holoweb.net>.
Why would that be needed? The s:commonsValidator tag should render
Javascript referencing the actual rendered ID of the component it's
attached to. I haven't played much with validators, much less validators
for components inside dataLists, but I would have thought this should be
able to work as it is.
Paul, could you include your sample JSP and, if possible, copy/paste the
rendered HTML as well, in a Bugzilla ticket so the issue gets tracked?
L.
Hermod Opstvedt wrote:
> Hi
>
> Did I hear forceId? - You need to use this attribute to force the name to be
> what you want.
>
> Hermod
>
>
> -----Opprinnelig melding-----
> Fra: Paul Devine [mailto:devinesy@gmail.com]
> Sendt: 29. mars 2006 22:47
> Til: user@struts.apache.org
> Emne: [Shale] commons client side validation not working inside a dataList
>
> I tried using the commons validation features of Shale. The application is
> using Myfaces 1.1.1. The validation javascript is being written back to the
> browser. The server side validation is working fine but a javascript `field
> error occurs during the . However there is a problem with the client side
> input element Id's that the javascript validation is looking for versus the
> client side id's that are generated by the dataList. The page i tried
> validation on has a Myfaces dataList inside a form, and for each iteration
> through the list there are inputs. Basically a dataList will append the `row
> index` to the client side Id to guarantee uniqueness, as in
> "myForm:myDataList_0:someRequiredField" for the first row,
> "myForm:myDataList_1:someRequiredField" for the second, and so on. But in
> the rendering of the javascript by the struts validatorScript tag, the
> clientId of the input components lose their row index.
>
> I have created an illustrative example that generates the same problem. The
> code is included below and the inline comments hopefully explain what's
> happening. To keep things simple there is no backing bean, and I use a
> class from shale-core to give me some objects to edit, so all you'd just
> need to deploy into a shale-core based "blank" web-app. My application page
> is more complex than this but I am running into exact the same problem
> withthe validation javascript
>
> Does this look familiar to anyone? Any workarounds, solutions?...
>
> Thanks
> -- Paul Devine
>
> <%@ page language="java" import="java.util.*,
> org.apache.shale.dialog.impl.DialogImpl"%>
> <%@ 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="t"%>
> <%@ taglib uri="http://struts.apache.org/shale/core" prefix="s" %>
> <%
> /* Put a couple of Shale DialogImpl objects into the session (we just need
> an object with a getter and a setter
> * and this class is readily accessible)
> */
> List inputObjects = new ArrayList();
> inputObjects.add(new DialogImpl());
> inputObjects.add(new DialogImpl());
> session.setAttribute("someInputObjects",inputObjects);
> %>
> <f:view>
> <%--
> A form with a dataList of inputs. The client side id's of the components
> will be
> someForm:someDataList_0:someRequiredField and
> someForm:someDataList_1:someRequiredField
> --%>
> <h:form id="someForm" onsubmit="return validateForm(this);">
> <t:dataList id="someDataList" value="#{someInputObjects}" var="object"
> rowIndexVar="index">
>
> <h:outputLabel value="Name"/>
> <h:inputText id="someRequiredField" value="#{object.name}" size="20"
> required="true">
> <s:commonsValidator type="required" arg="Name" server="true"
> client="true"/>
> </h:inputText><h:message for="someRequiredField"
> errorClass="errorMessage"/>
>
> </t:dataList>
> <%--
> The dataList is now closed. Before we close out the form, write out the
> validator javascript. But
> this results in a mismatch on the client side id's in the required function.
> Note the uniqueness
> indexes _0 and _1 are missing. Because we are outside the
> dataList there is no "row index" anymore (and for some reason the
> HtmlInputText components `calculate`
> their clientId's again when asked for getClientId from Shale's
> ValidatorScript findCommonsValidators method
> Here's what the validatorScript comes up with:-
> function required() {
> this[0] = new Array("someForm:someDataList:someRequiredField", "Name is
> required.", new Function("x", "return {}[x];"));
> }
> --%>
> <s:validatorScript functionName="validateForm"/>
> <h:commandButton action="submit"/>
> </h:form>
> </f:view>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
SV: [Shale] commons client side validation not working inside a
dataList
Posted by Hermod Opstvedt <he...@opstvedt.com>.
Hi
Did I hear forceId? - You need to use this attribute to force the name to be
what you want.
Hermod
-----Opprinnelig melding-----
Fra: Paul Devine [mailto:devinesy@gmail.com]
Sendt: 29. mars 2006 22:47
Til: user@struts.apache.org
Emne: [Shale] commons client side validation not working inside a dataList
I tried using the commons validation features of Shale. The application is
using Myfaces 1.1.1. The validation javascript is being written back to the
browser. The server side validation is working fine but a javascript `field
error occurs during the . However there is a problem with the client side
input element Id's that the javascript validation is looking for versus the
client side id's that are generated by the dataList. The page i tried
validation on has a Myfaces dataList inside a form, and for each iteration
through the list there are inputs. Basically a dataList will append the `row
index` to the client side Id to guarantee uniqueness, as in
"myForm:myDataList_0:someRequiredField" for the first row,
"myForm:myDataList_1:someRequiredField" for the second, and so on. But in
the rendering of the javascript by the struts validatorScript tag, the
clientId of the input components lose their row index.
I have created an illustrative example that generates the same problem. The
code is included below and the inline comments hopefully explain what's
happening. To keep things simple there is no backing bean, and I use a
class from shale-core to give me some objects to edit, so all you'd just
need to deploy into a shale-core based "blank" web-app. My application page
is more complex than this but I am running into exact the same problem
withthe validation javascript
Does this look familiar to anyone? Any workarounds, solutions?...
Thanks
-- Paul Devine
<%@ page language="java" import="java.util.*,
org.apache.shale.dialog.impl.DialogImpl"%>
<%@ 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="t"%>
<%@ taglib uri="http://struts.apache.org/shale/core" prefix="s" %>
<%
/* Put a couple of Shale DialogImpl objects into the session (we just need
an object with a getter and a setter
* and this class is readily accessible)
*/
List inputObjects = new ArrayList();
inputObjects.add(new DialogImpl());
inputObjects.add(new DialogImpl());
session.setAttribute("someInputObjects",inputObjects);
%>
<f:view>
<%--
A form with a dataList of inputs. The client side id's of the components
will be
someForm:someDataList_0:someRequiredField and
someForm:someDataList_1:someRequiredField
--%>
<h:form id="someForm" onsubmit="return validateForm(this);">
<t:dataList id="someDataList" value="#{someInputObjects}" var="object"
rowIndexVar="index">
<h:outputLabel value="Name"/>
<h:inputText id="someRequiredField" value="#{object.name}" size="20"
required="true">
<s:commonsValidator type="required" arg="Name" server="true"
client="true"/>
</h:inputText><h:message for="someRequiredField"
errorClass="errorMessage"/>
</t:dataList>
<%--
The dataList is now closed. Before we close out the form, write out the
validator javascript. But
this results in a mismatch on the client side id's in the required function.
Note the uniqueness
indexes _0 and _1 are missing. Because we are outside the
dataList there is no "row index" anymore (and for some reason the
HtmlInputText components `calculate`
their clientId's again when asked for getClientId from Shale's
ValidatorScript findCommonsValidators method
Here's what the validatorScript comes up with:-
function required() {
this[0] = new Array("someForm:someDataList:someRequiredField", "Name is
required.", new Function("x", "return {}[x];"));
}
--%>
<s:validatorScript functionName="validateForm"/>
<h:commandButton action="submit"/>
</h:form>
</f:view>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org