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
Cesar Ramirez Vasquez005391619375684564Cesar Ramirez Vasquez005391619375684564 

I cant get the value of an input field (lookup) in the controller ? Value is always null.

So i have a function that allows me to search and select the lookup value; after i select 1 and the textbox is filled i use a command link to send that value among others to the controller and update the object but no matter what i do the lookup value is alwais null. Any ideas ? I am stucked, thanks in advance for your time!

Visual Force:
<apex:pageBlockTable id="srch_id" value="{!Piezas}" var="o">
            
            <apex:column value="{!o.Name}"> <apex:facet name="header"> </apex:facet> </apex:column>          
            <apex:column value="{!o.Producto__r.Name}"> <apex:facet name="header"> </apex:facet> </apex:column>
            <apex:column value="{!o.Bodega__c}"> <apex:facet name="header"> </apex:facet> </apex:column>
            <apex:column value="{!o.Estado__c}"> <apex:facet name="header"></apex:facet> </apex:column>
            <apex:column value="{!o.Reparaci_n_ETL__c}"> <apex:facet name="header"> </apex:facet> </apex:column>
            <apex:column headerValue="Opciones" >
          

           
                  //This is the value i am unable to get
                  <apex:inputField id="Reparacion" value="{!PI.Reparaci_n_ETL__c}"/>

           
 
                    <apex:commandLink value="Agregar a Reparacion" action="{!actualizaPieza}" immediate="false">
                            <apex:actionSupport event="onclic"/>    
                            <apex:param name="namePieza"   assignTo="{!piezaActual}" value="{!o.Name}"  />
                            <apex:param name="rep" value="Reparacion"  />
                   </apex:commandLink>
                  
            </apex:column>
           
        </apex:pageBlockTable>

Controller :

public class addPiezaController {

public String order {get; set;}
public List<Pieza__c> Piezas = new List<Pieza__c>();
public String piezaActual {get; set;}
public id idRep {get; set;}

private Pieza__c PI = new Pieza__c();

public void setPI(Pieza__c value) {
    PI = value;
}

public Pieza__c getPI() {
    return PI;
}




//This is the method i am trying to execute
public addPiezaController (){
order = '';
Piezas = null;
piezaActual = '';
}

public List<Pieza__c> getPiezas(){

Piezas = [select Name, Producto__r.Name, Bodega__c, Estado__c, Reparaci_n_ETL__c from Pieza__c where Orden__r.Name =: order ];

return Piezas;
}

public void actualizaPieza(){

//Id repID = ApexPages.currentPage().getParameters().get('idRep');

System.debug(LoggingLevel.Error, 'Reparacion ID:' + PI.Reparaci_n_ETL__c);
System.debug(LoggingLevel.Error, 'Name:' + piezaActual);


Pieza__c P = [select name, Reparaci_n_ETL__c, Estado__c  from Pieza__c where name =: piezaActual];
P.Reparaci_n_ETL__c = PI.Reparaci_n_ETL__c;
P.Estado__c = 'Utilizada en reparación';

Update(P);

getPiezas();
}

}
SrikanthKuruvaSrikanthKuruva
Declare private Pieza__c PI = new Pieza__c(); as public instead of private.let me know if you find an issue even after doing this.

Also i see that you have to correct the code as below(highlighted in bold letters).  
<apex:commandLink value="Agregar a Reparacion" action="{!actualizaPieza}" immediate="false">
                            <apex:actionSupport event="onclick"/>   
                            <apex:param name="namePieza"   assignTo="{!piezaActual}" value="{!o.Name}"  />
                            <apex:param name="rep" value="Reparacion"  />
                   </apex:commandLink>


Cesar Ramirez Vasquez005391619375684564Cesar Ramirez Vasquez005391619375684564
No still not working the main issue is that when i select the lookup value and hit the command link the value selected disapear. Thats so wear. Thanks for your reply i will keep trying !!
SrikanthKuruvaSrikanthKuruva
ok got it. Can you do this.
give an id to the form in the VF page. say <apex:form id="form1">
And now in the commandlink please use a rerender attribute
<apex:commandLink value="Agregar a Reparacion" action="{!actualizaPieza}" immediate="false" reRender="form1">

since immediate default value is false you can remove this attribute however this is not compulsory.
now try to run and then check the value at
System.debug(LoggingLevel.Error, 'Reparacion ID:' + PI.Reparaci_n_ETL__c);

This should solve the issue. let me know how it goes.