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.
Related
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.
Lets say i have an inline VF page
Code Snippet
<apex:page>
<apex:pageBlockTable value="{!tempList}" var="c" width="100%" columns="11">
<apex:column value="{!c.OwnerId}" headerValue="Case Owner">
</apex:column>
</apex:pageBlocktable>
</apex:page>
From the contrioller i get the tempList (List created on Case).
Now in the inline VF page i want to remove the hyper link for the case owner name that got displayed in my page.
Any Thoughts ?
<apex:column value="{!c.Owner.Name}" headerValue="Case Owner" />
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;
}
}
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!!
So, Say I have the following visualforce page:
<table width="100%" border="0">
<tr>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!contacts}" var="contact">
<apex:column >
<apex:facet name="header">
email
</apex:facet>
<apex:outputField value="{!contact.email}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
Name
</apex:facet>
<apex:commandLink reRender="detail">{!contact.name}
<apex:param name="id" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</td>
</tr>
</table>
and the following corresponding controller:
public List<Contact> contacts = [SELECT name, division, email FROM Contact];
Say I want to break up this table on division (i.e, when there is a new division, I would like a header to be placed in the table that reads the division name, and then the names and emails of all contacts within that division to appear under the header... similar ot this:
[ Division 1 ]
Email Name
.... ...
... ...
... ...
[ Division 2 ]
Email Name
... ...
[ Division 3 ]
Email Name
... ...
etc...
Is there a way to do this inline in the apex pageblock? Or would I have to make a unique pageblock for each division?
Does anyone have an alternate approach I could take to solve this problem?
It would be much, much easier if your "Division" (custom field?) would be a lookup to a separate object. That's what relationships in Salesforce and this weird syntax in SOQL is there for. You could simply use a subquery and 2 loops:
[SELECT Name, (SELECT Id, Name, Email FROM Contacts__r) FROM Division__c]
which is similar to
[SELECT Name, (SELECT Id, Name, Email FROM Contacts) FROM Account]
But I suspect it's a text/picklist field... Then - roughly speaking something like this:
Put results of your select into buckets, 1 bucket for each division
Optionally sort the bucket names (alphabetically?)
In VF - use 2 loops, 1 on buckets, 2nd on the bucket content (it's OK if the 2nd loop will be <apex:pageBlockTable> and not strictly <apex:repeat> etc.)
Sample (untested!)
// 1
Map<String, List<Contact>> contactsByDiv = new Map<String, List<Contact>>();
for(Contact c: [SELECT Id, Name, Email, Division__c FROM Contact]){
List<Contact> contactsInThisDiv = contactsByDiv.get(c.Division__c);
if(contactsInThisDiv.isEmpty()){
contactsInThisDiv = new List<Contact>{c};
} else {
contactsInThisDiv.add(c);
}
contactsByDiv.put(c.Division__c, contactsInThisDiv);
}
// 2
List<String> allDivisions = new List<String>();
allDivisions.addAll(contactsByDiv.keyset());
// I've selected a List to store the Div names because sets are unpredictable. List is easier to sort if you'd want it to
// allDivisions.sort();
<!-- 3 - in VF page -->
<apex:repeat value="{!allDivisions}" var="i">
<h1>{!i}</h1>
<apex:pageBlockTable value="{!contactsByDiv[i]}" var="c">
<apex:column value="{!c.Email}" />
</apex:pageBlockTable>
</apex:repeat>
public List<Contact> contacts = [SELECT name, division, email FROM Contact order by division];
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
<apex:form >
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!contacts}" var="contact">
<apex:column headerValue="email" >
<apex:outputField value="{!contact.email}"/>
<span Class="divisionName" division="{!contact.division}"/>
</apex:column>
<apex:column headerValue="Name" >
<apex:commandLink reRender="detail">{!contact.name}
<apex:param name="id" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<script>
var previous= $('<tr class="myHeaderRow"><td colspan="2">'+''+'</td></tr>') ;
$('.divisionName').each(
function(index, value){
if( $(value).attr('division')!=previous.text()){
$(this).closest('tr').before('<tr style="height: 10px !important;" class="myHeaderRow"><td colspan="2" style="text-align: -webkit-center;">'+$(value).attr('division')+'</td></tr>');
previous = $(this);
}
}
);
</script>
</apex:form>