Right now, I have a VF page in which I need to pass at least one object to get a list from SF.

The context:

An application that is used to monitor bikes that are used by clients going from one point to another in the city. The city has several points where the client can leave/take the bike, and he can only leave the bike into another point or the same point.

The issue:

I have a VF page that can receive two inputs to create a new record that a bike was taken by a client: the client and the point where he is taking the bike from. I would like to have a list of available bikes in that point before creating the record, but the list isn't populated when I select a point.

The page code:

<apex:page controller="LocacaoController" tabStyle="Locacao__c">
<apex:form >
    <apex:pageBlock title="Ações">
        <apex:commandButton action="{!createLocacao}" value="Nova Locação" rendered="{!!displayCriacao}"/>
        <apex:commandButton action="{!finalizarLocacao}" value="Finalizar Locação" rendered="{!!displayCriacao}"/>
        <apex:commandButton action="{!inicioLocacao}" value="Início"/>

    <apex:pageblock title="Locações">
        <apex:pageBlockTable value="{!locacoes}" var="loc" rendered="{!!displayCriacao}">
            <apex:column headerValue="Locação">
                <apex:outputText value="{!loc.Name}"/>
            <apex:column headerValue="Bicicleta Utilizada">
                <apex:outputText value="{!loc.Bicicleta__r.Name}"/>
            <apex:column headerValue="ID do Cliente">
                <apex:outputText value="{!loc.Cliente__r.Name}"/>
            <apex:column headerValue="Nome do Cliente">
                <apex:outputText value="{!loc.Cliente__r.NomeCliente__c}"/>
            <apex:column headerValue="Ponto de Locação">
                <apex:outputText value="{!loc.Ponto_Locacao__r.Name}"/>

    <apex:pageBlock title="Nova Locação" rendered="{!displayCriacao}">
        <!--<apex:commandButton action="{!inicioLocacao}" value="Voltar"/>-->

        <apex:outputLabel value="Cliente" for="ClienteLabel"/>
        <apex:inputField value="{!novaLocacao.Cliente__c}" id="ClienteLabel"/>

        <apex:outputLabel value="Ponto" for="PontoLabel"/>
        <apex:inputField value="{!novaLocacao.Ponto_Locacao__c}" id="PontoLabel">
            <apex:actionSupport event="onchange" reRender="listaBikesNoPonto"/>

        <apex:pageBlockTable value="{!AvailableBikes}" var="bike" id="listaBikesNoPonto">
            <apex:column headerValue="ID da Bike">
                <apex:outputText value="{!bike.Name}"/>
            <apex:column headerValue="Disponível">
                <apex:outputText value="{!bike.Disponivel__c}"/>

    <apex:pageBlock title="Finalizar Locação">

The controller:

// controller
public class LocacaoController
    // booleans controle de form
    public boolean displayCriacao {get; set;}
    public boolean displayFinalizacao {get; set;}

// form criação
public Locacao__c novaLocacao {get; set;}
public List<Bicicleta__c> bikes {get; set;}

// form padrão
List<Locacao__c> locacoes;

public List<Locacao__c> getLocacoes()
    if (locacoes == null)
        locacoes = [SELECT id, Name, Bicicleta__r.Name, Cliente__r.NomeCliente__c, Cliente__r.Name, Status__c, Ponto_Locacao__r.Name  FROM Locacao__c WHERE Status__c = 'Em andamento'];
    return locacoes;

public void createLocacao()
    displayCriacao = true;

public void finalizarLocacao()
    displayFinalizacao = true;

public void inicioLocacao()
    displayCriacao = false;
    displayFinalizacao = false;

public List<Bicicleta__c> getAvailableBikes()
    if (novaLocacao == null)
        novaLocacao = new Locacao__c();
        return null;
    if (novaLocacao.Ponto_Locacao__c == null)
        return null;
        return [SELECT id, Name, Disponivel__c FROM Bicicleta__c WHERE Disponivel__c = true AND PontoAtual__c = :novaLocacao.Ponto_Locacao__c];

How can I make the rerender work? Is there a simple solution to do what I want here?

I have searched SE and Google for similar issues, but none of them worked for me or fitted my case.

  • Just to confirm you want the <apex:pageBlockTable value="{!AvailableBikes}" var="bike" id="listaBikesNoPonto"> to rerender when an event happens?
    – AlphaBravo
    Apr 2 '15 at 18:52
  • Yes. I want a list of bikes on that table. Apr 2 '15 at 18:53
  • It's really weird on the VF page. you need to put that inside of an outputPanel: <apex:outputPanel id="thePanel">*Table here*</apex:outputPanel> and <apex:actionSupport event="onchange" reRender="listaBikesNoPonto"/> should be <apex:actionSupport event="onchange" reRender="thePanel"/>
    – AlphaBravo
    Apr 2 '15 at 18:56
  • Did those changes. The list still doesn't appear. <apex:outputpanel id="listaBikesNoPonto"> <apex:pageBlockTable value="{!AvailableBikes}" var="bike"> <apex:column headerValue="ID da Bike"> <apex:outputText value="{!bike.Name}"/> </apex:column> <apex:column headerValue="Disponibilidade"> <apex:outputText value="{!bike.Disponivel__c}"/> </apex:column> </apex:pageBlockTable> </apex:outputpanel> is the code I'm using. Apr 2 '15 at 19:04
  • Have you checked the debug logs to see you're getting past your logic if novalocacao and Ponto_Locacao__C are both not null? -- My suggestion would be comment it out: if (novaLocacao == null) novaLocacao = new Locacao__c(); return null; if (novaLocacao.Ponto_Locacao__c == null) return null; -- and make sure the query is actually returning data.
    – AlphaBravo
    Apr 2 '15 at 19:12

Try wrapping your inputfield in an apex:actionregion.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.