+ Start a Discussion
Gino BassoGino Basso 

Error: Literal value is required for attribute

I have a component that accepts a Boolean attribute. Certain combinations of inline functions generate the error message shown in the subject line. See code below for details:

 

<!-- this produces the error --> <c:myComponent myBooleanValue="{!LEN(myObj__c.myField__c) == 0}" .../> <!-- this produces the error --> <c:myComponent myBooleanValue="{!LEN(myObj__c.myField__c) = 0}" .../> <!-- this works! --> <c:myComponent myBooleanValue="{!NOT(LEN(myObj__c.myField__c) > 0)}" .../>

 

Obviously I have a workaround (the last example) but I'm curious to know why the other two do not work.

Ron WildRon Wild

I ran into a similar situation and found that removing default='false' from the apex:attribute tag on the component fixed the problem.

 

NOTE: In my case, the error appeared no matter what formula was used.

 

 

d3developerd3developer

I think that means that default values for Booleans in components are broken. I have the same problem.

gogz_sfdcgogz_sfdc

I've just run into the same issue. 

 

I'm wondering if this is because the Default value is a literal thus the value being passed to the attribute must also be a literal.... 

ApexGuruApexGuru

Yes, it is because of the default value!!

I had the same issue when passing an Integer parameter to a component.

 

Thank you for this finding!!

Ralph CallawayRalph Callaway

Just ran into this problem, removing the default attribute took care of it.  Was able to make my own default value using BLANKVALUE.

 

<apex:component >

	<apex:attribute name="defaultNeeded"
		type="String"
		description="Needs a default value"
		required="false"/>
	
	<apex:variable value="{!BLANKVALUE(defaultNeeded, 'Default Value')}" var="innerValue"/>

</apex:component>

 

Ami AssayagAmi Assayag

Another way to fix this is to create a property in the class:

 

Control:

<apex:attribute name="enabled" type="boolean" required="false" assignTo="{!controlEnabled}" />

Class:

public boolean controlEnabled { get { if(controlEnabled == null) controlEnabled = true; return controlEnabled; } set; }

 

 

 

 

CloudMikeCloudMike

This is really sounds like a bug in the component attribute behavior.  I've sucessfully used the combination of required=false with a default value without hitting the "Literal" error.  It doesn't seem to be consistent for a specific datatype either. 

 

This works fine:

<apex:attribute name="searchContacts" type="boolean" required="false" assignTo="{!includeContact}"
description="Search for matches in the Contact object?" 
default="true"/>

 

But this does not:

<apex:attribute name="firstName" type="string" required="false" 
		description="The default value for First Name" 
		default="John"/>

 I don't suppose anyone has any more insight into this issue?

Nickname7Nickname7

Did anyone create this as a bug or report to Salesforce Support? 

cwall_sfdccwall_sfdc

I logged a bug for the Visualforce team.  Fix is TBD.  If an urgent fix is needed, please open a support case and reference this community thread.  Thanks for raising.

WizradWizrad

I am also encountering this bug.

 

Here is some example code:

 

<apex:attribute name="okButtonLabel" description="Label for 'ok' button"
                type="String" required="false" default="Ok" />

...

<c:EQT_Popup title="{!$Label.EQT_Selection_Title}"
              body="{!$Label.EQT_Selection_Body}"
           popupId="bs"
   hasCancelButton="true"
             width="425"
            height="130"
     okButtonLabel="{!$Label.EQT_Broker_Choose}" />

 

Error: 

Literal value is required for attribute okButtonLabel in <c:EQT_Popup> in EQT_Portal at line 104 column 56