Visualforce rendered attribute is not working as expected - salesforce

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

Related

AngularJS validations popup on page load in firefox

I have used angularJS validations like ng-required and ng-minLength and show them if $touched and $invalid true. I have used UI-route to show different page in slides(using ngAnimate) on a single page. When we click the button to move on next slide it show the validation message pop-up of next page as shown in image. It shows the validation message popup on page load. I have used novalidate on form tag and formnovalidate on button but not working at all.
<input type="email" class="form-control" placeholder="Email" ng-model="registration.email"
name="email" ng-required="true" ng-class="{errorField: (personalInfoForm.email.$invalid
&& personalInfoForm.email.$touched) || isEmailError}" ng-blur="validateUserNameAvailability()"
ng-pattern ="emailPattern" />
<div class="errorTooltip" ng-show="isEmailError">{{emailError}}</div>
<div ng-show="personalInfoForm.email.$invalid && personalInfoForm.email.$touched && !isEmailError">
<div ng-show="personalInfoForm.email.$error.required" class="errorTooltip">
{!$Label.Text_You_Must_Enter_A_Value}
</div>
<div ng-show="personalInfoForm.email.$error.email || personalInfoForm.email.$error.pattern" class="errorTooltip">
{!$Label.Text_Please_Enter_Valid_Email}
</div>
</div>
Please post you complete code for the form but from your description of the issue i'm guessing the button type used on the "Next" button to go to the next slide must be
<input type="submit">Next</input>
change it to button.
<input type="button">Next</input>
You must have used a common form tag for all the slides and submit the form at the end of the last slide to save the data. But by using the button type as submit on the Next button the form is getting submitted at the end of each slide. Let me know if my analysis was correct.
I have found fix for this issue. Firefox load angularJS slow therefore it show all validation message on page load and later hide them.
I have added one css line in starting of page that added to ui-view.
<style>.first-page{ display: none; }</style>
I have removed this css in the end of page.
<script>$('.first-page').css('display','block');</script>
I have applied this class 'first-page' on main div of page.
This resolve my issue. Now all pages loaded in ui-view component perfectly.
Note: This also resolve the content override issue on slide animation. Firefox load angular animation slow. I have hide the page till its load completely. This resolve all firefox issues.

ActionFunction won't call controller function without Alert Message

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.

Display report in visualforce page

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:commandButton in visualforce component does not call controller method

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

VisualForce - conditional html tags

I am trying to apply a different style to the first element in a list.
I am currently attempting to use a counter to apply the li with a class only when cnt==0 but I cannot include < > brackets in an OutputText tag. Is there any way to escape the brackets or insert the class into an <li> tag using a condition?
I know this could be done after the fact using JavaScript but I'd rather avoid it.
<apex:variable var="cnt" value="{!0}" />
<apex:repeat value="{!items}" var="item" >
<!-- only render the class if it is the first element -->
<apex:OutputText value="<li class="activeLI">" rendered="{!cnt==0}" />
<apex:OutputText value="<li>" rendered="{!cnt!=0}" />
<img src="{!$Resource[item.Image__c]}" width="85" height="90"/>
</li>
<apex:variable var="cnt" value="{!cnt+1}"/>
</apex:repeat>
Visualforce is strict, every element must have an opening and closing tag or must be self-closing. When compiled, Visualforce will complain as it will only see the closing "li" tag and not the conditional opening "li" tag, one solution is to make the class name a variable as follows:
<apex:variable var="cnt" value="{!0}" />
<apex:variable var="class" value=""/>
<apex:repeat value="{!items}" var="item" >
<apex:variable var="class" value="activeLI" rendered="{!cnt==0}"/>
<apex:variable var="class" value="" rendered="{!cnt!=0}"/>
<li class="{!class}">
...
</li>
<apex:variable var="cnt" value="{!cnt+1}"/>
</apex:repeat>
Have you consider using a CSS selector? Here's an example on how to style the first element of a list.
<style>
ul.myList > li:first-child {color : red}
</style>
<ul class="myList">
<li>this is red</li>
<li>this has default formatting</li>
</ul>
Have you considered using <apex:dataList>? I think it may accomplish what you're looking to do.

Resources