# How to use page reference and rendered simultaneously?

Hello, everyone! I am developing a website on Salesforce. And I have some pages redirections along with usage of rendered. In particular, I have a home page where products divided by categories are hidden in blocks, which are rerendered after we choose category reference. And I have some page which lists all products - Products page. It should by click on the category (it is sidebar) redirect to a home page and rerender block for the specific category. Is that possible to use page reference and rendered simultaneously? By the way, I have custom Product object with fields like Name, Description__c, Price__c, Quantity__c and Category__c (TV, Laptop. Mobile phone, Monitor). Your help will be appreciated!!

  <div class="main">
<apex:form id="monitorsForm" rendered="{!renderMonitor}">
<apex:outputPanel id="monitorsDetail">
<apex:pageBlock title="Monitors" id="monitorsBlock">
<br/>
<apex:pageBlockTable value="{!monitorsList}" var="monitor">
<apex:column >
<apex:param name="id" value="{!monitor.Id}"/>
<apex:pageBlockSection >
<apex:image value="{!URLFOR(\$Resource.Monitor, monitorsImages[monitor.Name])}" width="600" height="400" id="monitorImage"/>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:outputText value="{!monitor.Price__c}" id="monitorPrice"/><br/>
<apex:outputText value="{!monitor.Description__c}"/>
</apex:pageBlockSection>
<br/>
<apex:param name="itemsId" value="{!monitor.Id}" assignTo="{!chosenItemId}"></apex:param>
</apex:commandButton>
<br/><br/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockSection >
<apex:outputText value="There are {!monitorsQuantity} products in this category" id="productsNumber"/><br/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</div>


This is sidebar for categories in Products page:

   <div class="sidebar">
<apex:form id="categories">
<apex:pageblock title="Categories" id="blockA">
<br/>
<br/>
<br/>
</apex:pageblock>
</apex:form>
</div>


And some code from controller for redirection to some category:

public PageReference redirectProductPage(){
if (currentPage == null) {
PageReference pageRef = new PageReference('/apex/ProductsPage');
pageRef.setRedirect(true);
return pageRef;
} else {
return null;
}
}

public PageReference redirectMonitorsFromHome() {
redirectProductPage();
renderMonitor = true;
renderTV = false;
renderLaptop = false;
renderMobile = false;
renderShoppingCart = false;
return null;
}

• Have you tried reRendering monitorsForm on your <apex:commandButton>? Until you re-render that panel, I'd expect the rendered state of monitorsForm to always be set to the value it was initialised with. – Dan Jones Mar 8 '17 at 17:20
• @DanJones which button exactly do you mean? – Cassie Mar 8 '17 at 17:26
• Scratch that. On your <apex:commandLink action="{!redirectMonitorsFromHome}, you're not reRendering monitorsForm, or anything for that matter, so it's maintaining whatever it was set to beforehand. If the sidebar is a Visualforce Component and was literally taking you from Page A to Page B as implied in your question, you'd probably need to set a parameter in the URL and check what should be displayed based on that. company.my.salesforce.com/apex/myPage?foo=bar&hello=world, something like that. – Dan Jones Mar 8 '17 at 17:39