0

I have a column that needs to display date if there is no condition else display a combination of text+date if a criteria is met.

I have to append a text Week Of to a date field if a custom field material_group__c in Object1 has certain values N2, A. I want to achieve this only using VISUALFORCE.

Following is what I tried...

ATTEMPT 1

                   <apex:column title="Estimated Delivery Date at time of Order" rendered="{!OR(p.gew_material_group__c = 'N2', p.material_group__c = 'A')}">
                     <apex:facet name="header">EDD</apex:facet>              
                     <apex:outputText value="Week Of- {0,date,dd/MM/yyyy}" > 
                        <apex:param value="{!p.planned_ship_date__c}"/> 
                     </apex:outputText> 
                    <apex:outputText value="{0,date,dd/MM/yyyy}" rendered="{!OR(NOT(p.material_group__c = 'N2'), NOT(p.material_group__c = 'A'))}"> 
                        <apex:param value="{!p.planned_ship_date__c}"/> 
                    </apex:outputText>
                 </apex:column>  

ERROR 1: Show visualforce codes on column instead of value that is within " " double quotes, without throwing any error

ATTEMPT 2

                 <apex:column title="Estimated Delivery Date at time of Order">
                     <apex:facet name="header">EDD</apex:facet>              
                      <apex:outputText value="{!IF(OR(p.material_group__c = 'N2',p.material_group__c = 'L2'),'week of-{0, date, MM'/'d'/'yyyy}','{0, date, MM'/'d'/'yyyy}')}">
                        <apex:param value="{!p.planned_ship_date__c}" />                            
                    </apex:outputText>  

ERROR 2: Incorrect parameter type for operator '/'. Expected Number, received Text

But it seems, i can't have two apex:outputText on the same column. So how should I go about it? Thanks

9
  • In attempt 2: shouldn't your date format be enclosed within single quotes too ? Commented Oct 13, 2014 at 20:56
  • Did you mean like this '{0, date, MM'/'d'/'yyyy}' ??
    – MnZ
    Commented Oct 13, 2014 at 21:07
  • Only trouble I'm facing is to add a string text as prefix to a date field, If I add 'week of-{0, date, MM'/'d'/'yyyy}' the text part is causing trouble. Is there a better way?
    – MnZ
    Commented Oct 13, 2014 at 21:13
  • Actually no, I'm wrong. It's just that your second error message appears to indicate that the / is misinterpreted by the parser. Your format in Attempt 2 looks ok. Did you by any chance mix up the errors or attempts ? Commented Oct 13, 2014 at 21:13
  • In case it helps, you can often use <apex:outputPanel layout="none">...</apex:outputPanel> to wrap multiple tags in contexts where only one is allowed to keep Visualforce happy with no extra markup emitted in the HTML.
    – Keith C
    Commented Oct 13, 2014 at 21:17

1 Answer 1

2

Your Attempt 2

There is an error in second attempt. You don't want to enclose '/' within quotes. Please try following - it worked for me:

<apex:column title="Estimated Delivery Date at time of Order">
    <apex:facet name="header">EDD</apex:facet>              
        <apex:outputText value="{!IF(
            OR(p.material_group__c = 'N2', p.material_group__c = 'L2'),
            'week of-{0, date, MM/d/yyyy}', '{0, date, MM/d/yyyy}'
        )}">
            <apex:param value="{!p.planned_ship_date__c}" />                            
        </apex:outputText>

Your Attempt 1

I wanted to help here as well but I could't find an error in this approach. I copied your example and tried in one of my tables but it was working fine.

8
  • Hi @neff. Your prev answer worked for me. Double forward slash did the trick. Please post that as answer. FYI <apex:outputText value="{!IF(OR(p.gew_material_group__c = 'N2',p.gew_material_group__c = 'P2'),'Week Of-{0, date, MM//d//yyyy}','{0, date, MM//d//yyyy}')}"> WORKED for me
    – MnZ
    Commented Oct 13, 2014 at 22:07
  • Hi @MnZ, at first I thought about double slashes but it was generating double quotes on my page. Are you sure that single slashes are not enough? They worked for me
    – neff
    Commented Oct 13, 2014 at 22:15
  • Single slashes worked if there was no text attached to it, in this case "Week Of". Could you post what u tried? Double slashes accepted text prefixes as well as displayed proper date format in my case.
    – MnZ
    Commented Oct 14, 2014 at 9:16
  • Single quotes example: <apex:outputText value="{!IF( true, 'week of-{0, date, MM/d/yyyy}', '{0, date, MM/d/yyyy}' )}"> <apex:param value="{!Service__c.My_Date_Field__c}" /> </apex:outputText>. It displays "week of- 10/14/2014". That's strange :-)
    – neff
    Commented Oct 14, 2014 at 9:35
  • 1
    Sorry @neff my mistake ...here's the correct one again ......'Week Of-{0, date, MM/d/yyyy}','{0, date, MM/d/yyyy}') totally worked.! thnx to u
    – MnZ
    Commented Oct 14, 2014 at 10:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .