Consider this simple component:

<apex:component access="public" layout="none">
    <apex:attribute name="myString" type="String" />

    {!ISNULL(myString)} {!ISBLANK(myString)} {!myString == ''}

Just using the component yields the following values:

<c:MyComponent />

true true true

And it gets even weirder if you use it without an actual value:

<c:MyComponent myString="" />

false false true

Why? Why on earth is a "empty" attribute not blank or null but an omitted attribute is - plus both equal an empty string! Afaicr ISNULL is just an alias for ISBLANK - is this correct? But aside from that - why on earth does a blank string not equal an empty string? Why does it differ?

I hope someone can explain this weird behavior.

Also: Can I differentiate between an empty attribute and an omitted attribute?

  • It doesn't really have anything to do with component or attribute. Your real question is why is an empty string not blank?
    – Adrian Larson
    Sep 28 '16 at 21:30
  • That is not my question because String.isBlank('') is always true. Plus: In my example it seems to be an empty string in both cases - but it is only blank in one case.
    – Semmel
    Sep 29 '16 at 0:48
  • But this isn't Apex, it's Visualforce.
    – Adrian Larson
    Sep 29 '16 at 0:57
  • True. Forget about the Apex-part. In this Visualforce-example I still have an empty string in both cases but only in one case it's also blank.
    – Semmel
    Sep 29 '16 at 1:15
  • I'm not sure I understand what markup you're using in the first and second example. You've only shown one version.
    – Adrian Larson
    Sep 29 '16 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.