0

I want to display blank fields if there are no records returned.

Now it is returning null like below -

enter image description here

Apex Class -

   public with sharing class wrapper_test_controller {
        public list<wrapperclass> wrapperelement_for_account{get;set;}
        public list<wrapperclass> wrapperelement_for_contact{get;set;}
        public string selectedproductfamily {get;set;}
        public list<product2> queryResult{get;set;}
        public list<Work_Order_Item__c> queryResult1{get;set;}
        public List<wrapperclass> lstobjfields
                {
                  get;
                  set;
                } 


            public PageReference query() {
            system.debug('@@@'+selectedproductfamily);
                 String qryString = 'SELECT Id,name,family,Measurement_Type__c,Cleaning_Unit_Price__c,Treatment_Unit_Price__c,(select Service__c,Quantity__c,Length__c,Width__c from work_order_items__R) FROM product2 WHERE ' +

                    '(Family like \'%' + selectedproductfamily + '%\')';

                queryResult = Database.query(qryString);


                return null;

            }

        public wrapper_test_controller (ApexPages.StandardController controller) {


         }

        public class wrapperclass{
        public String name { get; set; }  
        public Integer data { get; set; }  
        public Product2  account {get;set;}
        public Work_Order_Item__c service {get;set;}

        public wrapperclass(String Name,Integer data) {
        this.name = Name; 
          this.data = data;
         } 
        public wrapperclass (Work_Order_Item__c record){
          this.service = record;

          }

          public wrapperclass (Product2 record1){
          this.account= record1;

         }  

         public wrapperclass (Work_Order_Item__c a, Product2 mh)
                {
                    service = a;
                    account = mh;
                }
        }
        }

VF Page -

<apex:page standardController="Work_Order__c" extensions="wrapper_test_controller">

    <apex:form >

        <apex:pageblock id="pb">       

        </apex:pageblockSection>
                 <apex:pageblocksection title="Products" >

               <apex:outputPanel title="Family">
               <apex:outputLabel value="Family:"> &nbsp;&nbsp;
               <apex:actionRegion >              
                <apex:selectList value="{!selectedproductfamily}" size="1" label="Family"  rendered="true" >
                    <apex:actionSupport action="{!query}" reRender="pb1" id="fam" event="onchange"/> 

                    <apex:selectOptions value="{!productfamily}" />

                </apex:selectList>
                   </apex:actionRegion> 
                   </apex:outputLabel>
                   </apex:outputPanel>  
            </apex:pageblocksection>
         <apex:pageblocktable value="{!queryResult}" var="acc" id="pb1">
          <apex:column >
          <apex:facet name="header">Name</apex:facet>
          <apex:outputfield value="{!acc.Name}" />
          </apex:column>
          <apex:column headervalue="Family">
          <apex:outputfield value="{!acc.Family}" />
          </apex:column>
          <apex:column headervalue="Measurement Type">
          <apex:outputfield value="{!acc.Measurement_Type__c}" />
           </apex:column>
          <apex:column headervalue="Treatment Price">
           <apex:outputfield value="{!acc.Treatment_Unit_Price__c}" />
          </apex:column>
          <apex:column headervalue="Cleaning Unit Price">
           <apex:outputfield value="{!acc.Cleaning_Unit_Price__c}" />
           </apex:column>

          <apex:column headerValue="Service">
          <apex:repeatvalue="{!acc.work_order_items__R}" var="b">
          <apex:inputfield value="{!b.Service__c}"/>
          </apex:repeat>
          </apex:column>


          <apex:column headerValue="Quantity">
          <apex:repeat value="{!acc.work_order_items__R}" var="b">
          <apex:inputfield value="{!b.Quantity__c}"/>
          </apex:repeat>
          </apex:column>

           <apex:column headerValue="Length">
           <apex:repeat value="{!acc.work_order_items__R}" var="b">
          <apex:inputfield value="{!b.Length__c}"/>
          </apex:repeat>
          </apex:column>

           <apex:column headerValue="Width">
           <apex:repeat value="{!acc.work_order_items__R}" var="b">
          <apex:inputfield value="{!b.Width__c}"/>
          </apex:repeat>
          </apex:column>  

          </apex:pageblocktable>

        </apex:pageblock> 
    </apex:form>
</apex:page>

[![enter image description here][2]][2]

5
  • on pageload in constructor add a blank record in queryResult list..
    – Ratan Paul
    May 4 '16 at 10:11
  • hi ratan .. i want the blank field should come if there are no values.The above pic is an pageblocktable which is controller by a filter which is there in apex class..If it returns no value for service, length, width field it should display the picklist with none and a two blank textbox for length and width
    – hellraizer
    May 4 '16 at 10:18
  • Sid then I suggest use apex:outputField and inputField for all the columns.. SO basically if field is null then display inputField or if field is not null then display outputField using rerender attribute..
    – Ratan Paul
    May 4 '16 at 10:22
  • can u help me out in this .. How to use apex:outputField and inputField on condition...
    – hellraizer
    May 4 '16 at 10:23
1

Use inputtext instead of inputfiled!

Check if its a null then use inputtext.

Ex:

Instead of <apex:inputfield value="{!b.Width__c}"/>

use <apex:inputtext value="{!b.Width__c}"/>

1
  • Service column is a picklist. If i use input:text it wont show the picklist...
    – hellraizer
    May 4 '16 at 10:15
0

you can do either way but I prefer {!variable != null}.

One thing that might often be a better idea though is to do the checks in the controller so that less of the logic is in the VF page.

EDIT: SObject booleans will always be true/false. It won't be null.

1
  • That is not displaying me any blank fields. From the above pic u can see as records displayed in 2nd row , i want same fields should be displyed in 1st row but it should be blank as it has no values..
    – hellraizer
    May 4 '16 at 9:55
0

I think that you have a problem in the repeat

<apex:repeatvalue="{!acc.work_order_items__R}" var="b">
          <apex:inputfield value="{!b.Service__c}"/>
</apex:repeat>

How the list of work_order_items__R is empty you dont print the input field.

you need change the controller to add a new work_order_item__c if the list is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.