Output label not conditional

I have a requirement to show page message for a particular selected template. The template selection done here. But render is always returning true in this case. Can someone help me here?

<apex:selectList id="chooseTempalte" label="Choose Template" title="Select your Template"        value="{!selectedTemplateId}" size="1" onChange="rerenderEmailFields(this.value)">
   <apex:selectOptions value="{!TemplateOptions}"/>
</apex:selectList>

<apex:outputLabel style="color:red;"  rendered="{!IF(selectedTemplateId='Update Status - Send to ABSM', false, true)}" >  
  Please note this selected option  will set the status value to Under Review <br/><br/>
</apex:outputLabel>

Please find the apex controller snippet here.

public List<SelectOption> getTemplateOptions() {
        options = new List<SelectOption>();
        for (EmailTemplate t : etMap.values()) {
            options.add(new SelectOption(t.Id,t.Name));
            if((selectedTemplateId == '' || selectedTemplateId == null) && t.Name == 'Update Status - Send to ABSM')
            {
                selectedTemplateId = t.Id;
                ApplyTemplate();
            }
        }

    return options;
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You’re assigning a record ID to selectedTemplateId with this:

selectedTemplateId = t.Id;

and then comparing it with a string in the page, which is why the comparison evaluates as false and then your IF() function returns true.

You haven’t listed the code that populates etMap but as long as you’re initialising it with a query that includes the Name field (or if it’s coming from a trigger), then you should be able to do something like the following. I’m using a new variable (selectedTemplate) as I’m guessing the other is used as a page parameter.

public EmailTemplate selectedTemplate {get; set;}

public List<SelectOption> getTemplateOptions() {
    options = new List<SelectOption>();
    for (EmailTemplate t : etMap.values()) {
        options.add(new SelectOption(t.Id,t.Name));
        if((selectedTemplateId == '' || selectedTemplateId == null) && t.Name == 'Update Status - Send to ABSM')
        {
            selectedTemplateId = t.Id;
            selectedTempalte = t;
            ApplyTemplate();
        }
    }
    return options;
}

Then in the page you can test against the name field as you want:

<apex:outputLabel style="color:red;"  rendered="{!IF(selectedTemplate.Name = 'Update Status - Send to ABSM', false, true)}" >  
  Please note this selected option  will set the status value to Under Review <br/><br/>
</apex:outputLabel>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x