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
sundar84sundar84 

How to show the two different object picklist values in Pageblock table

Hi Friends

 

I  have developed one visual force page. One page block have Two pageBlock Sections, That Pageblock sections have two picklist.  Two different object  values has reterived  in the picklist values.  i would like to show these values in one Pageblocktable.  its possible. Please let me know  yours suggestions..

 

Visual Force page

 <apex:pageBlock title="Inventory Line Item" >          

 

         <apex:pageBlockSection title="" >
             <apex:pageBlockSectionItem >                         
                 <apex:outputLabel value="Inward ILI" for="item1" style="font-weight:bold" />                                       
                     <apex:selectList value="{!InwardILI}"  multiselect="false" size="1" onselect="show" id="sellist1" >
                         <apex:selectOptions value="{!ILIitems}"/> 
                         <apex:actionSupport event="onchange" reRender="Pallet" status="..."/>                        
                     </apex:selectList>                     
              </apex:pageBlockSectionItem>      
              <apex:pageBlockSectionItem >      
                   <apex:outputLabel value="Pallet Id" for="item1" style="font-weight:bold" />                                       
                       <apex:selectList value="{!Invplist}"  multiselect="false" size="1" onselect="show" id="Pallet" >
                           <apex:selectOptions value="{!Invpitems}"/> 
                       </apex:selectList>
              </apex:pageBlockSectionItem>     
              <apex:pageBlockSectionItem >    
                   <apex:commandButton style="" value="Add Line Items" action="{!AddInventoryPallet}" />                 
              </apex:pageBlockSectionItem>                                      
            </apex:pageBlockSection>
        </apex:pageBlock> 
Controller:
*/ Two picklist values */
public List<SelectOption> getILIitems() {       
       List<selectoption>selectILI = new List<Selectoption>();     
       List<ILI__c>InwardILIlist = new List<ILI__c>();      
       InwardILIlist = [Select Id,Name,Product__c From ILI__c where Direction__c='Inward'and Product__c =:ProductName];
       System.debug('::InwardILIlist::'+InwardILIlist);
       selectILI .add(new SelectOption('-Select-','-Select-'));
       for(ILI__c ili: InwardILIlist ){
           selectILI.add(new SelectOption(ili.Id,ili.Name));              
        }             
       System.debug('::SelectILI::'+selectILI);
       return selectILI ;       
    }   
 public List<SelectOption> getInvpitems() {    
        List<selectoption>selectInvpallet = new List<Selectoption>(); 
        List<Inventory_Pallet__c>inventorypalletlist = new List<Inventory_Pallet__c>();
        
        inventorypalletlist = [ 
            Select Id,Name From Inventory_Pallet__c 
            where Inventory_Line_Item__c =:InwardILI and Status__c='Inward'];
        System.debug('::inventorypalletlist'+inventorypalletlist);
        selectInvpallet.add(new SelectOption('-Select-','-Select-'));
        for(Inventory_Pallet__c invp: inventorypalletlist ){
          selectInvpallet.add(new SelectOption(invp.id,invp.Name));                    
        } 
        return selectInvpallet;
    } 
Thanks
Sundar

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You should be able to compress these into a single pageblocksectionitem by surrounding them both with an outputPanel.

 

Something like:

 

 

<apex:pageBlockSectionItem >                         
   <apex:outputPanel id="picklists">
        <apex:outputLabel value="Inward ILI" for="item1" style="font-weight:bold" />                                       
        <apex:selectList value="{!InwardILI}"  multiselect="false" size="1" onselect="show" id="sellist1" >
          <apex:selectOptions value="{!ILIitems}"/> 
              <apex:actionSupport event="onchange" reRender="Pallet" status="..."/>                        
        </apex:selectList>                     
        <apex:outputLabel value="Pallet Id" for="item1" style="font-weight:bold" />                                       
        <apex:selectList value="{!Invplist}"  multiselect="false" size="1" onselect="show" id="Pallet" >
           <apex:selectOptions value="{!Invpitems}"/> 
        </apex:selectList>
   </apex:outputPanel>
</apex:pageBlockSectionItem>    

 

All Answers

bob_buzzardbob_buzzard

Can you clarify your requirements a little?  The pageblocktable component iterates a list of objects and typically outputs the fields/properties on those objects.  Are you looking to iterate the select options and produce some kind of side by side comparison?

sundar84sundar84

Hi bob

 

My requirements is  if i select  one ILI from the First Picklist ,Respective selected ILI  pallet  will be displayed in the second picklist.  the Two picklist  have in two section items. its working fine.

 

The  First picklist value is came from ILI__c, Second  picklist values came from Inventory_Pallet__c.   refer the Apex class

 

But  my requirement is how to  display the  two picklist values in  one pageblock.

 

Thanks

Sundar

 

bob_buzzardbob_buzzard

You should be able to compress these into a single pageblocksectionitem by surrounding them both with an outputPanel.

 

Something like:

 

 

<apex:pageBlockSectionItem >                         
   <apex:outputPanel id="picklists">
        <apex:outputLabel value="Inward ILI" for="item1" style="font-weight:bold" />                                       
        <apex:selectList value="{!InwardILI}"  multiselect="false" size="1" onselect="show" id="sellist1" >
          <apex:selectOptions value="{!ILIitems}"/> 
              <apex:actionSupport event="onchange" reRender="Pallet" status="..."/>                        
        </apex:selectList>                     
        <apex:outputLabel value="Pallet Id" for="item1" style="font-weight:bold" />                                       
        <apex:selectList value="{!Invplist}"  multiselect="false" size="1" onselect="show" id="Pallet" >
           <apex:selectOptions value="{!Invpitems}"/> 
        </apex:selectList>
   </apex:outputPanel>
</apex:pageBlockSectionItem>    

 

This was selected as the best answer
sundar84sundar84

Hi Bob

 

Thanks for your  suggestion.  Later i found  this solution.,

 

 

Thanks

Sundar

 

 

 

 

 

sundar84sundar84

 

Hi Bob
Scenario: when i select the product and click  the add button two picklist will created for the  selected product.
list of ILI are displayed in the first picklist. its working
My problem
1. If i select the  value from the ILI picklist  the related pallet name will show in the Pallet  picklist.
but it couldn't shown.  
2 .If i add the second product  first  product pallets will overridden to the second product pallet picklist
Please give your suggestion for resolve this issue..
 <apex:pageBlock title ="Products">
 <apex:pageBlockSectionItem >
                <apex:outputLabel value="Select Product"></apex:outputLabel>
                    <apex:outputPanel id="productlist">                    
                        <apex:selectList value="{!selectedProduct}" id="sellist2" size="1">
                            <apex:selectOptions value="{!pitems}"></apex:selectOptions>
                        </apex:selectList>
                    </apex:outputPanel>                    
           </apex:pageBlockSectionItem>      
        </apex:pageBlockSection>          
         <apex:pageBlockButtons location="bottom"> 
            <apex:commandButton value="Add" action="{!addLineItems}"/>
       </apex:pageBlockButtons>         
    </apex:pageBlock>
<apex:pageBlock title="Inventory Line Item"  rendered="{!InventoryPalletclasslist.size >0}">    
         <apex:pageBlockTable value="{!InventoryPalletclasslist}" var="il" id="iList">                                                                     
             <apex:column colspan="2"  headerValue="Product">
                 <apex:outputText value="{!il.productNam}"/>
             </apex:column> 
             <apex:column headerValue="ILI">
                 <apex:selectList value="{!InwardILI}"  multiselect="false" size="1" onselect="show" id="sellist1" >
                     <apex:selectOptions value="{!il.ILIselectoption }"/> 
                         <apex:actionSupport event="onchange" reRender="Pallet" status="..." immediate="True"/>                        
                     </apex:selectList>                             
              </apex:column>                                                                                          
              <apex:column headerValue="Inventory Pallet">
                  <apex:selectList value="{!Invplist}"  multiselect="false" size="1" onselect="show" id="Pallet" >
                      <apex:selectOptions value="{!Invpitems}"/> 
                  </apex:selectList>
              </apex:column>           
         </apex:pageBlockTable>                
         <apex:pageBlockButtons location="bottom">
             <apex:commandButton style="" value="Add Line Items" action="{!AddInventoryPallet}" />                 
         </apex:pageBlockButtons>       
     </apex:pageBlock>
Controller:
*/ Add the Product and ILI */
public pageReference addLineItems(){        
        List<selectoption>newselectILI = new List<Selectoption>(); 
        ILIPalletinnerclass  ilip = new ILIPalletinnerclass ();        
        List<ILI__c>NewInwardILIlist = new List<ILI__c>();   
        
        NewInwardILIlist = [Select Id,Name,Product__r.Name From ILI__c where Direction__c='Inward'and Product__c =:ProductName];
        
        if ( NewInwardILIlist.size() > 0) {
           
            if( ! productNameSet.contains(NewInwardILIlist.get(0).Product__r.Name) ) {
                newselectILI .add(new SelectOption('-Select-','-Select-'));
                for(ILI__c newili : NewInwardILIlist) {
                    newselectILI.add(new SelectOption(newili.id,newili.Name));
                }
                productNameSet.add(NewInwardILIlist.get(0).Product__r.Name);
                ilip.productNam = NewInwardILIlist.get(0).Product__r.Name;
                ilip.ILIselectoption = newselectILI ;
               // ilip.Palletselectoption = getPalletselectoption();  
                InventoryPalletli.add(ilip );
            } else {
             
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Product already present in the Inventory Line Items'));
                 return null;
            }
        }
/* get the Pallet  information */
 public List<SelectOption> getInvpitems() {    
        List<selectoption>selectInvpallet = new List<Selectoption>(); 
        List<Inventory_Pallet__c>inventorypalletlist = new List<Inventory_Pallet__c>();
        
        inventorypalletlist = [ 
            Select Id,Name From Inventory_Pallet__c 
            where Inventory_Line_Item__c =:InwardILI and Status__c='Inward'];
        System.debug('::inventorypalletlist'+inventorypalletlist);
        selectInvpallet.add(new SelectOption('-Select-','-Select-'));
        for(Inventory_Pallet__c invp: inventorypalletlist ){
          selectInvpallet.add(new SelectOption(invp.id,invp.Name));                    
        } 
        return selectInvpallet;
    } 
Thanks
Sundar

 

bob_buzzardbob_buzzard
Your action support has h immediate attribute set to true. This means that your selection will be discarded. Remove this attribute and the chosen option will be sent to the controller.
sundar84sundar84

Hi bob

 

Thanks for your support. I have been removed that property..The picklist values will shown properly. but  when i add the second product   the first product pallet pick list values has overridden with second product pallet pick list.  this is my problem

 

Thanks

sundar

bob_buzzardbob_buzzard
Ah, okay, I think I understand what is happening. You are using a single variable to hold the pallet pick list values. This means that wherever you select your product, all pallet values will be changed to those for the product. You'll need to retain your pallet pick lost options in the collection that backs the data table. The same applies tom the chosen pallet value.
sundar84sundar84

Bob

 

Yes you are right pallet pick list values are contained in single variable. but the pallet information should be displayed based on the Selected ILI picklist values.  i have no issues when i add the single product.

 

After added the sencond product and select the ILI and Pallet list its working. if i click the AddlineItems button the second Product pallets has over ridden with first product pallet pick list.. Still i am lacking in this problem..

 

click the Addlineitems button this InvPalletMainList Method will called..

 

 

 public List<Inventory_Pallet__c> invPalletMList {public get;public set;}   

   public void InvPalletMainList() {   

 

      for(ILIPalletinnerclass il : InventoryPalletli ) {

        if ( il.isSelected == TRUE ) {

            PalletIds.add(il.Palletselectoption );

        }

       } 

       if( PalletIds.size() > 0 ) {        

           for(Inventory_Pallet__c i:[SELECT Id,Name,Product__c,Inventory_Line_Item__r.name,Gross_Weight__c,Tare_Weight__c,Net_Weight__c

            FROM Inventory_Pallet__c 

            WHERE id=: PalletIds and Status__c='Inward']) {

 

                if ( palletIdSet.contains(i.Id) == false ) {

                    palletIdSet.add(i.Id);

                    invPalletMList.add(i);

                } 

            }

        }          

       // return invPalletMList;       

   }

 

public pageReference AddInventoryPallet() { 
       
       System.debug(':::InventoryPalletliSave:::'+InventoryPalletli);
       InvPalletMainList();
       //getInvpitems(); 
       
       return null; 
           
    } 

 

 

Thanks

Sundar

bob_buzzardbob_buzzard

This is because you have a single variable backing the selected product - inwardLI.  Whenever you choose the selectlist value for any product, the selected item will be stored in this variable.  This means that all product selectlists will choose the same product (as they all use the same variable).  As you have a single method to generate the pallet selectlist based on the inwardLI variable, every instance of the pallet selectlist then has the same options.

 

Each selectlist value needs to be a different variable, and you'll need to store the selectlist options in the class that you use to back the pageblocktable.

sundar84sundar84

Yes bob

 

I was tried to implement the dependent picklists in the same pageblock. but i can't implement due to the single variable problem. as per your suggestion i was used my old design.  its working fine. 

 

Thanks for your support

 

Thanks

sundar