abstractionz
asked on
Creating a custom JSF component
I have a javascript editable combobox. I would like to make it into a JSF component. I am not sure where to begin. It is basically a dropdown menu, where the user can select one option, or type in anything they want. So the selected choice, or the user input is posted. It's a combination of a textbox and a menu. Is it possible to create a jsf component that just renders the javascript which i already have?
Do you know JSF? www.jsftutorials.net
Easy enough. You need to create four things:
1. A renderer. This simply spits out the appropriate javascript and associated HTML field(s)
2. A JSP Tag that allows you to embed it in the page
3. A faces-config.xml that describes the new widget
4. A concrete component class.
Actually, have a look at the standard Select widgets. You can have your selectable values as selectItem/selectItems, your component is the standard UISelect component, and all you need is a tweaked renderer - you can base it on the selectOne or selectMany renderer. If your items are encoded in a special way, then set your renderer's getRendersChildren to return true and iterate over the children.
1. A renderer. This simply spits out the appropriate javascript and associated HTML field(s)
2. A JSP Tag that allows you to embed it in the page
3. A faces-config.xml that describes the new widget
4. A concrete component class.
Actually, have a look at the standard Select widgets. You can have your selectable values as selectItem/selectItems, your component is the standard UISelect component, and all you need is a tweaked renderer - you can base it on the selectOne or selectMany renderer. If your items are encoded in a special way, then set your renderer's getRendersChildren to return true and iterate over the children.
ASKER
Hi bpmurray,
I followed your steps and got the javascript to render. However, the colon stuck in the id is causing a javascript warning. I dont suppose there is anyway around that other than modifying all my javascript...
How could I tweak a renderer to allow the user to make a UISelect editable?
I followed your steps and got the javascript to render. However, the colon stuck in the id is causing a javascript warning. I dont suppose there is anyway around that other than modifying all my javascript...
How could I tweak a renderer to allow the user to make a UISelect editable?
ASKER
My javascript has to use the clientId as a variable name, but the colon messes it up:
var myform:fromDate
var myform:fromDate
That's a completely legitimate ID - you should fix your JavaScript.
ASKER
var myform:fromDate = 6;
alert(myform:fromDate);
would not work
alert(myform:fromDate);
would not work
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.