You need to sign in to do that
Don't have an account?

Can custom components get input from the user and return to the page?
I'm trying to build a page that is a multi-purpose search tool. The user makes a selection from a selectList (Account Search, Opportunity Search, etc.) which causes the appropriate component to render on the page. The component contains input fields so the user can type in search terms, click a Search button and then a third table component is displayed below with the search results. Sort of like the Advanced search combined with a List View.
My problem is, I can't figure out how to get a handle on the input text from the user, within the custom component. Apparently the custom components are instantiated separately from the main page and if I use the same controller, I get a new instance of the class. So I tried creating a new search object, instantiated from the main page, and then passed it to the component, using the input fields as the search object class variables. Again, the page has no idea that values on the search object have changed. It looks like once something is passed into a component, the link to the page is broken, and we have a new instance of "something." Are components completely passive?
In the example below, the inputFields render with the initial values '1234' fine. Then changing the value to '5678' and clicking an Update commandButton rerenders the fields, back to the original '1234'. So the searchObj isn't maintained between the component and the page. I've tried with simple text, custom classes, and last with a Product2. Any ideas?
My problem is, I can't figure out how to get a handle on the input text from the user, within the custom component. Apparently the custom components are instantiated separately from the main page and if I use the same controller, I get a new instance of the class. So I tried creating a new search object, instantiated from the main page, and then passed it to the component, using the input fields as the search object class variables. Again, the page has no idea that values on the search object have changed. It looks like once something is passed into a component, the link to the page is broken, and we have a new instance of "something." Are components completely passive?
In the example below, the inputFields render with the initial values '1234' fine. Then changing the value to '5678' and clicking an Update commandButton rerenders the fields, back to the original '1234'. So the searchObj isn't maintained between the component and the page. I've tried with simple text, custom classes, and last with a Product2. Any ideas?
Code:
Page: <apex:page id="thePage" standardController="Variable_Master__c" extensions="variableManagementController"> <c:productSearch id="psearch" searchObj="{!searchObj}"/> </apex:page> Component: <apex:component > <apex:attribute name="searchObj" description="Object to contain search terms." type="Product2"/> <apex:form id="search"> <apex:pageBlockSection title="Search" columns="1" collapsible="false" showHeader="false"> <apex:pageBlockSectionItem > <apex:outputLabel for="prodName" value="Product Name"/> <apex:inputText id="prodName" value="{!searchObj.Name}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel for="prodCode" value="Product Code"/> <apex:inputField id="prodCode" value="{!searchObj.ProductCode}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:form> </apex:component> Controller: public class variableManagementController { public Product2 searchObj { get; set; } public variableManagementController(ApexPages.StandardController controller) { this.sc = controller; this.searchObj = new Product2(Name='Test',ProductCode='1234'); } }
and the resultPanel component should be
Mark
Message Edited by MarkL on 12-08-2008 10:59 AM