In Visualforce, Does "rendered" reexecutes after "reRender" refreshes a section? - salesforce

I am trying to hide the section 'searchCriteria' when 'Edit' link is clicked. The hiding is done in Controller 'editSearchResult()' method using 'pageLoad' variable.
The 'pageLoad' is used in 'searchCriteria' section with rendered attribute. But, the section is not refreshing with updated values from Controller when Edit link is clicked.
But if I remove 'rendered' attribute on the section 'searchCriteria', system refreshes the section with updated values from Controller. Can anyone explain how 'rendered' handles display?
Visualforce Code:
<apex:page controller="RerenderDemoController">
<apex:form id="thisForm">
<apex:outputPanel id="searchCriteria" rendered="{!pageLoad}">
<apex:pageBlock>
<apex:pageBlockSection>
This is Search Criteria Section. Page Load: {!pageLoad},
User: <apex:outputText value="{!userName}">
</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
<apex:outputPanel id="searchResults">
<apex:pageBlock>
<apex:pageBlockSection>
This is Search Results Section. {!accts}
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
<apex:outputPanel id="EditResult">
<apex:pageBlock>
<apex:pageBlockSection>
This is Edit Result Section.
<apex:commandLink action="{!editSearchResult}" reRender="searchCriteria">Edit</apex:commandLink>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
Apex Controller:
public class RerenderDemoController {
public List<Account> accts {get; set;}
public Boolean pageLoad {get; set;}
public String userName {get; set;}
public RerenderDemoController() {
pageLoad = true;
userName = 'My First Name';
accts = [select id, name from Account limit 10];
}
public void editSearchResult() {
pageLoad = false;
accts = [select id, name from Account limit 20];
userName = 'My Last Name';
}
}

What you can do is, wrap your outputPanel with another outputPanel
<apex:outputPanel id="searchCriteria">
<apex:outputPanel rendered="{!pageLoad}">
<apex:pageBlock>
<apex:pageBlockSection>
This is Search Criteria Section. Page Load: {!pageLoad},
User: <apex:outputText value="{!userName}">
</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:outputPanel>
Hope, this will solve your issue.

You can use JQuery to Hide the content just use html class and use [jquery]:https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
and use $('.classname').hide();
hope it helps you.

Related

Why can't display some columns in public site of salesforce?

This is full code:
Controller:
public class TestController {
public List<MyProduct__c> MyProducts {get;set;}
public string searchstring {
get{
if (searchstring==null) searchstring = '';
return searchstring;
}
set;}
public TestController()
{
search();
}
public void search(){
string searchquery='select Product_Code__c,name,price__c,imagename__c from MyProduct__c where name like \'%'+searchstring+'%\' Limit 20';
MyProducts= Database.query(searchquery);
}
}
Home Page is a visualforce page:
<apex:page controller="TestController" >
<apex:form >
<div align="center">
<apex:inputText style="width: 360px; height: 25px" value="{!searchstring}" label="Input"/>
<apex:commandButton value="Search" action="{!search}" />
</div>
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!MyProducts}" var="a">
<apex:column >
<apex:image width="100" height="100" value="{!URLFOR($Resource.ProductImage, 'ProductImage/' & a.ImageName__c)}"></apex:image>
</apex:column>
<apex:column value="{!a.ImageName__c}"/>
<apex:column value="{!a.Product_Code__c}"/>
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Price__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Result when click Preview from Developer Console:
It display 4 columns and image view ok.
But if Run from a public site and not login salesforce:
It only display 2 columns:
Why can't display 2 columns(ImageName__c,Price__c) in public site?
It might have to do with permissions.
Visualforce is a framework that enforces Salesforce's security measures directly, so if the user which is accessing the Visualforce page does not have permission to see a certain field, it will not render it.
I would suggest you check profiles/permission sets and verify that the user accessing the page has enough access.

Passing values to nested apex page for editing

I have an apex page with custom extension. I am using pageblocktable to show all available records. Table has modify button, on click of button I am showing another nested apex page in a javascript dialog. Question is how to pass pageblocktable row values to nested page for editing purpose?
You can share same controller for both pages.
Page1:
<apex:page standardcontroller="Object__c" extensions="MyController">
<apex:column headerValue="Action">
<apex:commandLink action="{!goToPage2}" value="Edit" >
<apex:param name="rowId" assignTo="{!rowId}" value="{!item.Component.Id}" />
</apex:commandLink>
</apex:column>
</apex:page>
Page2:
<apex:page standardcontroller="Object__c" extensions="MyController">
{!objForPage2.Name}
</apex:page>
Controller:
public with sharing class MyController{
public string rowId {get;set;}
Object__c objForPage2;
public Pagereference goToPage2(){
for(Object__c obj : objectList){
if(obj.Id==rowId){
objForPage2= obj;
}
}
return Page.Page2;
}
}

reRender and rendered attribute in visualforce

i write a visualforce page with source code
<apex:page controller="MyController1">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="search">
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanel" id="theCommandLink"/>
<apex:outputPanel id="thePanelWrapper">
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and the MyController1 class is
public class MyController1{
public Boolean rend{get;set;}
public PageReference commandLinkAction(){
rend=true;
return null;
}
}
when i click on Advanced Search link nothing happens but i was expecting outputPanel with id "thePanel" should render.why it is not rendering please someone explain??
In moment that you click on the link the panel not on the page, SF not rendered it.
As #Shimshon said, when the HTML code is generated from Visualforce, the Visualforce components marked as rendered="false" are not displayed in the resulting HTML document.
In this case:
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">
if you are going to rerender this panel, then you must ensure that the component will be displayed in the HTML code so the rerender action can find it. Since {! rend} is initially set to false in the controller's constructor "thePanel" is never rendered in the page, thus you try to rerender a component that does not exist.
#theGreatDanton 's solution will work because <apex:outputPanel id="thePanelWrapper"> is the container panel that is always rendered:
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanelWrapper" id="theCommandLink"/>
and if this panel is pointed by rerender attribute, then "thePanelWrapper" and their child nodes ("thePanel") will be updated.
try the below code.
<apex:page controller="MyController1">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="search">
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanelWrapper" id="theCommandLink"/>
<apex:outputPanel id="thePanelWrapper">
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class MyController1{
public Boolean rend{get;set;}
//setting the boolean to false in the constructor
public MyController1(){
rend = false;
}
public void commandLinkAction(){
rend=true;
// return null;
}
}
Hope this helps!!

parameter value null is redirected to url

Hi i am writing a simple controller class with code
public class OMTime1 {
public String xx { get; set; }
public PageReference continue1(){
String url='/apex/OneMoreTime?id='+ApexPages.currentPage().getParameters().get('id')+'&process='+xx;
PageReference page=new PageReference(url);
page.setRedirect(true);
return page;
}
}
and a simple VF Page with code
<apex:page controller="OMTime1" >
<!-- Begin Default Content REMOVE THIS -->
<!-- End Default Content REMOVE THIS -->
<apex:form >
<apex:selectList id="chooseColor" value="{!xx}" size="1">
<apex:selectOption itemValue="1" itemLabel="Terminate Resource"/>
<apex:selectOption itemValue="2"
itemLabel="Change Resource Position at Same Location"/>
<apex:selectOption itemValue="3" itemLabel="Change Resource Position with in same Location "/>
<apex:selectOption itemValue="4" itemLabel="Change Resource Position to a Different Location"/>
</apex:selectList>
</apex:form>
<apex:form >
<apex:commandButton value="Continue" action="{!continue1}" id="theButton"/>
</apex:form>
</apex:page>
my task s when user click on button name as Continue page will redirect to it a url /apex/OneMoreTime?id=record_id&process=some_value
some_value=1,2,3, or 4
but when i click on button it redirect to /apex/OneMoreTime?id=record_id&process=null
why this null is coming in parameter i want to redirect a value related to label of select option.please suggest way how to resolve it
Short answer: because <apex:commandButton> is broken ;)
Recently I've posted an explanation of 2 most common workarounds on Salesforce-dedicated stackexchange site: https://salesforce.stackexchange.com/questions/4937/command-button-vs-command-link
Use an <apex:commandLink styleClass="btn"> and it will work while looking almost the same as button.

display records based on selection of name from picklist in salesforce

I am trying to get my hands on learning Visual force.
I have an object inv_c which holds invoice records and another object item_c
I have in my VF page a picklist with the object names.
If user selects inv_c then all records of inv_c are displayed if user selects item__c all records of item are displayed
Is there any way where the list would be displayed on the completion of the selection or do we have to have button to get it.
how can i achieve this in VF? any small code snippet would be wonderful
Thanks
You can do this using a JavaScript onchange event with the help of the ActionSupport Visualforce Component. Here's an example.
<!-- Page: -->
<apex:page controller="exampleCon">
<apex:form>
<apex:outputpanel id="counter">
<apex:outputText value="Click Me!: {!count}"/>
<apex:actionSupport event="onclick"
action="{!incrementCounter}"
rerender="counter" status="counterStatus"/>
</apex:outputpanel>
<apex:actionStatus id="counterStatus"
startText=" (incrementing...)"
stopText=" (done)"/>
</apex:form>
</apex:page>
/*** Controller: ***/
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
In your case the actionSupport component would be a child of your selectRadio component i.e.
<apex:selectRadio value="{!selection}">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" .... />
</apex:selectRadio>

Resources