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
Alex SashaAlex Sasha 

<apex: param> doesn't work

I' m passing parametrs ro controller from 2 palaces 
first look like:

<apex:dataTable id="tableCategories"  value="{!products}" var="prod" styleClass="table table-striped">      
.......
   <apex:column >
                        <apex:form >

                        <apex:commandButton action="{!makevisibleProduct}" value="View details" 
                         styleClass="btn-success">                
                                     <apex:param name="product" value="{!prod.name}"/>
                         </apex:commandButton>

                        </apex:form>

      </apex:column>
 


                     
controller:

public  with sharing class HomeController {
    private String  ProdName;
  public PageReference makevisibleProduct(){
          productVisibility=true;
            ProdName = ApexPages.currentPage().getParameters().get('product');
          return null;
    }
 public Boolean getisVisibleProduct(){
    
        return productVisibility;
    }
 


Then I want to render particualr product detail with name= Prodname;

Public Product__c getProduct(){
       
        List<Product__c> products =[Select name, description__c, quantity__c,price__c from Product__c
                                   WHERE name =: ProdName
                                   ];
        return products[0];
    }

Table that should displays products:

<apex:pageBlock id ="tableProduct" rendered="{!isVisibleProduct}" mode="maindetail">

                <vs:panel title="Demo Panel Primary" type="primary">
                    <table class="table table-condensed" >
                   
                    <tr>
                      <td class="active">{!product.name} </td>
                    </tr>
....

Whe clicking the button output is:

Visualforce Error
Help for this Page
System.ListException: List index out of bounds: 0 
Class.HomeController.getProduct: line 57, column 1

this line: 

return products[0];

But strangely thing that a has nearly the same button in another place of code which works fine:
 

      <apex:form >
                    <apex:repeat value="{!categories}" var="cat" id="theRepeat">

                        <apex:commandButton reRender="tableCategories" style="margin:4px" value="{!cat.name}"               styleClass="btn-success">

                            <apex:param name="category" value="{!cat.name}"/>
                            </apex:commandButton>

                    </apex:repeat>
         </apex:form>


 

<apex:dataTable id="tableCategories"  value="{!products}" var="prod" styleClass="table table-striped">
                    <apex:facet name="header">Products</apex:facet>
                    <apex:column value="{!prod.Category__r.name}" headerValue="Category name"/>
                    <apex:column value="{!prod.name}" headerValue="Product name"/>
.....
 


controller side
 

public List<Product__c> getProducts(){
        String CategoryName = ApexPages.currentPage().getParameters().get('category');

            List<Category__c> categs = [SELECT(select id, name, Category__r.name,Maker__r.name, description__c from product__r) from Category__c WHERE name = :CategoryName];
...
            products = categs[0].product__r;
            return products;
 

 

Best Answer chosen by Alex Sasha
VineetKumarVineetKumar
Can you replace line 95-96 with the below code:
<apex:outputPanel id="tableProduct" >
                <apex:pageBlock rendered="{!productVisibility}">

If the above doesn't work, do let me know if it would be possible for you to share your credentials.
I might have to debug your page.

All Answers

VineetKumarVineetKumar
You need to add a reRender attribute in your command button.
Something like below
<apex:commandButton action="{!makevisibleProduct}" value="View details" styleClass="btn-success" reRender="tableProduct">               
    <apex:param name="product" value="{!prod.name}"/>
</apex:commandButton>


reRender tag is required for apex:param to get working. As you can see in your second code, the command button has a reRender attribute.
Alex SashaAlex Sasha

Ok, but now i'm getting another problem, when i'm clicking my button, nothing happens, so/ it seems like rendered state is not being switched 

<apex:pageBlock id ="tableProduct" rendered="{!productVisibility}" mode="maindetail">

                <vs:panel title="Demo Panel Primary" type="primary">
                    <table class="table table-condensed" >
                   
                    <tr>
                      <td class="active">{!product.name} </td>
            
                    </tr>
                       <tr>
                      <td class="active">{!product.description__c}</td>
                  
                    </tr>
                    <tr>
                      <td class="active">{!product.quantity__c}</td>

                    </tr>
                      <tr>
                      <td class="active">{!product.price__c}</td>
          
                    </tr>
                    </table>
                </vs:panel>
                </apex:pageBlock>
<apex:form >
                        <apex:commandButton reRender="tableProduct" action="          
                       {!makevisibleProduct}" value="View details" styleClass="btn-success">
                            <apex:param name="product" value="{!prod.name}"/>
                         </apex:commandButton>
                        </apex:form>

 
VineetKumarVineetKumar
Please wrap your <apex:pageBlock> with <apex:outputPanel> and reRender the outputPanel.
<apex:outputPanel id ="tableProduct">
	<apex:pageBlock rendered="{!productVisibility}" mode="maindetail">
		<vs:panel title="Demo Panel Primary" type="primary">
			<table class="table table-condensed" >
				<tr>
					<td class="active">{!product.name} </td>
				</tr>
				<tr>
					<td class="active">{!product.description__c}</td>
				</tr>
				<tr>
					<td class="active">{!product.quantity__c}</td>
				</tr>
				<tr>
					<td class="active">{!product.price__c}</td>
				</tr>
			</table>
		</vs:panel>
	</apex:pageBlock>
</apex:outputPanel
<apex:form >
	<apex:commandButton reRender="tableProduct" action="{!makevisibleProduct}" value="View details" styleClass="btn-success">
		<apex:param name="product" value="{!prod.name}"/>
	</apex:commandButton>
</apex:form>

 
Alex SashaAlex Sasha

Unfortunately it didnt' help.  I dont't know  What else can I do except show all pages and controller. Help me please it's very important

Whole page

<!--
 - Created by LanaPC on 30.06.2016.
 -->

<apex:page sidebar="false" showheader="false" docType="html-5.0" id="index" controller="HomeController" standardStylesheets="false">

     <vs:importvisualstrap theme="paper"/>
    <html lang="en">
    <head>
       <apex:stylesheet value="{!URLFOR($Resource.bootstrap, '/css/bootstrap.min.css')}" />
        <apex:includeScript value="{!URLFOR($Resource.bootstrap, 'js/bootstrap.min.js')}"/>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <meta name="description" content=""/>
        <meta name="author" content=""/>
    </head>
    <body>

    <div  class="container-fluid">
    <div class="row">

        <div class="col-md-8" >
            <div class="page-header">

                <h1> <p class="text-danger">Alex-San Company</p> <small>Subtext for header</small></h1>
                </div>

        </div>
        <div style="margin-top: 55px"  class="col-md-4">
            <apex:form >
                <apex:commandLink >
                    <strong><apex:outputText >
                        ordered Items
                    </apex:outputText>
                    </strong>
                    <apex:outputPanel id="dd" rendered="{!productVisibility}" styleClass="badge">0</apex:outputPanel>
                </apex:commandLink>
            </apex:form>
        </div>
    </div>

    <vs:visualstrapblock >

    <div style="margin-bottom: 40px" class="row">
        <div class="col-md-8" >

                <apex:form >
                    <apex:repeat value="{!categories}" var="cat" id="theRepeat">

                        <apex:commandButton reRender="tableCategories" style="margin:4px" value="{!cat.name}" styleClass="btn-success">
                            <apex:param name="category" value="{!cat.name}"/>
                           </apex:commandButton>

                    </apex:repeat>
                </apex:form>
                      
        </div>
        <div class="col-md-4">

               <apex:form >
                    <apex:commandLink >
                        <strong><apex:outputText >
                        ordered Items
                        </apex:outputText>
                        </strong>
                        <apex:outputPanel styleClass="badge">0</apex:outputPanel>
                    </apex:commandLink>
                </apex:form>
        </div>

    </div>
     
        <vs:row >
            <vs:column type="col-md-4">
                <apex:dataTable id="tableCategories"  value="{!products}" var="prod" styleClass="table table-striped">
                    <apex:facet name="header">Products</apex:facet>
                    <apex:column value="{!prod.Category__r.name}" headerValue="Category name"/>
                    <apex:column value="{!prod.name}" headerValue="Product name"/>
                    <apex:column value="{!prod.Maker__r.name}" headerValue="Product Maker"/>
                    <apex:column value="{!prod.Description__c}" headerValue="Description"/>
                    <apex:column >
                        <apex:form >
                        <apex:commandButton reRender="tableProduct" action="{!makevisibleProduct}" value="View details" styleClass="btn-primary">
                            <apex:param name="product" value="{!prod.name}"/>
                         </apex:commandButton>
                        </apex:form>
                    </apex:column>

                </apex:dataTable>

            </vs:column>
            <vs:column type="col-md-8">

            <apex:outputPanel >
                <apex:pageBlock id="tableProduct" rendered="{!productVisibility}"> 

                <vs:panel title="Product details" type="primary">
                    <table class="table table-condensed" >
                   
                    <tr>
                        <td class="active">
                       <h5>product name</h5> 
                       </td>
                      <td class="active"><h5>{!product.name} </h5></td>
         
                    </tr>
                       <tr>
                       <td class="active">
                      <h5>description</h5>
                       </td>
                      <td class="active">  <h5>{!product.description__c}</h5></td>
             
                    </tr>
                    <tr>
                     <td class="warning">
                         <h5>quantity in stock</h5>
                       </td>
                      <td class="warning"><h5> {!product.quantity__c}</h5></td>
                 
                    </tr>
                      <tr>
                      <td class="danger">
                       <h3> price</h3>
                       </td>
                      <td class="danger"><h3>{!product.price__c} $ </h3></td>
                 
                    </tr>
                    </table>

                </vs:panel>
                </apex:pageBlock> 
               </apex:outputPanel>
                
            </vs:column>
        </vs:row>

    </vs:visualstrapblock>
    </div>
   </body>
    </html>
</apex:page>

Controller

public  with sharing class HomeController {
    private final  Set<String> distingMakersName;
    private List<Category__c>  categories;
    private List<Maker__c> relatedMakers;
    private List<Product__c> products;
    public Boolean  productVisibility{get;set;}
    Public String  ProdName{get; set; }


     private List<Set<Maker__c>> listMakers=new List<Set<Maker__c>>();

    public List<Category__c> getCategories(){
        categories=[SELECT name, Id, ( select id,name, maker__r.name, maker__r.id from product__r)  from Category__c];

       return categories;

    }

    public Boolean getisVisibleTable(){
        if (!products.isEmpty()){
            return true;
        }else return false;
    }


    public PageReference makevisibleProduct(){
          System.debug('makevisible before '+productVisibility);
          productVisibility=true;
          System.debug('makevisible after'+productVisibility);
           
          return null;
    }

    public List<Product__c> getProducts(){
        String CategoryName = ApexPages.currentPage().getParameters().get('category');
        if(CategoryName!=null) {

            List<Category__c> categs = [SELECT(select id, name, Category__r.name,Maker__r.name, description__c from product__r) from Category__c WHERE name = :CategoryName];
            if(categs[0].product__r.isempty()){
                Product__c emtyProd=new Product__c();
                emtyProd.name='now we dont have products from that category';
                List<Product__c> prs = new List<Product__c>();
                prs.add(emtyProd);
                return prs;
            }
            products = categs[0].product__r;
            return products;
        } else return products;

    }

    Public Product__c getProduct(){
         ProdName = ApexPages.currentPage().getParameters().get('product');
        
      

        List<Product__c> prods =[Select name, description__c, quantity__c,price__c from Product__c
                                   WHERE name =: ProdName
                                   ];

         if(prods.isEmpty()){
            return new Product__c();
         }
        return prods[0];
    }


    public HomeController(){

        List<Category__c> categs =[ SELECT(select id,name, Category__r.name, Maker__r.name, description__c from product__r) from Category__c WHERE name ='Tablet'];
        products=categs[0].product__r;
        productVisibility=false;
           System.debug('contstructor ' + productVisibility);
 

    }

}
VineetKumarVineetKumar
Can you replace line 95-96 with the below code:
<apex:outputPanel id="tableProduct" >
                <apex:pageBlock rendered="{!productVisibility}">

If the above doesn't work, do let me know if it would be possible for you to share your credentials.
I might have to debug your page.
This was selected as the best answer
Alex SashaAlex Sasha
Yes, it's done. Thanks a lot!
Alex SashaAlex Sasha
But it still  very strange though
VineetKumarVineetKumar
Cool..
If my suggestion(s) helped you, do mark it as the "Best Answer" right under the comment.
This will help the rest of the community should they have a similar issue in the future. 

Thank you..
VineetKumarVineetKumar
strange as in?
Alex SashaAlex Sasha

I mean why it works only in such a way and neither <apex:outputPanel id="tableProduct"  rendered="{!productVisibility}" > no 

<apex:pageBlock  id= "tableProduct" rendered="{!productVisibility}">

Alex SashaAlex Sasha
where is your answer?) add it please
VineetKumarVineetKumar
Ok, so as a rule of thumb you can assume that whenever you reRender a component, the sub components or the child components get refreshed/reRendered. So, when you were reRendering apex:pageBlock, it was reRendering the child components, and not the pageBlock itself. Hence the value was remaining the same. So, to refresh the apex:pageBlock we wrapped it wround with an apex:outpanel and reRendered it.
I hope this explains your query.
Alex SashaAlex Sasha
Ok thanks