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
sonamsonam 

Retrive radio button value

Hi,

I'm quite new to salesforce.

I'm developing a mock page it should have the following fuctionality.

 

1. Search book and customer on basis of certain fields.(runs successfully)

2. Select the book and customer(which are selected through radio button) and sent in the click of 'ISSUE' button.

3. After clicking issue the book should be assigned and the borrower field of the book should be updated by the customer ID.

 

I'm able to do the 1st.

I get the values initially in debug but wen it comes to my 'Issue method' it flushes the values

I am not able to retrieve the values of radio button in the apex class.

 

Please guide me on this.

 

Below is my class and the VF page

<apex:page controller="newBookController">

<apex:form >
            <apex:sectionHeader title="Search a Customer"/>
                <apex:outputLabel style="font-weight:bold;" value="Name" ></apex:outputLabel>
                    <apex:inputText value="{!Name}"/> 
                    
            <br></br> 
        
            <apex:sectionHeader title="Search for a Book"/>
                <apex:outputLabel style="font-weight:bold;" value="Author" ></apex:outputLabel>
                    <apex:inputText value="{!Author}"/> 
                    
                <br></br> 
                <apex:outputLabel style="font-weight:bold;" value="Book Name" ></apex:outputLabel>
                    <apex:inputText value="{!BookName}"/>
                    
                <br></br> 
                <br></br>  
                        
                <apex:outputLabel style="font-weight:bold;" value="Price" >    
                    <apex:selectRadio id="selectRadio" value="{!bookPriceRange}">
                    <apex:selectOptions value="{!priceRange}"/>
                    </apex:selectRadio>
                </apex:outputLabel>
                    <apex:inputText value="{!price}"/>
    <br></br> 
    <br></br>   
    <br></br>
    
    
<apex:commandButton action="{!search}" value="Search" id="search" rerender="out, msgs, table" status="status"/>
    </apex:form>


<apex:form > 

<apex:outputpanel id="table">
        <apex:pageBlock >
                <apex:pageBlockTable value="{!Books}" var="c" >
                    <apex:column headerValue="select">
                        <apex:actionSupport action="{!getBook}" event="onclick" rendered="true" reRender="hidden">
                            <input type="radio" name="selectBook" id="id">
                            <apex:param name="BookID" value="{!c.Id}"/>
                            </input>
                        </apex:actionSupport>
                    </apex:column>
                    
                    <apex:column >
                            <apex:facet name="header">ID</apex:facet>
                            <apex:commandLink action="{!gotoPage}" id="theCommandLink" value="{!c.name}"> 
                            <apex:param value="{!c.id}" name="pid" ></apex:param>
                            
                            </apex:commandLink> 
                </apex:column>
                    
                    <apex:column >
                            <apex:facet name="header">Author</apex:facet>
                            <apex:outputField value="{!c.Author__c}" ></apex:outputField>
                    </apex:column>
                    <apex:column >
                            <apex:facet name="header">Book Name</apex:facet>
                            <apex:outputField value="{!c.Book_Name__c}" />
                    </apex:column>
                
                    <apex:column >
                            <apex:facet name="header">Price</apex:facet>
                            <apex:outputField value="{!c.price__c}" />
                    </apex:column>
                
                
                </apex:pageBlockTable>
        </apex:pageBlock>

    <apex:pageBlock >
            <apex:pageBlockTable value="{!Customers}" var="c">
                   
                    <apex:column headerValue="select">
                        <apex:actionSupport action="{!getCustomer}" event="onclick" rendered="true" reRender="hidden">

                            <input type="radio" name="selectCustomer" id="id">
                            <apex:param name="CustomerID" value="{!c.Id}"/>
                            </input>
                        </apex:actionSupport>
                    </apex:column>
                    <apex:column >
                        <apex:facet name="header">ID</apex:facet>
                        <apex:outputField value="{!c.Name}" />
                    </apex:column>
                    <apex:column >
                        <apex:facet name="header">Customer Name</apex:facet>
                        <apex:outputField value="{!c.Name__c}" />
                    </apex:column>
            
            </apex:pageBlockTable>
    </apex:pageBlock>


</apex:outputPanel>

<apex:commandButton action="{!issue}" value="Issue" id="Issue" rerender="out, msgs, table" status="status"/>

</apex:form>



</apex:page>

 

public class newBookController {

List <Book__c> Books;
List <Book__c> BooksSelected;
List <Customer__c> Customers;
private String Name=null;
private String Author= null;
private String BookName= null;
String bookPriceRange=null;
Double price=null;
integer flag=0;
public String selectBook =null;
public String selectcustomer=null;
public String selectBookIssue =null;
public String selectcustomerIssue=null;






    public String getAuthor() { return Author; }
    public void setAuthor(String dataAuthor) { Author = dataAuthor; }
    
    public String getName() { return Name; }
    public void setName(String dataName) { Name = dataName; }
    
    public String getBookName() { return Bookname; }
    public void setBookName(String dataBookname) { BookName= dataBookname; }
    
    public String getBookPriceRange() {  return bookPriceRange;    }
    public void setBookPriceRange(String bookPriceRange) { this.bookPriceRange= bookPriceRange; }
    
    public Double getPrice() {  return price;    }
    public void setPrice(Double price) { this.price= price; }




    
     public List<SelectOption> getPriceRange() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('Greaterthan','Greater than')); 
        options.add(new SelectOption('Lessthan','Less than')); 
        options.add(new SelectOption('Equalto','Equal to')); return options; 
    }
                   
   
    
public void search()
        {  


            If(Name!=null)
                    {
                        String queryStr = 'SELECT Name__c,Name from Customer__c WHERE'  + '(Name__c like \'%' + Name+ '%\')';
                        Customers=DataBase.query(queryStr);

                    }      
                    
 //-------------------- Code to search for book-------------------------------------// 
                          
            If(price==null  || bookPriceRange==null)           
 

                    {
                        
                        
                        If (Author!=null && (BookName=='' && BookName==null) )          
                            {
                                String queryStr = 'SELECT Author__c,Book_Name__c,Name from Book__c WHERE'  + '(Author__c like \'%' + Author+ '%\')';
                                Books=DataBase.query(queryStr);
                                
                                system.debug('Books-----------------with like AUTHOR-------------  -------------'+Books);
                            }

                        If ((Author==null && Author=='')&& BookName !=null )           
                            {
                                String queryStr = 'SELECT Author__c,Book_Name__c,Name from Book__c WHERE'  + '(Book_Name__c  like \'%' + Bookname + '%\')';
                                Books=DataBase.query(queryStr);
                                system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                            }




                        If (Author!=null && BookName!=null )          
                            {
                            
                                String queryStr = 'SELECT Author__c,Book_Name__c,Name from Book__c WHERE'  + '(Author__c like \'%' + Author+ '%\')' + 'or'+ '(Book_Name__c  like \'%' + Bookname + '%\')';
                                Books=DataBase.query(queryStr);
                                system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                            }
                }

        else

        {


                If(bookPriceRange=='Equalto' )
                    {
                    
                                If (Author!=null && (BookName=='' && BookName==null))           
                                {
                                            String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE'  
                                            + '(Author__c like \'%' + Author+ '%\')'
                                            +'and'
                                            +'(price__c = :price)'
                                            ;
                                            Books=DataBase.query(queryStr);
                                            
                                            system.debug('Books-----------------with like AUTHOR-------------  -------------'+Books);
                                }

                                If ((Author==null && Author=='')&& BookName !=null)           
                                {
                                            String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE '  
                                            + '(Book_Name__c  like \'%' + Bookname + '%\')'
                                            +'and'
                                            +'(price__c = :price)';
                                            Books=DataBase.query(queryStr);
                                            system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                                }
                                



                                If (Author!=null && BookName!=null   )           
                                {
                                
                                            String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE'  
                                            +'('+ 
                                            
                                            +'('+ 
                                            + '(Author__c like \'%' + Author+ '%\')' 
                                            + 'or'
                                            + '(Book_Name__c  like \'%' + Bookname + '%\')'
                                            +')'+
                                            +'and'
                                            +'(price__c =  :price))';
                                            Books=DataBase.query(queryStr);
                                            system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                                }
                                

            }
 
            {
        If(bookPriceRange=='Greaterthan' )
            {


                If (Author!=null && (BookName=='' && BookName==null))           
                {
                        String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE'  
                        + '(Author__c like \'%' + Author+ '%\')'
                        +'and'
                        +'(price__c > :price)'
                        ;
                        Books=DataBase.query(queryStr);
                        
                        system.debug('Books-----------------with like AUTHOR-------------  -------------'+Books);
                }

                If ((Author==null && Author=='')&& BookName !=null)           
                {
                        String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE '  
                        + '(Book_Name__c  like \'%' + Bookname + '%\')'
                        +'and'
                        +'(price__c > :price)';
                        Books=DataBase.query(queryStr);
                        system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                }




                If (Author!=null && BookName!=null   )           
                {
                
                        String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE'  
                        +'('+ 
                        
                        +'('+ 
                        + '(Author__c like \'%' + Author+ '%\')' 
                        + 'or'
                        + '(Book_Name__c  like \'%' + Bookname + '%\')'
                        +')'+
                        +'and'
                        +'(price__c >  :price))';
                        Books=DataBase.query(queryStr);
                        system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                }


}


{
    If(bookPriceRange=='Lessthan' )
    {



                If (Author!=null && (BookName=='' && BookName==null))           
                {
                        String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE'  
                        + '(Author__c like \'%' + Author+ '%\')'
                        +'and'
                        +'(price__c < :price)'
                        ;
                        Books=DataBase.query(queryStr);
                        
                        system.debug('Books-----------------with like AUTHOR-------------  -------------'+Books);
                }

                If ((Author==null && Author=='')&& BookName !=null)           
                {
                        String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE '  
                        + '(Book_Name__c  like \'%' + Bookname + '%\')'
                        +'and'
                        +'(price__c < :price)';
                        Books=DataBase.query(queryStr);
                        system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
                        }




            If (Author!=null && BookName!=null   )           
            {
            
                        String queryStr = 'SELECT Author__c,Book_Name__c,Name,price__c from Book__c WHERE'  
                        +'('+ 
                        
                        +'('+ 
                        + '(Author__c like \'%' + Author+ '%\')' 
                        + 'or'
                        + '(Book_Name__c  like \'%' + Bookname + '%\')'
                        +')'+
                        +'and'
                        +'(price__c <  :price))';
                        Books=DataBase.query(queryStr);
                        system.debug('Books-----------------with like BOOK NAME-------------  -------------'+Books);
            }


}


}          


}

}         




//-------------------code to search for customers--------------------




}    
public List<Customer__c> getCustomers() {

return Customers;
}

public List<Book__c> getBooks() {

return Books;
}


public PageReference gotoPage() 
{
system.debug('in gotoPage method');
String idVal = ApexPages.currentPage().getParameters().get('pid');
system.debug('idVal>>>'+idVal);
PageReference redirect = new PageReference('https://ap1.salesforce.com/'+idVal); 
//redirect.getParameters().put('id',ApexPages.currentPage().getParameters().get('id')); 

redirect.setRedirect(true); 

return redirect;
}

public void getCustomer()
{
//--------------- getting the value in debug

selectcustomer = System.currentPagereference().getParameters().get('CustomerID');
system.debug('------------------------customer--------------'+selectcustomer);
String selectcustomerIssue=selectcustomer;

}

public void getBook()
{
//--------------- getting the value in debug
selectBook = ApexPages.currentPage().getParameters().get('BookID');
system.debug('-------------------------book---------------'+selectBook);
String selectBookIssue=selectBook;

}
 
public void issue()
{
//---------------------debug value= null----------------------
system.debug('------------------------customer-issue-------------'+selectcustomerIssue);

system.debug('-------------------------book----issue-----------'+selectBookIssue);



//String queryBook ='(Select id,price__c,Name,Name__c from Book__c where borrower__c=:selectcustomer)';
//BooksSelected=DataBase.query(queryBook);


//        for(Book__c b:BooksSelected)
  //          {
    //            if(b.id==selectBook)
      //              {
        //            flag=1;
          //          }
            //}
            
            
//If(flag==0)
  //  {
  //      Book__c BooksSelected = [SELECT Author__c,Book_Name__c,Name,price__c,borrower__c FROM Book__c WHERE id=:selectBook];
  //      BooksSelected.borrower__c =selectcustomer; 
    //    
      //  try 
          //  {
        //        update BooksSelected;
       //     } 
        //catch (DmlException e) 
       //     {
         //       system.debug('update done');
           // }
    
    //}




}



public void calTotalAmt(Book__c[] books)
{
for(Book__c b:BooksSelected)
{
price=price+b.price__c;
}
}







}

 

Ashish_SFDCAshish_SFDC

Hi Sonam, 

 

Please try if by changing the Radio button and adding two defined picklist values and adding the values to a list solves your problem, not sure if that affects your design. 

 

Regards,

Ashish

sonamsonam

Hi Ashish,

 

Thank you for your reply.

But , i need to hav the details in a table.

 

Regards,

Sonam