use varaible in one viusualforce page from another - salesforce

I have two visualforce pages (ParentPage and ChildPage) and one page include other. On ChildPage declared some variable which I want to use in ParentPage. Is it posible?
<apex:page id="ChildPage">
<apex:variable var="isRegistered" value="true"/>
</apex:page>
<apex:page id="ParentPage">
<apex:include pageName="childPage"/>
????? how to use variable "isRegistered"
</apex:page>

You can pass variable value as a parameter in iFrame url. If you are resetting the value in parent page than re-render the section.

Related

Pass one of the list field value to pagename attribute for a apex:include tag

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

How to add a visualforce page to the end of existing page according to a condition?

Suppose we have a custom salesforce controller and a custom visualforce page for it. at the end of the visualforce page I like to evaluate a public member variable of the controller and if it is true I like to add the contents of another visualforce page (e.g. apex/test) to the first page.
<apex:page controller="mycontroller">
...........
my tags and page contents comes here
...........
{!if(my_member_variable == true, attach contents of "apex/test" page to end of this page, "do nothing")}
</apex:page>
How can I do that?
In simple words, I am searching for a command similar to include() on PHP for visualforce.
Thanks,
Sounds like you want to use an apex:include along with its rendered attribute.
<apex:page controller="mycontroller">
<!-- ... -->
<apex:include pageName="TheNameOfTheIncludedPage" rendered="{!my_member_variable}"/>
</apex:page>
Incidentally. The salesforce.stackExchange.com is a great place to ask Salesforce specific questions.

apex:inputField Binding Value not updated

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).

Repeat a form and passing it custom objects

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.

How to hide a section of fields using a checkbox?

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.

Resources