Announcement Announcement Module
No announcement yet.
form:select disabled attribute Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • form:select disabled attribute

    I've been playing around with the spring form taglib lately and came across a fairly disturbing phenomenon.

    <form:select path="whatever" disabled="${true}">
    Will render a select element that is NOT disabled

    <form:select path="whatever" disabled="${'true'}">
    Will render a select element that IS disabled.

    This indicates to me that the tag expects a string in that attribute and is refusing to coerce any boolean values (possibly checking the type first).

    The impact is that I'm unable to do something like <form:select path="whatever" disabled="${someOtherfield.selectedId != -1}" /> which is something that happens fairly often in our system.

    Am I simply missing some part of the form taglibs functionality? Is this a legitimate design decision? A defect?

  • #2
    Ok, I'm pretty sure this one is a defect...

    AbstractHtmlInputElementTag.isDisabled has the single line:
    return "true".equals(evaluate("disabled", getDisabled()));
    evaluate returns an object, in this case Boolean.TRUE

    String.equals will compare types, and return false, the Boolean isn't automagically converted to a string because String.equals takes an Object parameter.

    A suggested fix would be:
    return "true".equals(evaluate("disabled", getDisabled()).toString());
    however that doesn't handle cases where evaluate returns null, so there is probably a better solution...

    So where do I go from here? I guess I need to find Spring's bug tracking mechanism, see if this is already raised, and if it's not then raise it with a suggested fix?

    This'll be a new process for me so any advice/pointers/links would be appreciated and hopefully stop me from raising items in the wrong system etc and wasting peoples time.


    • #3