I'm trying to capture the selected tab in my controller. I have the below code and it works fine if I leave in the alert message in the script. Once I remove the alert it no longer seems to make the call to the controller. I'm only displaying one tab in the code snippet. I have 3 others defined.
<apex:page showheader="true" sidebar="true" controller="mycontroller">
<script>
function setActiveTabJava(value){
alert('here');
setActiveTab(value);
}
</script>
<apex:form >
<apex:actionFunction id="activeTab" name="setActiveTab" action="{!setTab}" reRender="">
<apex:param name="activeTab" assignTo="{!activeTab}" value=""/>
</apex:actionFunction>
</apex:form>
<apex:pageblock >
<apex:tabpanel selectedtab="Tab One" width="100%">
<apex:tab label="This is tab one" name="tabone" id="referralTab" ontabenter="setActTabJava('TAB1');">
<!-- other tab code-->
</apex:tab>
</apex:tabpanel>
</apex:pageblock>
I basically fixed this by using the value attribute on the tab panel. Since my controller only interested in know which tab was selected, and not when the tab was selected it worked. Basically:
<apex:tabpanel value="{!activeTab}">
<apex:tab name="tab1">...</apex:Tab>
So whenever a tab is changed, as long as you've specified a name attribute on the tab it will be accessible in your controller.
So sorry I no longer have that controller code to post but it was basically just a method that set a variable in the controller.
Related
I want to create a button that effectively does the same thing as "ctrl r"
After my end user finishes updating info in the visualforce page. I want to give them to option to click this button and it will refresh the entire record page which the visualforce is embedded onto.
I honestly have no idea how to do this, my coding experience is limited. The only thing i've been able to do is get the page to reload within the visualforce page and that's not very helpful.
This is what I tried:
Visualforce code:
<apex:page standardController="Request__c" extensions="ActionRelatedList">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="Reload" action="{!redirect}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Redirect method:
public PageReference redirect() {
String requestURL ='URL';
PageReference newRequestURL = new PageReference(requestURL);
newRequestURL.setRedirect(true);
return newRequestURL;
}
But this doesn't refresh my entire page, it just opens it within the visualforce page.
You can do this using code below:
<apex:page standardController="Account" >
<apex:form >
<apex:pageBlock>
<apex:commandButton value="Reload" onclick="window.top.location='/{!Account.id}'; "/>
</apex:pageBlock>
</apex:form>
</apex:page>
I have custom validation rules defined on my custom employee__c object in salesforce. I use a standard controller visualforce page with custom extension to show a UI to the user for data entry. My challenge is to show the validation rule error to the user in an easy to read manner. Here is the part of the code that I have.
Visualforce
<apex:page standardController="Employee__c" extensions="EmployeeExtension" sidebar="false">
<apex:sectionHeader ...
<apex:form id=fr>
<apex:pageMessages id="errMsg"/>
<apex:pageBlock title="Employee Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!mySave}" value="Save" reRender="errMsg"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
....
</apex:form>
</apex:page>
Apex Controller
public class EmployeeExtension {
....
public PageReference mySave(){
....
try{
upsert empList;
} catch (DMLException ex) {
ApexPages.addMessages(ex);
}
}
}
This shows the errors at the page top which is the way I want, but it shows twice. Here is how it will display the error at page top.
error_message_from_custom_validation_comes_here
TriggerEmployee: Exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, error_message_from_custom_validation_comes_here
In my entire controller I do not have any other DML operations nor do I use ApexPages.addmessage any where else. The strange thing is if I remove
ApexPages.addMessages(ex);
while keeping the try catch block as is, then I see only
error_message_from_custom_validation_comes_here
I wonder why it shows the page messages in vf page even when I am not sending anything from controller. I appreciate all your responses, but I would like to see solutions not involving javascript or jquery.
You can use this:
ApexPages.addMessage(
new ApexPages.Message(
ApexPages.severity.ERROR,
ex.getMessage()
)
);
Alternatively you could also imitate the standardController:
public class EmployeeExtension {
....
public PageReference mySave(){
/* do your thing */
return this.standardController.save();
}
}
This way you return the page reference of the save which is the standard behaviour (if you want to imitate this) and if there is a validation error it will show up in the tag and only the nice formatted message will show up.
You don't need a reRender on the save:
<apex:page standardController="Employee__c" extensions="EmployeeExtension" sidebar="false">
<apex:sectionHeader ...
<apex:form id=fr>
<apex:pageMessages/>
<apex:pageBlock title="Employee Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!mySave}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
....
</apex:form>
</apex:page>
Salesforce/Visualforce will do the rest for you :)
i want to display a report on a visualforce page. I found this snippet of code but it brings back a blank page. What piece am i missing to have it show the report data?
<apex:page showHeader="false" sidebar="false">
<apex:iframe src="/00OQ0000000Gdbm"/>
</apex:page>
I use code that looks like this to show a report in a Visualforce page. I've left out details that would get in the way:
<apex:page standardController="CustomOb__c" extensions="CobjController">
<apex:sectionHeader title="Manage Stuff"/>
<apex:form>
...
<apex:outputPanel id="MissingAttRpt" >
<apex:iframe src="/00O0000000AAJlV?isdtp=lt" scrolling="true" height="1588px" width="100%"/>
</apex:outputPanel>
...
</apex:form>
</apex:page>
The outputPanel is used so that the report can be re-rendered without refreshing the whole page.
Try getting rid of the showHeader and sidebar properties.
<apex:pageBlock >
<apex:selectList id="fields" value="{! xxx}" multiselect="true" size="3" rendered="{! FieldRendering}">
<apex:selectOptions value="{!items}"/>
<!-- Search content -->
<apex:actionSupport event="onchange" reRender="srcResultPanel" action="{!find}"/>
</apex:selectList>
the select list is not rendering when FieldRendering attribute is true for sure but when i remove rendered attribute then its showing selectList and rerendering selectoptions properly can any one please tell how to fix it in starting FieldRendering attribute is false but after clicking a button it is true but it is not rendering after clicking the button why please explain and suggest how to fix it ??
The thing is if a tag is not meeting rendered criteria when the page loads it doesn't present in page so can't be rerendered. A viable solution is to wrap target tag in outputPanel and rerender It( the outputPanel tag).
I have a commandButton in a visualforce component. The expected behavior is that the controller method would be called. The page is refreshed, but the method registered in the commandButton {!performUnlinkContact} is not called. The strange thing is that if I put the button on the base visualforce page, it calls the controller method as expected - but when in a component, it does not.
Here is my component:
<apex:component >
<apex:attribute name="rk" description="RK Base Contact Data" type="Object" required="true"/>
<div class="unlinkBox">
<div class="unlinkHeader">
<div class="unlinkHeaderLeft">Wrong Contact?</div>
<div class="unlinkHeaderRight"><apex:image style="cursor: pointer;" value="{!$Resource.x}" alt="Close Panel" /></div>
</div>
<div class="unlinkBody">
<div class="unlinkBodyLeft">
Click Yes if the Contact displayed is incorrect.<br/><br/>You will be given the opportunity to link to a different Contact.
</div>
<div class="unlinkBodyRight">
<apex:outputpanel id="callMethod">
<apex:commandbutton value="Yes, this is the wrong contact" action="{!performUnlinkContact}" rerender="" status="myDisplayStatus" /> <a onclick="return hideUnlinkPanel()" style="color:blue;cursor:pointer;text-decoration:underline">No</a>
</apex:outputpanel>
<apex:actionStatus id="myDisplayStatus" startText="(performing Contact Unlink...)" stopText=""/>
</div>
</div>
</div>
</apex:component>
and here is the method in the controller extension:
public PageReference performUnlinkContact() {
System.debug('==================================!!performUnlink');
if (this.thisLead.rkContactId__c != 0) {
this.thisLead.rkContactId__c = 0;
update this.thisLead;
}
return null;
}
I'm sure I must be doing something wrong since I am new to salesforce and still learning, but I am unable to find any related issues when I search on how to resolve this issue. Thanks in advance for the help.
Thanks for the replies - to resolve I ended up adding an actionFunction to the base Page, then just calling this function in the component via a button's onclick event:
Code in base page:
<apex:actionFunction name="doUnlink" action="{!performUnlinkContact}" rerender="refresh" status="myStatus"/>
Code to call function in the component:
<input type="button" value="Yes, this is the wrong contact" onclick="doUnlink();" />
This method seems to work well so far.
You can also pass a reference of performUnlinkContact() to the component, using an apex:attribute of type ApexPages.Action, and then when your commandButton uses this reference, it will call the method defined in the page controller.
<apex:component>
<apex:attribute name="performUnlinkContact" type="ApexPages.Action" description="Passing method from controller"/>
<!-- your stuff here -->
</apex:component>
Then when you use your component, you have to populate that attribute like so:
<c:MyComponent performUnlinkContact="{!performUnlinkContact}"
I think rerender="" is not a way to do a fake reRender command. I would try it with rerender="none".