You need to sign in to do that
Don't have an account?
Custom component popup - bug hunters needed!
I am trying to develop a custom component that will search on any field on an object, and I would like to do it without using any java code. I am really close. I've used a VF popup based on code from TehNrd and managed to get the component controller and the VF page controller talking to each other. The issue I am having is with the selectoption on the popup. It is being populated with a string array passed into the custom component. When I do the AssignTo="{!myList}" in the attribute, the go button and the close button on the popup work fine. When I do the assignto, they don't work. Any thoughts?
Custom Component
<apex:component controller="searchcomponentcontroller" > <apex:attribute name="pageController" type="PageControllerBase" assignTo="{!pageController}" required="true" description="The controller for the page." /> <apex:attribute description="" name="label" type="String" required="true"/> <apex:attribute description="" name="Searchby" type="String[]" required="true" AssignTo="{!myList}" /> <apex:outputlabel for="intxt" value="{!label}"/> <apex:inputtext id="intxt" value="{!initValue}"/> <img id="imglead" src="/s.gif" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onClick="showPopup()"></img> <apex:actionfunction name="showPopup" action="{!showpopup}" rerender="popup"/> <apex:outputPanel id="popup"> <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}"> <div align="Right"><apex:commandButton value="X" action="{!closepopup}" rerender="popup"/></div> <apex:sectionHeader title="Lookup" /><br/> <apex:outputPanel id="searchmaterial" layout="block" rendered="true"> <apex:outputLabel value="Search: " for="txtsearch" StyleClass="labelCol"/> <apex:inputText value="{!searchtext}" id="txtsearch"/> <apex:outputlabel for="Options" Value=" by: "/> <apex:selectList id="Options" value="{!selectedOption}" size="1" > <apex:selectOptions value="{!Options}" /> </apex:selectList> <apex:Commandbutton Value="Go" action="{!updateValue}" /> <div style="overflow:auto; width:?px; height:?px"><br/> </div> </apex:outputPanel> </apex:outputPanel> </apex:outputPanel> <style type="text/css"> .customPopup{ background-color: white; border-style: solid; border-width: 2px; left: 50%; padding:10px; position: absolute; z-index: 9999; /* These are the 3 css properties you will need to tweak so the pop up displays in the center of the screen. First set the width. Then set margin-left to negative half of what the width is. You can also add the height property for a fixed size pop up.*/ width: 800px; height: 400px; margin-left: -400px; top:100px; } </style> </apex:component>
Custom Component Controller
public with sharing class searchcomponentcontroller extends componentcontrollerbase{ public String myValue = ''; public string[] OptionList; public List<SelectOption> Options; boolean displaypopup; public void selectedoption{get; set;} public String searchtext{get;set;} public String getInitValue() {return myValue; } public void setInitValue(String s){myValue = s;} public void updateValue() {myvalue = searchtext; } public void setdisplaypopup(boolean b){displaypopup = true;} public Boolean getdisplaypopup(){return displaypopup;} public void showpopup(){displaypopup = true;} public void closepopup(){displaypopup = false;} public List<SelectOption> getOptions(){return Options;} public void setmyList(String[] sa){ OptionList = sa; Options = new List<SelectOption>(); for(integer i=0; i<sa.size(); i++){ Options.add(New SelectOption(sa[i],sa[i]));} } public String[] getmyList(){ return OptionList;} }
VF Page
<apex:page controller="MattTestController" > <apex:form > <c:CustomSearch pageController="{!this}" Searchby="{!filterlist}" label="My Label: "/> </apex:form> </apex:page>
Page Controller
public with sharing class MattTestController extends pagecontrollerbase { public searchcomponentcontroller myComponentController { get; set; } public override void setComponentController(ComponentControllerBase compController) { myComponentController = (searchcomponentcontroller)compController; } public override ComponentControllerBase getMyComponentController() { return myComponentController; } public String[] getfilterlist(){ String[] s = new String[]{'This','That'}; return s; } }
PageControllerBase
public with sharing virtual class PageControllerBase { private ComponentControllerBase myComponentController; public virtual ComponentControllerBase getMyComponentController() { return myComponentController; } public virtual void setComponentController(ComponentControllerBase compController) { myComponentController = compController; } public PageControllerBase getThis() { return this; } }
ComponentControllerBase
public with sharing virtual class ComponentControllerBase { public PageControllerBase pageController { get; set { if (value != null) { pageController = value; pageController.setComponentController(this); } } } }
I'm completely confused by your opening paragraph. "AssignTo" works but "assignto" does not?