[JIRA] Created: (STS-460) Empty form text fields give null String values

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[JIRA] Created: (STS-460) Empty form text fields give null String values

JIRA jira@mc4j.org
Empty form text fields give null String values
----------------------------------------------

                 Key: STS-460
                 URL: http://mc4j.org/jira/browse/STS-460
             Project: Stripes
          Issue Type: Improvement
          Components: ActionBean Dispatching
    Affects Versions: Release 1.4.3
         Environment: Windows/Linux, Tomcat 5.5.25
            Reporter: Phil Sladen
         Assigned To: Tim Fennell


I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.

Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:

public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
        protected void bindNullValue(ActionBean bean, String property, Class type)
                        throws ExpressionException {
                if (type == String.class) {
                        BeanUtil.setPropertyValue(property, bean, new String());
                }
                else {
                        super.bindNullValue(bean, property, type);
                }
        }
}

All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Resolved: (STS-460) Empty form text fields give null String values

JIRA jira@mc4j.org
     [ http://mc4j.org/jira/browse/STS-460?page=all ]

Tim Fennell resolved STS-460.
-----------------------------

    Resolution: Not a Bug

This is absolutely not a bug.  Where possible Stripes will always 'set to null' values for which there is no value in the request.  Strings are not treated specially, nor in my opinion should they be.

> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://mc4j.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>         Assigned To: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (STS-460) Empty form text fields give null String values

JIRA jira@mc4j.org
In reply to this post by JIRA jira@mc4j.org
    [ http://mc4j.org/jira/browse/STS-460?page=comments#action_11035 ]
           
Phil Sladen commented on STS-460:
---------------------------------

Hi, I'm new to JIRA and when I submitted this issue I didn't mean it to be described as a 'bug', and certainly not 'major', sorry.

I think if Sun applied the same logic to the Java language then we would have ended up with expressions such as 'string1.concat(string2.concat(string3))' etc. instead of 'string1 + string2 + string3' ;)

All the web projects I have worked so far have never (except for the odd special cases) defined a DB column for a form text field as nullable. The simplest convention to use is that empty text fields result in empty String types (and not null ones). Some reasons are:

 - most importantly, you don't have to check for null Strings everywhere and NPEs with String types becomes virtually non-existent.
 - some, if not all, JDBC drivers require that a null String be set on a row with setNull(), so it has to be explicitely checked for. Ok, this is irrelevant f you are using a persistence API :)

I am a big fan of consistency, but IMHO sometimes not at the expense of simplicity. How about a quick straw poll about this, or even including such a property binder for those like myself? Thanks again.

> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://mc4j.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>         Assigned To: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (STS-460) Empty form text fields give null String values

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@mc4j.org

    [ http://www.stripesframework.org/jira/browse/STS-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12295#comment-12295 ]

Tim Burt commented on STS-460:
------------------------------

I think the fundamental point was missed here.  Even if there is a value (i.e. the empty string) in the request, Stripes ignores that value (when it is an empty string) and converts it to null.  I think this is occurring in the DefaultActionBeanPropertyBinder convert method:

            if("".equals(value))
                continue;

Because the value is skipped, the action cannot tell whether the form field was set to the empty string vs. omitted from the request.  This is causing us a problem because we need to persist an empty string, not null, under these circumstances.

> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://www.stripesframework.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>            Assignee: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (STS-460) Empty form text fields give null String values

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@mc4j.org

    [ http://www.stripesframework.org/jira/browse/STS-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12299#comment-12299 ]

Phil Sladen commented on STS-460:
---------------------------------

Hi Tim,
The fundamental point wasn't missed, although maybe the issue could have been described more fully. The custom property binder specified earlier will give the results you desire. Configure where Stripes looks for extensions with:
                <init-param>
                        <param-name>Extension.Packages</param-name>
                        <param-value>{your package}.MyPropertyBinder</param-value>
                </init-param>
Put the property binder class in package {your package} and you're good to go.
If the property is null before property binding takes place and the request doesn't have the property, then the property will still be null after property binding. However, if the request has an empty string for the property then it will be empty (not null) after property binding.


> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://www.stripesframework.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>            Assignee: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (STS-460) Empty form text fields give null String values

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@mc4j.org

    [ http://www.stripesframework.org/jira/browse/STS-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770#comment-12770 ]

Mike Baliel commented on STS-460:
---------------------------------

Stripes is great, but i'm having the exact same issue as described by Tim Burt.  There is certainly a work around for this so it is not a major issue, but IMHO, empty Strings should be treated as "Empty Strings".

> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://www.stripesframework.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>            Assignee: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (STS-460) Empty form text fields give null String values

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@mc4j.org

    [ http://www.stripesframework.org/jira/browse/STS-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12851#comment-12851 ]

Tim Burt commented on STS-460:
------------------------------

I just wanted to note another aspect of this that is biting me now, and I haven't figured out a workaround yet.  If the string property is associated with a map (i.e. form.map.test) and is the only form value being sent (in our environment, we only send changed form values), then the map is never instantiated so I cannot just call BeanUtils/PropertyUtils to set "form.map.test".  

Personally, I (still) believe that this behavior should be optional, or at least easy to override.  As it is, I lose the fact that the user changed a form field value from some non-empty string to the empty string -- I don't care whether the value is represented as the empty string or null, but I do need to know that they modified the value.  As it stands now, the action class has no indication that the form field was changed.

> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://www.stripesframework.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>            Assignee: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (STS-460) Empty form text fields give null String values

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@mc4j.org

    [ http://www.stripesframework.org/jira/browse/STS-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852#comment-12852 ]

Tim Burt commented on STS-460:
------------------------------

If I'd thought for a minute, the workaround specified in the description is fine -- I missed that it was referencing the stripes BeanUtil class, not the apache commons BeanUtils class.

    @Override
    protected void bindNullValue(ActionBean bean, String property, Class<?> type) throws ExpressionException {
        if (String.class.equals(type))
            BeanUtil.setPropertyValue(property, bean, ""); // use null if you prefer
        else
            super.bindNullValue(bean, property, type);
    }

> Empty form text fields give null String values
> ----------------------------------------------
>
>                 Key: STS-460
>                 URL: http://www.stripesframework.org/jira/browse/STS-460
>             Project: Stripes
>          Issue Type: Improvement
>          Components: ActionBean Dispatching
>    Affects Versions: Release 1.4.3
>         Environment: Windows/Linux, Tomcat 5.5.25
>            Reporter: Phil Sladen
>            Assignee: Tim Fennell
>
> I can understand that empty form fields give rise to empty objects when there is a converter involved and invalid input, but it seems a bit OTT to also treat Strings the same way. Although String is not a native type, it is treated as such in some respects in the language, and I think Stripes should do the same by default. Otherwise, code is going to be littered with checks for null or be forced to use something like StringUtils. I would however expect the String to be left unaltered, and possibly null, if the corresponding parameter is not provided in the request. I could then choose whether such extra checks are warranted for Strings as well as other objects.
> Instead, I found the most convenient way around the issue was to provide my own PropertyBinder:
> public class MyPropertyBinder extends DefaultActionBeanPropertyBinder {
>         protected void bindNullValue(ActionBean bean, String property, Class type)
>                         throws ExpressionException {
>                 if (type == String.class) {
>                         BeanUtil.setPropertyValue(property, bean, new String());
>                 }
>                 else {
>                         super.bindNullValue(bean, property, type);
>                 }
>         }
> }
> All credit due to Stripes extensibility, but I don't think I should have to do this.

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development