Design code for Books page:
By default the PageBlockTable displays its value as OutputLabel but we need to click the value for navigation purpose. So here i used <apex:commandLink> to convert it as Link. Book name is passed as parameter using <apex:param>
<apex:page controller="BooksController"> <apex:form > <apex:sectionHeader subtitle="All Books" title="Books"/> <apex:pageBlock > <apex:pageBlockTable value="{!allbooks}" var="a"> <apex:column headervalue="Name"> <apex:commandLink value="{!a.Name}" action="/apex/SelectedBook?id={!a.Name}"> <apex:param name="id" value="{!a.Name}"/> </apex:commandLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Apex Code for Books page controller:
Here the getAllBooks fuction retrive the values from the Book__c custom objects and bind it to the PageBlockTable
public class BooksController { public List<Book__c> allbooks; public List<Book__c> getAllBooks() { if(allbooks==null) { allbooks=[SELECT Name,Book_Author__c,Book_ISBN__c from Book__c]; } return allbooks; } }
Apex Code for SelectedBook page controller:
Here in the constructor the parameter value is retrieved using its name. Using that value the getSbook function gets the specific book details and bind it to the PageBlockTable.
public class SelectedBookController { public String selectedName {get;set;} public Book__c sbook; public SelectedBookController() { sbook=new Book__c(); selectedName = ApexPages.currentPage().getParameters().get('id'); } public Book__c getSbook() { sbook=[Select Name,Book_ISBN__c,Book_Author__c from Book__c where Name=:selectedName]; return sbook; } }
Design code for SelectedBook page:
<apex:page controller="SelectedBookController"> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!sbook}" var="b"> <apex:column value="{!b.Name}"/> <apex:column value="{!b.Book_Author__c }"/> <apex:column value="{!b.Book_ISBN__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
No comments:
Post a Comment