You need to sign in to do that
Don't have an account?
Placement of a related list in between the fields on a VisualForce Page
I have two custom objects:
SOO and DMOS with a Master Detail relationship between them.
SOO being the Master object.
I am creating a VisualForce page. I want to show some fields of SOO then the related list (DMOS) and then the remaining fields of the SOO object.
I tried to implement it as follows:
<apex:page standardController="SOO__c" > <apex:form > <apex:pageBlock > <apex:pageblockbuttons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!delete}" value="Delete"/> </apex:pageblockbuttons> <apex:pageblockSection title="SOO Detail" Columns="2" > <apex:inputField value="{! SOO__C.Name}"/> <apex:inputField value="{! SOO__C.OwnerId}"/> <apex:inputField value="{! SOO__C.Account__c}"/> <apex:inputField value="{! SOO__C.SSO_Date__c}"/> </apex:pageblockSection> </apex:pageBlock> </apex:form> <apex:relatedList List="DMOS__r" /> <div style="width:100%;text-align:right;font-size:200%;font-weight:bold;"> <apex:outputLabel value="Sky Score: " style="font-size:50%;font-weight:normal;"></apex:outputLabel> <apex:outputField value="{! SOO__C.SKY_Score__c}"/> </div> <apex:form > <apex:pageBlock > <apex:pageblockbuttons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!delete}" value="Delete"/> </apex:pageblockbuttons> <apex:pageblockSection title="SOO Detail Continued..." Columns="2" > <apex:inputField value="{! SOO__C.Objective__c}"/> <apex:inputField value="{! SOO__C.csi__c}"/> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
The problem with this approach is that I am getting two sets of save buttons one for each form. I have read that it is better to have a single form per page.
One more solution that I can think of is having a custom controller/extension to the standard controller with custom Save functionality.
Please let me know what is the best way to achieve this. The reason for customization is that I am trying to simulate an excel file that the customer was using and the customer wants everything to be looking similar to the excel.
Finally I could figure out the solution to my problem with the inputs from various users on the forums and previous posts.
I have posted a screenshot of the output page and the code Here
Complete code of the page:
All Answers
The single versus multi-form is more of a stylistic/understanding thing now. The problem used to be multiple copies of the Viewstate, one per form, but Visualforce handles this now. That said, there's no reason to have two forms that I can see.
The copies of the buttons are being produced by the pageblockbuttons components - by default they put buttons at the top and bottom of the page block. If you set the location attribute you can have one set of buttons at the top of the page and another at the bottom - see the underlined attributes below:
Hi Bob, Thanks for the reply.
There are two problems:
1. I cannot nest the "<apex:relatedList />" tag within a "<apex:form>" tag. This is the reason why I had to go for the below mentioned arrangement.
2. As per your suggestion I can use location="top / bottom" attributes with pageBlockButtons but the problem that I run into is that the buttons save only the fields mentioned in their respective forms.
e.g. buttons placed in from1 save the fields placed in form1 only.
Finally I could figure out the solution to my problem with the inputs from various users on the forums and previous posts.
I have posted a screenshot of the output page and the code Here
Complete code of the page: