You need to sign in to do that
Don't have an account?
Javier Castro
Passing values from pageBlockTable to custom controller
Hi, I'm trying to pass values from a pageBlockTable to my custom controller, but something is not working properly and I don't what it is. I post my code below and I hope someone can help me.
Thanks in advance.
Visualforce code:
Controller code:
My second div is displayed but I always get null in my params. If I put a reRender attribute on the command button I get the correct values in my params but the second div is not displayed.
Thanks in advance.
Visualforce code:
<div calss="modal-dialog" style="display:{!if(mostrarCitasPaciente,'block','none')};"> <div class="tablemodal-container"> <apex:form id="tabla"> <apex:pageBlock > <apex:pageBlockTable value="{!lstCitas}" var="citas" styleClass="table table-hover"> <apex:column value="{!citas.Name}"/> <apex:column value="{!citas.CloseDate}"/> <apex:column value="{!citas.Doctor__c}"/> <apex:column value="{!citas.Doctor__r.Especialidad__c}"/> <apex:column> <apex:commandButton value="Ver cita" action="{!mostrarCitaIndividualPaciente}"> <apex:param name="doctor" value="{!citas.Doctor__c}" assignTo="{!doctorCita}"/> <apex:param name="especialidad" value="{!citas.Doctor__r.Especialidad__c}" assignTo="{!especialidadCita}"/> <apex:param name="fecha" value="{!citas.CloseDate}" assignTo="{!fechaCita}"/> </apex:commandButton> </apex:column> </apex:pageBlockTable> <table class="table borderless" align="center"> <tr> <td align="center"> <apex:commandButton styleClass="btn btn-secondary" value="Primera pagina" reRender="tabla" action="{!primeraPagina}" disabled="{!Ant}"/> <apex:commandButton styleClass="btn btn-secondary" value="Pagina anterior" reRender="tabla" action="{!anterior}" disabled="{!Ant}"/> <apex:commandButton styleClass="btn btn-secondary" value="Pagina siguiente" reRender="tabla" action="{!siguiente}" disabled="{!Sig}"/> </td> </tr> </table> </apex:pageBlock> </apex:form> </div> </div> <div class="modal-dialog" > <div class="tablemodal-container"> <table align="center" id="RID"> <tr> <td align="left"><apex:outputLabel value="Doctor"/></td> <td align="center"><apex:outputLabel value="Especialidad"/></td> <td align="right"><apex:outputLabel value="Fecha"/></td> </tr> <tr> <td>{!doctorC}</td> <td>{!especialidadC}</td> <td>{!fechaC}</td> </tr> </table> </div> </div>
Controller code:
public class controlador{ public String doctorCita{ get; set; } public String especialidadCita{ get; set; } public String fechaCita{ get; set; } public String doctorC{ get; set; } public String especialidadC{ get; set; } public String fechaC{ get; set; } public void obtenerCitaIndiviudalPaciente(){ doctorC = this.doctorCita; especialidadC = this.especialidadCita; fechaC = this.fechaCita; //My logic } }
My second div is displayed but I always get null in my params. If I put a reRender attribute on the command button I get the correct values in my params but the second div is not displayed.
All Answers
There is a known problem with <apex:param> and <apex:commandButton> and you need a reRender Id (could be dummy, targetted an empty panel for instance)
Need to be add a DummyID for reRender.
https://salesforce.stackexchange.com/questions/187539/passing-parameters-commandbutton
<apex:outputPanel id="panel2">
</apex:outputPanel>
<apex:commandButton ... reRender="panel2">
<apex:param ... />
</apex:commandButton>
I'm going to write my new simplified code below.
Visualforce code:
Controller code:
What I want to do is when I click the button, the second "div group" should be displayed with the values corresponding to the row on the table, because the vars should have the value of the params.
I can see in the console logs that the params has the correct values but for some reason the second div group is not displayed, and this is what I want to solve now.
Thanks in advance.