+ Start a Discussion
mustafatopmustafatop 

Using conditional statement in apex page

l get syntax error following line,
<apex:selectlist value="{!IF({!counter}={!1},{!selectedItem},{!selectedItem2})}" size="1">

 

How to use this formula functions in apex tags?

<apex:variable var="counter" value="{!1}"/>          
                <apex:repeat value="{!events}" var="itr"> 
                    <br/><br/>     
                    
                    <table>            
                        <tr>
                            <td><apex:OutputText value="{!counter}"/></td>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!IF({!counter}={!1},{!selectedItem},{!selectedItem2})}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                    <apex:variable var="counter" value="{!counter+1}"/>                     
               </apex:repeat>

 

bob_buzzardbob_buzzard

Once you open the '{!' you are in merge syntax until you close the '}', so you don't need to open/close on each field:

 

<apex:selectlist value="{!IF(counter=1,selectedItem,selectedItem2)}" size="1">

 

I'm not 100% sure that this will work, as I can't recall having a conditional value for a selectlist before.

mustafatopmustafatop

I have tried this. I am getting this error: Unknown property 'IF(counter=1,selectedItem,selectedItem2)'

 

selectedItem and selectedItem2 variable are here:

 String s = '09:00';
     String s2 = '09:00';
     
     public String getSelectedItem(){
          return s;
     }
     public void setSelectedItem(String s){
         this.s = s;
     }
     
     public String getSelectedItem2(){
          return s2;
     }
     public void setSelectedItem2(String s2){
         this.s2 = s2;
     }

     public List<SelectOption> getItems(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options;      
     }

 

mustafatopmustafatop

Actually my problem was below link. I have created this topic for as an alternative solution.

http://boards.developerforce.com/t5/Apex-Code-Development/How-to-use-apex-selectlist-into-apex-repeat/td-p/557521

bob_buzzardbob_buzzard

The error that you saw was the reason that I put I wasn't 100% sure - some attributes require a property rather than allowing merge syntax to determine the value.  I'd expect action methods to behave the same, now that I've seen the results of your attempt.