You need to sign in to do that
Don't have an account?
Pass filter/id in URl to diplay products based on filter
Hi,
I have a Custome object which is a list of products that I am displaying in sites, I have a sub navigation menu that lists the products by category, I would like to pass the category selected as a variable so that the page that is linked to just filters from teh prodycts table based on the selection.
Am I correct in thinking I need an ID to do this and in that case I would need a master detail realtionship for my category rather than a picklist?
<apex:component controller="SoftwareDFListController"> <apex:repeat value="{!Software}" var="swdfItem"> <table id="swtable"> <tr><th colspan="2">{!swdfItem.Name} - {!swdfItem.Vendor__c}</th></tr> <tr><td class="odd">Vendor Description: </td><td><apex:outputText escape="false" value="{!swdfItem.Vendor_Description__c}"/></td></tr> <tr><td class="odd">Addtional Links: </td><td><apex:outputLink target="_blank" value="{!swdfItem.Vendor_Link__c}">Vendor Product Site</apex:outputLink></td></tr> </table> </apex:repeat> </apex:component>
:
ublic class SoftwareDFListController { public Software__c[] Software { get { return [SELECT Name, Category__c, Vendor_Description__c, Vendor__c, Vendor_Link__c FROM Software__c WHERE Category__c ='Product1' ORDER BY Name]; } } testmethod static void test() { SoftwareDFListController swdflc = new SoftwareDFListController(); Software__c[] items = swdflc.Software; } }
Here is my current controller I would like Category_c to be a variable can I pass the category names in a URL or do I need them to be an Id and in that case do I need to make Category it's own table / object as a lookup.
Thanks in advance.
Scott
<li><apex:outputLink value="{!$Site.Prefix}page?pageid=xxxxMAE">Product1</apex:outputLink></li> <li><apex:outputLink value="{!$Site.Prefix}page?pageid=xxxxMAE">Product2</apex:outputLink></li> <li><apex:outputLink value="{!$Site.Prefix}page?pageid=xxxxMAE">Product3</apex:outputLink></li>
Ah, I think I know what you are trying to do. You can actually pass in parameters to your component from your page using apex:attribute.
Create an variable name category in your component's controller
In your component, you add the following markup:
In your page, you can then pass in the category to the component like this:
All Answers
You don't need a master detail relationship to do what you want.
Using your current setup, you can use apex:param component to append parameter to the URI.
Here is an example:
Now your html output would look like the following:
Thanks that is awesome, and I just need to change the Controller to have a variable for Category rather than hardocded like I had it now?
It was nearly awesome, this returns everything in my Software Object based on what was hardcoded into the controller, in the page that gets linked to using the bottom part of the solution you wrote the HTML part I would like to then read that Category parameter in and have the displayed records filtered on that category.
In Apex, you can ask for the parameters from the URI using ApexPages.currentPage().getParameters(). You can then set that to a variable and pass that variable into your query statement.
Also, get and set functions are called multiple time during a request. It would be better to store your query result into a variable and return it, instead of performing a query every time.
An example would be the following:
Still can't seem to get this to work, is the <apex:param> tag you have described enough in my component? won't I need a CurrentPage.Parameters somewhere?
Is the controller complete as you currently have it do I need to get the value of Category e.g. Category=Product1 and then return Product1 for use in the variable? Also as they are String variables and contain spaces do I need to get the ' ' around the returned string?
I should have asked this earlier. How are you accessing the component?
Can you post an example of the page you would be using the component in? I can probably provide you a better solution if I know how they would be interacting with each other.
Hi,
Just putting the component in as per below, I can see how I can achieve this by making a component and controller for each category and just havinga page and inserting a component for each category but that seems like a long way around and I am not sure whether the will impact my Sites page access later
Sorry I am new to this just trying to get efficiency and I can't find any good examples anywhere the Sites documentation is very light on.
Thanks.
Ah, I think I know what you are trying to do. You can actually pass in parameters to your component from your page using apex:attribute.
Create an variable name category in your component's controller
In your component, you add the following markup:
In your page, you can then pass in the category to the component like this:
Thanks for your assistance and perseverance! That did the trick with a couple of minor adjustments
1) in the component <apex:attribute> "assignTo={!category}"
2) and you did say this in your reply..in the page used an expression <c:componentref category="{!$CurrentPage.parameters.Category}"
3) I did seem to have a minor issue when passing parameters that included spaces but using the the legal character for space seemed to fix it:
Thanks again I did fin some examples using the attribute but I couldn't find a complete example anywhere so was having trouble piecing it all together those 3 extra lines of code saved me a lot of time and trouble and implemented a really nice solution for me.