History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: STR-2859
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Major Major
Assignee: Unassigned
Reporter: Manuel Valladares
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 1

When using <html:html xhtml="true"> the form name is not used but the id, and the client validation using javascript fails

Created: 05/May/06 05:33 PM   Updated: 03/Jul/07 10:31 PM
Component/s: Tag Libraries
Affects Version/s: 1.2.8
Fix Version/s: None

Environment:
Linux Fedora 5
Tomcat 5.5 and JBoss 4.0.3
Struts 1.2.8
Issue Links:
Duplicate
 


 Description  « Hide
When we use client javascript validation we have a problem when we try to set the strict xhtml format in the <html:html> tag.

For example, in the following jsp code:

<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/c" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html:html xhtml="true" locale="true">
<html:errors/>

<html:javascript formName="TmpForm"/>

<head>
</head>
<html:form action="/Tmp.do" method="get" onsubmit="return validateTmpForm (this)">
<html:text property="aparam"/>
<html:submit/>
<html:cancel/>

</html:form>
</html:html>


The generated code for the form is:
<form id="TmpForm" method="get" action="/MRE/Tmp.do;jsessionid=50AB02D65B89E98624364A26680EF831" onsubmit="return validateTmpForm (this)">

As you see, it doesn't have a "name" property but a "id".
And the validation javascript function created is:
   function validate....(form) {
        var isValid = true;
        var focusField = null;
        var i = 0;
        var fields = new Array();

        var formName = form.getAttributeNode("name");

        oRange = eval('new ' + formName.value + '_floatRange()');

        [...........]

        return isValid;
    }

But the form doesn't have a "name" property. And the javascript fails.

If you change the generated javascript code looking for "id" instead of "name" everything should work fine.
For example, you could produce a code like:

   function validate....(form) {
        var isValid = true;
        var focusField = null;
        var i = 0;
        var fields = new Array();

        var formName = form.getAttributeNode("name") ? form.getAttributeNode("name") : form.getAttributeNode("id");
             

        oRange = eval('new ' + formName.value + '_floatRange()');

        [...........]

        return isValid;
    }


Hope this helps.
                       Manuel Valladares

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Henri Yandell - 08/May/06 03:55 PM
Only worry with marking this as a duplicate Don, is that the issue this duplicates says that the issue was fixed in 1.2.8, however the reporter is using 1.2.8.

Don Brown - 08/May/06 05:11 PM
Manuel, are you sure you are using the commons-validator jar that came with Struts 1.2.8? Both upgraded jars have to be in place because, actually, most of the fix was to commons-validator.

Manuel Valladares - 09/May/06 09:06 AM
Hello,
Currently we are using struts 1.2.9 that comes packed with commons-validator version 1.1.4 and it fails.

Following your hint that the problem was in the commons-validator, we upgraded the version of commons-validator from jakarta to version 1.3 and everything works fine.

Maybe you should check the version of commons-validator that comes packed in struts 1.2.9.

Now I am not sure if for the testing I was using 1.2.9 instead of 1.2.8. We were changing versions in the development machines and maybe I was wrong in the bug report and we were using 1.2.9 instead of 1.2.8. Sorry for the confusion.

If you want I can send you our test code.

Niall Pemberton - 09/May/06 09:34 AM
This issue was fixed by a combination of the changes in Struts 1.2.8 and Validator 1.2.0 - however both Struts 1.2.8 and Struts 1.2.9 were shipped with Validator 1.1.4 and so resolving the issue does require upgrading to a later version of Commons Validator as you have done. This was/is indicated on the Struts 1.2.8 upgrade notes on the wiki:
http://wiki.apache.org/struts/StrutsUpgradeNotes127to128

Also the Struts 1.2.9 upgrade notes on the wiki also highlight that it ships with 1.1.4 and suggest upgrading to a later version of Validator for bug fixes:
http://wiki.apache.org/struts/StrutsUpgradeNotes128to129

There are a couple of reasons why Struts 1.2.8/1.2.9 shipped with Validator 1.1.4 rather than the latest Validator version:

1) Both of these Struts releases were maintenance releases primarily to fix security issues so sticking with the more stable/widely used Validator 1.1.4 seemed like a good idea - rather than the (at the time) brand new Validator 1.2.0/1.3.0 versions. In the case of Struts 1.2.8, which could have shipped with Validator 1.2.0, this IMO has proved to be a good decision since there were a number of bugs introduced in 1.2.0 (now fixed in Validator 1.3.0).

2) Struts 1.2.x has not been modified to support all the features in Validator 1.2.0 (i.e. Variables in Resource Bundles - see http://wiki.apache.org/jakarta-commons/ValidatorVersion120) - this doesn't necessarily mean it shouldn't be changed to use the latest Validator version, but it would IMO create confusion when people try to use this feature and find it doesn't work in Struts (prior to Struts 1.3.x).