You need to sign in to do that
Don't have an account?
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();
}
}
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();
}
}
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>
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.