You need to sign in to do that
Don't have an account?
How do I hide/show a Visualforce page upon clicking a button?
I am trying to teach myself Apex, so I've come up with a project to create and am figuring it out step-by-stumbling-step. Here is the step I am stuck on.
Here is my goal: I want a page that shows you a list of records in a table. When you click the name of one of the records, the whole list disappears and you see a page showing information from that record.
Here's my code so far which is not working. It's a page which loads the two separate pages, and decides which one to render based on whether a certain variable (the selected record id) is null or not.
Controller:
Page 1:
detailPage:
Actual results: Clicking the name does nothing.
Am I on the right track trying to do this with three separate pages? Or should this all be handled in one visualforce page?
Here is my goal: I want a page that shows you a list of records in a table. When you click the name of one of the records, the whole list disappears and you see a page showing information from that record.
Here's my code so far which is not working. It's a page which loads the two separate pages, and decides which one to render based on whether a certain variable (the selected record id) is null or not.
Controller:
public class testController { public id gameId{get; set;} public List<Game__c> getGames() { List<Game__c> results = Database.query( 'SELECT id,name,owner.name,LastModifiedDate FROM game__c' ); return results; } }
Page 1:
<apex:page showheader="true" controller="testController"> <apex:include pageName="listPage" rendered="{! ISNULL( gameId ) }"/> <apex:include pageName="detailPage" rendered="{! NOT( ISBLANK( gameId )) }"/> </apex:page>listPage:
<apex:page showHeader="false" controller="testController" id="display"> <apex:form > <apex:pageblock > <apex:pageblocktable value="{! games}" var="g"> <apex:column headerValue="Name"> <apex:commandLink value="{!g.Name}" rerender="display" > <apex:param assignTo="{!gameId}" name="{!g.Id}" value="{!g.Id}"/> </apex:commandLink> </apex:column> </apex:pageblocktable> </apex:pageblock> </apex:form> </apex:page>
detailPage:
<apex:page showHeader="false" controller="testController"> <apex:outputtext value="test" /> </apex:page>Expected behavior: I click the the name of the any of the Game records in the list on the listPage and the whole list disappears and is replaced with a blank white screen and the word "test".
Actual results: Clicking the name does nothing.
Am I on the right track trying to do this with three separate pages? Or should this all be handled in one visualforce page?
Here is your code Just remove this attribute from your commane link :-
It will work properly..
If you need explaination why it is behaving like this, please let me know.
Happy to Help :)
All Answers
Create one visualforce page and controller use Rendered in the output panel, declare all the pageblocktable inside one output panel and record detail in the another page.when you click that name of the record call a method from controller and true and false that output panels.
Thanks
Vinuthh S
Here is your code Just remove this attribute from your commane link :-
It will work properly..
If you need explaination why it is behaving like this, please let me know.
Happy to Help :)
It displays the Detail section, if you click on one of the links in the list.
APEX Controller VF Page (Page Name: TestListDetail)
You need to replace the object and field names, if you want to try this code as it is.
Hope this helps.
public with sharing class testListDetail {
public String gameId {get; set;}
public List<Test__c> games {get; set;}
public Test__c game {get; set;}
public Boolean Table {get; set;}
public Boolean DetailPage {get; set;}
public testListDetail(ApexPages.StandardController controller) {
games = [SELECT Id, Name FROM Test__c];
Table = true;
DetailPage = false;
}
public PageReference fetchDetail(){
if (gameId != null){
game = [SELECT Id, Name, Number__c, Product_Support__c FROM Test__c WHERE Id = :gameId];
}
Table = false;
DetailPage = true;
return null;
}
}
<apex:page standardController="Test__c" extensions="testListDetail" >
<apex:form >
<apex:pageBlock >
<apex:outputPanel rendered="{!Table}">
<apex:pageblockSection title="My Games" >
<apex:pageblockTable value="{!games}" var="g">
<apex:column headerValue="Name">
<apex:commandLink value="{!g.Name}" action="{!fetchDetail}" >
<apex:param assignTo="{!gameId}" name="{!g.Id}" value="{!g.Id}"/>
</apex:commandLink>
</apex:column>
</apex:pageblockTable>
</apex:pageblockSection>
</apex:outputPanel>
<apex:outputPanel rendered="{!DetailPage}">
<apex:pageblockSection title="My Game" id="detailSection">
<apex:pageBlockSectionItem >
Name: <apex:outputField value="{!game.Name}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Amount: <apex:outputField value="{!game.Number__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Stage: <apex:outputField value="{!game.Product_Support__c}"/>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>