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
CodeFinderCodeFinder 

get input text value from pageblocktable

Hi, 

 

I would want to get the quantity from the input text of the table. I need it so that I can update the quantity for quote_line_items object.

 

<apex:page standardController="Product2" extensions="ProductListController">
<apex:form >
    <apex:pageBlock title="Products List">
        <apex:pageBlockSection title="List of Available Address" columns="1">
            <apex:pageBlockTable value="{!productsList}" var="prod"> 
                
                <apex:column headerValue="Select"> 
	    	 		<apex:commandLink value="Select" onclick="return confirm('Are you sure?')" action="{!selectId}" >
		          		<apex:param name="prodid" value="{!prod.id}" />
		          	</apex:commandLink>
		        </apex:column> 
                </apex:column>
                <apex:column headerValue="Product Name" >{!prod.Name}</apex:column>
                <apex:column headerValue="Size/Dimensions" >{!prod.Size_Dimensions__c}</apex:column>
                <apex:column headerValue="Total Quantity" >{!prod.Total_Quantity__c}</apex:column>
                <apex:column headerValue="Available Quantity" >{!prod.Available_quantity__c}</apex:column>
                <apex:column headerValue="Quantity Required" >
                    <apex:inputText value="{!quantity}"></apex:inputText>
                </apex:column>              
            </apex:pageBlockTable>
        </apex:pageBlockSection>    
    </apex:pageBlock>   
</apex:form>
</apex:page>

 

public with sharing class ProductListController{
    public Product2 product;
    public List<Product2> productsList = null;
    public id quoteId {get; set;}
    public String productId {get; set;}
    public Integer quantity;
    
    public ProductListController(ApexPages.StandardController controller)
    {
        product = (Product2) controller.getRecord();
        quoteId = ApexPages.currentPage().getParameters().get('quoteId');
    }
    
    public Integer getQuantity()
	{
	  return quantity;
	}
	
	public void setQuantity(Integer newTD)
	{
	   quantity=newTD;
	}
    
    public List<Product2> getProductsList()
    {   
        try{
            String query = 'SELECT ID, NAME, Available_quantity__c, Total_Quantity__c,  Size_Dimensions__c FROM Product2 ';
            productsList = Database.query(query);
        }
        catch(Exception e)
        {
            System.debug(e.getMessage());
        }   
        return productsList;
    }
    
    public PageReference selectId(){
    	productId = System.currentPageReference().getParameters().get('prodid');
    	Quote__c quote = [Select id,Name from Quote__c where id=:quoteId];
    	if(productId.length()>15){
			productId = (productId).substring(0,15);	
		}
    	Quote_Line_Item__c quoteLineItem = new Quote_Line_Item__c();    	
    	Product2 product = [Select id, Name from product2 where id=:productId];
    	quoteLineItem.Name = 'PROD - '+quote.Name+'  '+product.Name;
    	quoteLineItem.Product__c =  product.Id;
    	System.debug('*********Quantity*********' + quantity);
    	quoteLineItem.Quantity__c = quantity; 
    	quoteLineItem.Quote__c = quoteId;  	
    	insert quoteLineItem;
    	
    	return new PageReference('/' + quoteId);
    	 
    }
    
}

 But the quantity value does not pass into the variable. Can you please help me out.

 

 

Ron HessRon Hess

you have multiplte rows on your page table, but only one quantity field, so it may be that your controller is bound to multiple fields on that page, which one you get back from the page would be random i think.

 

if you try it with exactly one row in productsList , does it work as you expect?

CodeFinderCodeFinder

It is a list with a quantity text for every row in the list. I have not tried to do it for just one record.

bob_buzzardbob_buzzard

The thing is, you don't have quantity text for every row in the list.  While you have an apex:inputtext element for every row in the list, they are all bound to a single controller property.  This means that every input writes to the same controller property, so the last row to fire a setter wins.

 

I've explained this in more detail at:

 

http://salesforce.stackexchange.com/questions/5391/get-value-from-selectoption-in-a-pageblocktable/5393#5393

 

This is referring to a selectlist, but the principle applies to your situation too.

Sure@DreamSure@Dream
Hi Bob,

I am having code like this:


<apex:repeat value="{!listOfCodes}" var="code">
         ..........
        ...........
      <apex:inputTextArea value="{!comment}"/>
    <apex:commandLink action="{!submit}" />
</apex:repeat>



On clicking the submit button,  comment is getting as empty in the controller, even if i enter some text.

Could you please help me with this?.
siddarth rajsiddarth raj
Hi Sure@Dream

Could you please share here your solutions I am got into similar situation spent 2 days on figuring out what and why not returning latest values.....Your reply would really help me. Thanks
raz rraz r
Hi All,
Please provide the solution for the above issue ASAP...

Appriciate your quick response!!!