In my VF page I have a form which uses map of a hardcoded custom object for some operations (Schema.Sobjecttype.object1_c.fields.getMap()).
Now I want to repeat this same form three times in the same page each time it takes a different custom object.
<apex:page>
<apex:repeat .... give the 3 custom objects in a loop>
<apex: form>
//form code
</apex:form>
</apex:repeat>
</apex:page>
The form code is done inside a controller. So I want to know if I can give a list of sobjects to loop through and if yes then how?
Why don't you make the form a visualforce component and use the object name as a parameter for the component. Then in the component controller, load the getMap() for that object and show in the component.
Related
I have a picklist in my custom object. I am creating a visualforce page where different templates need to be embedded. In main VF page, I am iterating this custom object list, where in I have to pass picklist value to this apex:include's attribute "pagename". And I have visualforce pages whose name is same as this pick list value.
Below is the sample codes that I have tried so far but had no luck :
Code 1 --
<apex:page renderAs="pdf" controller="MyCheckLayoutController">
<apex:repeat value="{!listwrapper}" var="cl" >
<apex:include pageName="{!cl.check_layout_type}" > // cl.check_layout_type is variable in wrapper class and it is the name of visualforce page as well.
/* This gives error as variable not found. */
</apex:include>
</apex:repeat>
</apex:page>
Code 2 --
<apex:page renderAs="pdf" controller="MyCheckLayoutController">
<apex:repeat value="{!listwrapper}" var="cl" >
<apex:variable var="type" value="{!cl.check_layout_type}" />
{!type} // This variable contains value
<apex:include pageName="{!type}" >
/* But It doesnot read it's value here. It says pagename cannot be null*/
</apex:include>
</apex:repeat>
</apex:page>
I have tried many ways till now. It would be really great help if some one could answer.
Thanks.
So I actually gave this a try and it looks like the page name needs to be defined in the VF page or must be bound to a getter that return a page ref or a property that has get attribute that returns a page ref. It looks like it cannot be bound to the variable in a repeater. Maybe you should try to see if Dynamic Components might do the trick
I have created a component which is related to display standard state and country picklists on custom objects.
I am having trouble to add that component to standard VF page.
Is there a way I can add a component to the VF page?
<apex:page standardController="Account">
This is my <i>page</i>. <br/>
<c:myComponent/>
</apex:page>
Replace <c:myComponent/> with <YourNameSpace:myComponent/> if component is defined in different namespace. See Docs
I'm new to Salesforce/Apex and I need to be able to test a component I am working on in a separate page.
Here is the scenario. I have the following test page:
<apex:page sidebar="false" showHeader="false" standardController="Contact">
<div id="wrapper" style="max-width:980px;">
<c:djEmailTemplate_MainComponent sObject="{!Contact}" theContactId="{!Contact.Id}"/>
</div>
</apex:page>
I can display the page by adding /apex/testpage to the url after the project name.
What I don't know how to do is to include data to satisfy the parameters (sObject, theContactId) that are needed to populate values in the component.
Can anyone explain how I can do this?
Thanks in advance.
Your test page uses the Contact object as its standard controller, so in most cases you would want to specify a Contact record for the page/controller to operate on. You can use any existing Contact record in your org, or create a new one (specifically you'll want to grab the ID of the record) and then append the ID to the URL you're using like so: /apex/testpage?id=003xxxxxxxxxxxx. This will provide the page and controller a record to pass to the VF component.
I am working with Apex controller and Visual Force page.
Inside of the vf page I had a data table and each row of that table binds to a value from a list that generated from the controller
example code:
<apex:dataTable value="{!List}" var="item" styleClass="class1" >
...
<apex:column headerValue="Header1">
<apex:outputpanel rendered="{!NOT((a=='true'))}">
<div class='estimate-name-column'>
<apex:inputField value="{!item.Name}" required='true' rendered="{!(a=='false')}"/>
</div>
</apex:outputpanel>
</apex:column>
...
</apex:datatable>
As you can see, I was trying to hide some inputFields base on some conditions.
However, there was a problem. If I do the above, those inputFields who get rendered were not binded correctly. After submited the form with this data table, inside my controller all the records' in list Name are null. Even though I saw the 'Name' was posted in http request.
I am guessing is render interfere with the binding? because if I remove the rerendered conditions and display all InputField I can get the values inside the controller after submitting form
any ideas what happened?
If I recall correctly an apex tag must be present on the page in order to be rerendered.
In other words - something (maybe as simple as <span id="long:generated:salesforce:id"></span>) must be in HTML in order for later AJAX updates to inject new content into the placeholder. If it's not rendered, it will stay not rendered.(1)
Instead of rendered try to move your condition to styleor styleclass attributes. Something like
<apex:inputField value="{!item.Name}"
required="{!a=='false'}"
style="display:{!IF(a=='false','inline', 'none')}"/>
visibility:hidden (if you want them to occupy their space but not be seen) or display:none (to have them appear to be completely not there. See also What is the difference between visibility:hidden and display:none?
Footnote:
(1) unless of course you'll rerender a tag that contains "this" tag (something higher in the XML).
How to hide a section of fields using a checkbox in visualforce pages?
Assuming the Salesforce approach (keeping the page weight down etc.), you could do something like the following:
<apex:inputCheckbox value="{!theBool}">
<apex:actionSupport event="onChange" action="{!myAction}" rerender="theFieldsPanel"/>
</apex>
<apex:outputPanel id="theFieldsPanel">
<apex:variable var="v" value="" rendered="{!theBool}">
<apex:inputField value="{!someField"} rendered/>
<!-- more fields etc. -->
</apex:variable>
</apex:outputPanel>
Note that I don't use the rendered attribute on the output panel itself, this is because if it's not rendered then it doesn't exist in the page, and as such, doesn't make for a good rerender target! Now you just require a simple action on the controller (you could do any other logic in here if need be):
public Pagereference myAction()
{
// any logic etc. goes here
return null;
}
The benefit of doing things this way, as opposed to with javascript is that you can ensure that if the fields are hidden then values won't be sent back to the controller for the variables they're bound to. Simply hiding things with javascript would not have the same effect, so say the user typed something in one of the fields and then hid them, whatever he/she typed would still end up in the related controller variables.