+ Start a Discussion
JevJev 

Adding a inputField to a list in Apex/Visualforce

Hi,

 

I have a Visualforce page that lists all the products for a given opportunity in a apex:pageBlockTable

 

I want to add a column called "Quantity to order" which will be used in my controller to create some new objects. This field does not exist in the OpportunityLineItem object.

 

How do I add an additional inputText field to my pageBlockTable and have it bound to my controllerExtension, when it is not actually a field in Salesforce?

 

Ideally I'd like to programatically add a new Integer to the Opportunity.OpportunityLineItems List.

 

Thanks,

-Jev

Best Answer chosen by Admin (Salesforce Developers) 
hemantgarghemantgarg

Inner class will definitely solve your issue , use a inner class like following :-

 

public class Wrapper{

     public OpportunityLineItem line{get;set;}

     public String newField{get;set;}

}

 

Best

Hemant

All Answers

Starz26Starz26

add:

 

onblur="return setValue();"

 

Java:

 

<script>

 

function setValue(){

var a = document.getElementById('{!$Component.IDOFYOURIMPUTTEXTFIELD}').value;

       if (a != ""){
        sValue(a);
        return false;
       } else{
        return false;
      }
}

</script>

 

Then add an action function to the form to set the controller variable:

 

<apex:actionFunction name="sValuer" action="{!FUNCTIONINCONTROLLERTOUPDATEOPPLINEITEMWITHVALUE"}
<apex:param name="sValue" value="nothing " assignTo="{VARIABLEINCONTROLLERTOSET}"/>
</apex:actionFunction>

 

Basically this calls the javascript setValue after the inputText field looses focus (or you could do on change, or use a commandlink with the onclick set to "return setValue();"

 

the javascript then gets the value of the inputTextfield and passes it to the action function which uses the param tag to set the variable in the controller. The action in the action function calls a function int he controller that can use the value set by the param to update the opp line item.

hemantgarghemantgarg

Inner class will definitely solve your issue , use a inner class like following :-

 

public class Wrapper{

     public OpportunityLineItem line{get;set;}

     public String newField{get;set;}

}

 

Best

Hemant

This was selected as the best answer
JevJev

Thanks hemantarg, this is what I was looking for. 

 

Starz26, very interesting approach. I'll use this elsewhere!