You need to sign in to do that
Don't have an account?
Sushupsi
Component Development in Apex
Hi All,
Long time since i have posted on the forums. Here i am with a request for suggestion.
I have developed the following component:
<apex:component controller="PickText"> <script> function ShowText(list,text) { document.getElementById(list).style.visibility = "hidden"; document.getElementById(list).style.display = "none"; document.getElementById(text).style.visibility = "visible"; document.getElementById(text).style.display = "inline"; document.getElementById(text).focus(); } </script> <span style="color:Blue;font-weight:bold"><apex:OutputLabel >Please Press a key to enable Text Entry</apex:OutputLabel></span><br/><br/> <apex:inputText id="inputone" style="visibility:hidden; display:none;" size="4" maxlength="2" value="{!SelectProduct}"> <apex:actionSupport action="{!SaveText}" event="onblur" reRender="inputone"/> </apex:inputText> <apex:selectList id="sel" size="1" value="{!SelectProduct}" onkeypress="ShowText('{!$Component.sel}','{!$Component.inputone}');"> <apex:selectOptions id="prodlist" value="{!ListValues}"> </apex:selectOptions> </apex:selectList> </apex:component>
The Controller for the component goes like this:
Public class PickText { public PageReference SaveText() { return null; } Public String SelectProduct; Public List<SelectOption> getListValues() { List<SelectOption> ProdList = new List<SelectOption>(); ProdList.add(new SelectOption('None','None')); ProdList.add(new SelectOption('MT','MT')); ProdList.add(new SelectOption('MO','MO')); ProdList.add(new SelectOption('PPC','PPC')); ProdList.add(new SelectOption('UBP','UBP')); ProdList.add(new SelectOption('EPS','EP')); return ProdList; } Public String getSelectProduct(){ return SelectProduct; } Public void setSelectProduct(String Product){ this.SelectProduct = Product; system.debug('******'+SelectProduct); } }
My query is when i have developed this component, the intention is to store the value from a text box or pick list into a back end field.
I have stored a value in the controller in a local variable.
When this component is used in a VF page, how do i access the value in the field. (The problem is the value is Stored in component's controller)
Any pointers are appreciated.
TIA
- Sushupsi
i think you will need to use <apex:attribute> tag which may provide you two binding of data.
You can find more information here: Visualforce Developer's Guide
Thank you Prasanna, i am currently working on the same and will try posting the component. :)
Thanks
-Sushupsi
Hi there, I struggled hard to conclude and still fail to reach a solution.:smileysad::smileysad:
Please find my component and help me with the same:
The controller for my component is aas follows:
My intention is to save the value in the picklist and send it to a field in the page in which the Component is used.
The main purpose is to Use the same component in multiple locations in the same VF page and yet reuse the code.
My problem is that i am unable to find a way to return the value chosen in the "Component Controller" to my controller in current page which uses the custom component.
My page that uses the component is as follows:
The Controller for current page is as:
I tried using the Assign to attribute, but it seems of not much help. Please educate me how to resolve the issue and help me code better.
Hoping to find a solution soon.:smileysad:
TIA
-Sushupsi.