You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Boda Béla (JIRA)" <ji...@apache.org> on 2007/06/10 21:12:26 UTC

[jira] Created: (STR-3051) FieldChecks.evaluateBean method is absolutaly wrong!!!

FieldChecks.evaluateBean method is absolutaly wrong!!!
------------------------------------------------------

                 Key: STR-3051
                 URL: https://issues.apache.org/struts/browse/STR-3051
             Project: Struts 1
          Issue Type: Bug
          Components: Core
    Affects Versions: 1.3.8
         Environment: Using with AndroMDA 3.2. Windows XP, Java 5.0
            Reporter: Boda Béla
            Priority: Critical


The method below is wrong, because if a bean has a java.lang.Double field the validation is not working. The getValueAsString returns anything if the field is set. But if the user types sharacters in a double field the bean has a NULL value in that field, so this method returns null, that is wrong, because the typed string is not visible any more.

Wrong method:

    private static String evaluateBean(Object bean, Field field) {
        String value;

        if (isString(bean)) {
            value = (String) bean;
        } else {
            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
        }

        return value;
    }

Good method to use:

    private static String evaluateBean(Object bean, Field field, HttpServletRequest request) {
        String value;

        if (isString(bean)) {
            value = (String) bean;
        } else {
            value = request.getParameter(field.getKey());
        }

        return value;
    }

PS: Can't send a patch, sorry!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (STR-3051) FieldChecks.evaluateBean method is absolutly wrong!!!

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/STR-3051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41217 ] 

Niall Pemberton commented on STR-3051:
--------------------------------------

For Struts1 the recommendation is to use "String" properties in your ActionForm rather than typed properties such as "Double". This avoids the type of issue you're facing with validation and also allows invalid values for properties such as numeric types to be re-displayed to the user.

I'm sure supporting typed properties would be a popular addition, but it needs more work than the simple change you're proposing (which on its own is a really bad idea) and I don't believe there is the appetite for such development in Struts1. I believe that Struts2 handles this type of behaviour in a much better way - and if you can consider switching/moving to Struts2 - would probably be a better option for you.

I suggest we close this as WONT FIX.

> FieldChecks.evaluateBean method is absolutly wrong!!!
> -----------------------------------------------------
>
>                 Key: STR-3051
>                 URL: https://issues.apache.org/struts/browse/STR-3051
>             Project: Struts 1
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.3.8
>         Environment: Using with AndroMDA 3.2. Windows XP, Java 5.0
>            Reporter: Boda Béla
>            Priority: Critical
>
> The method below is wrong, because if a bean has a java.lang.Double field the validation is not working. The getValueAsString returns anything if the field is set. But if the user types sharacters in a double field the bean has a NULL value in that field, so this method returns null, that is wrong, because the typed string is not visible any more.
> Wrong method:
>     private static String evaluateBean(Object bean, Field field) {
>         String value;
>         if (isString(bean)) {
>             value = (String) bean;
>         } else {
>             value = ValidatorUtils.getValueAsString(bean, field.getProperty());
>         }
>         return value;
>     }
> Good method to use:
>     private static String evaluateBean(Object bean, Field field, HttpServletRequest request) {
>         String value;
>         if (isString(bean)) {
>             value = (String) bean;
>         } else {
>             value = request.getParameter(field.getKey());
>         }
>         return value;
>     }
> PS: Can't send a patch, sorry!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (STR-3051) FieldChecks.evaluateBean method is absolutly wrong!!!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/STR-3051?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed STR-3051.
------------------------------

    Resolution: Won't Fix

+1

> FieldChecks.evaluateBean method is absolutly wrong!!!
> -----------------------------------------------------
>
>                 Key: STR-3051
>                 URL: https://issues.apache.org/struts/browse/STR-3051
>             Project: Struts 1
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.3.8
>         Environment: Using with AndroMDA 3.2. Windows XP, Java 5.0
>            Reporter: Boda Béla
>            Priority: Critical
>
> The method below is wrong, because if a bean has a java.lang.Double field the validation is not working. The getValueAsString returns anything if the field is set. But if the user types sharacters in a double field the bean has a NULL value in that field, so this method returns null, that is wrong, because the typed string is not visible any more.
> Wrong method:
>     private static String evaluateBean(Object bean, Field field) {
>         String value;
>         if (isString(bean)) {
>             value = (String) bean;
>         } else {
>             value = ValidatorUtils.getValueAsString(bean, field.getProperty());
>         }
>         return value;
>     }
> Good method to use:
>     private static String evaluateBean(Object bean, Field field, HttpServletRequest request) {
>         String value;
>         if (isString(bean)) {
>             value = (String) bean;
>         } else {
>             value = request.getParameter(field.getKey());
>         }
>         return value;
>     }
> PS: Can't send a patch, sorry!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (STR-3051) FieldChecks.evaluateBean method is absolutly wrong!!!

Posted by "Boda Béla (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/STR-3051?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Boda Béla updated STR-3051:
---------------------------

    Summary: FieldChecks.evaluateBean method is absolutly wrong!!!  (was: FieldChecks.evaluateBean method is absolutaly wrong!!!)

> FieldChecks.evaluateBean method is absolutly wrong!!!
> -----------------------------------------------------
>
>                 Key: STR-3051
>                 URL: https://issues.apache.org/struts/browse/STR-3051
>             Project: Struts 1
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.3.8
>         Environment: Using with AndroMDA 3.2. Windows XP, Java 5.0
>            Reporter: Boda Béla
>            Priority: Critical
>
> The method below is wrong, because if a bean has a java.lang.Double field the validation is not working. The getValueAsString returns anything if the field is set. But if the user types sharacters in a double field the bean has a NULL value in that field, so this method returns null, that is wrong, because the typed string is not visible any more.
> Wrong method:
>     private static String evaluateBean(Object bean, Field field) {
>         String value;
>         if (isString(bean)) {
>             value = (String) bean;
>         } else {
>             value = ValidatorUtils.getValueAsString(bean, field.getProperty());
>         }
>         return value;
>     }
> Good method to use:
>     private static String evaluateBean(Object bean, Field field, HttpServletRequest request) {
>         String value;
>         if (isString(bean)) {
>             value = (String) bean;
>         } else {
>             value = request.getParameter(field.getKey());
>         }
>         return value;
>     }
> PS: Can't send a patch, sorry!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.