function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kosmitevkosmitev 

How to control rendered attribute of outputpanel based on variable's length

Hi guys,

The title pretty much explains what I need to do.

To clarify more:

I have a component with code like:

<apex:component access="global">
    <apex:attribute access="global" name="RecipientLabel" description="Recipient label." type="String" required="true"/>

-------SOME MORE STUFF HERE------

  <apex:outputPanel rendered="{!RecipientLabel}.length()>0"><div> <apex:outputLabel >{!RecipientLabel}:</apex:outputLabel> </div> </apex:outputPanel>

-----SOME MORE STUFF HERE -----


</apex:component>

If you look at the expression that I hae for rendered: "{!RecipientLabel}.length()>0"

That does not work it seems to be always false even though when I remove it the component shows and I can see that the output label has text in it.

Please let me know hwo to make that work.

I have tried sever different things like putting a javascript function in rendered different syntaxes but so I am not lucky enough to hit the right combination.

 

Thanks,

Kos

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You should be able to use the LEN function for this.

 

Change:

 

 

"{!RecipientLabel}.length()>0"

 

 

to

 

 

"{!LEN(RecipientLabel)>0}"

 

 

 

 

 

 

All Answers

ipsita.biswas@in.v2solutions.comipsita.biswas@in.v2solutions.com

Hi,

You can try using a controller, through which you can set a boolean value for the output Panel based on the Reciepient Length.

kosmitevkosmitev

Hi,

thanks you for your promt reply.

I was curious if there is a more elegant solution.

I have about 50 variables passed in to my component.

I will have to add another say 25 for a total of 75 in order to have flag but it will certainly work.

I was hoping that this can be done somehow having the label already.

 

If there is no better solution in a couple of day I will mark this as an answer as this will definately work.

 

Thanks again.

Kos

bob_buzzardbob_buzzard

You should be able to use the LEN function for this.

 

Change:

 

 

"{!RecipientLabel}.length()>0"

 

 

to

 

 

"{!LEN(RecipientLabel)>0}"

 

 

 

 

 

 

This was selected as the best answer
kosmitevkosmitev

Exactly.

Thank you very much !

 

Kos

aballardaballard

Right.  You have to use an expression that is evaluated by the server, in order for the server to know whether to render the component or not. 

 

I'd say there is a bug here in that the page compiler should have complained that the value of the rendered attribute is not a simple boolean value (after evaluating the embedded expression).

Pradeep_NavatarPradeep_Navatar

Hope this works for you :

 

<apex:outputPanel rendered="{!IF(LEN(RecipientLabel)> 0 ,true,false)}">