www.webdeveloper.com
Results 1 to 3 of 3

Thread: Using JavaScript on JSF:comboBox

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Exclamation Using JavaScript on JSF:comboBox

    Hi all,
    I'm trying to use java script to select an item in a JSF comboBox (which is non-editible) but i can't get it working!!!

    Below is the HTML that renders the control but i cannot find a way of clicking the combo button and then selecting an item using javascript

    Can anyone help me please!! I'm going mad!!!!!




    <td><div id="exceptionSearchOptionForm3:uehIdCondition"><div class="rich-combobox-font rich-combobox " id="exceptionSearchOptionForm3:uehIdConditioncombobox" style="width:200px;"><div class="rich-combobox-list-cord"></div><div class="rich-combobox-font rich-combobox-shell" style="width:200px;"><input autocomplete="off" class="rich-combobox-font-inactive rich-combobox-input-inactive " disabled="true" id="exceptionSearchOptionForm3:uehIdConditioncomboboxField" name="exceptionSearchOptionForm3:uehIdConditioncomboboxField" readonly="true" style="width:190px; " type="text" value="Contains" /><input class="rich-combobox-font-inactive rich-combobox-button-background rich-combobox-button-inactive" id="exceptionSearchOptionForm3:uehIdConditioncomboBoxButtonBG" readonly="true" tabindex="-1" type="text" /><input class="rich-combobox-font-inactive rich-combobox-button-icon-inactive rich-combobox-button-inactive " disabled="true" id="exceptionSearchOptionForm3:uehIdConditioncomboboxButton" readonly="true" style="; background-image: ;" tabindex="-1" type="text" /><div class="rich-combobox-strut rich-combobox-font" style="width:190px">Strut</div></div><div class="rich-combobox-list-cord " id="exceptionSearchOptionForm3:uehIdConditionlistParent" style="display:none; ; position:absolute;z-index:1000;"><div class="rich-combobox-shadow"><table border="0" cellpadding="0" cellspacing="0" id="exceptionSearchOptionForm3:uehIdConditionshadow"><tr><td class="rich-combobox-shadow-tl"><img alt="" height="1" src="/portal/a4j/g/3_3_1.GAimages/spacer.gif.jsf" style="border:0" width="10" /><br /></td><td class="rich-combobox-shadow-tr"><img alt="" height="10" src="/portal/a4j/g/3_3_1.GAimages/spacer.gif.jsf" style="border:0" width="1" /><br /></td></tr><tr><td class="rich-combobox-shadow-bl"><img alt="" height="10" src="/portal/a4j/g/3_3_1.GAimages/spacer.gif.jsf" style="border:0" width="1" /><br /></td><td class="rich-combobox-shadow-br"><img alt="" height="10" src="/portal/a4j/g/3_3_1.GAimages/spacer.gif.jsf" style="border:0" width="10" /><br /></td></tr></table></div><div class="rich-combobox-list-position" id="exceptionSearchOptionForm3:uehIdConditionlistPosition"><div class="rich-combobox-list-decoration" id="exceptionSearchOptionForm3:uehIdConditionlistDecoration"><div class="rich-combobox-list-scroll" id="exceptionSearchOptionForm3:uehIdConditionlist"></div></div></div></div><input id="exceptionSearchOptionForm3:uehIdConditioncomboboxValue" name="exceptionSearchOptionForm3:uehIdCondition" type="hidden" /></div><script type="text/javascript">var clientId = 'exceptionSearchOptionForm3:uehIdCondition';


    var comboboxUserStyles = {
    button : {
    classes :
    {
    normal: "",
    active: "",
    disabled: ""
    },
    style :
    {
    normal: "",
    active: "",
    disabled: ""
    }
    },
    buttonicon : {
    style :
    {
    normal: "",
    active: "",
    disabled: ""
    }
    },
    field : {
    classes :
    {
    normal: "",
    active: "",
    disabled: ""
    },
    style :
    {
    normal : "",
    active : "",
    disabled : ""
    }
    },
    combolist : {
    list: {
    classes:
    {
    active: ""
    },
    style:
    {
    active: "'"
    }
    },
    item: {
    normal : "",
    selected: ""
    }
    }
    };


    var combobox = new Richfaces.ComboBox( "exceptionSearchOptionForm3:uehIdCondition",
    "exceptionSearchOptionForm3:uehIdConditionlist",
    "exceptionSearchOptionForm3:uehIdConditionlistParent",
    "exceptionSearchOptionForm3:uehIdConditioncomboboxValue",
    "exceptionSearchOptionForm3:uehIdConditioncomboboxField",
    "exceptionSearchOptionForm3:uehIdConditioncomboboxButton",
    "exceptionSearchOptionForm3:uehIdConditioncomboBoxButtonBG",
    "exceptionSearchOptionForm3:uehIdConditionshadow",
    new Richfaces.ComboBoxStyles(),
    comboboxUserStyles,
    "200px", "200px",
    [] ,
    true,
    true,
    true,
    null,
    null,
    null,
    "",
    true, 'Contains',
    0, 0);</script></div>

  2. #2
    Join Date
    Oct 2009
    Posts
    1
    Yeah, was searching for it too and found nothing...
    But exploring rendered HTML we can see that its not actually <select> but set of input controls.
    Value is displayed in control $richFacesID+comboboxField (in your case - exceptionSearchOptionForm3:uehIdConditioncomboboxField)
    On submit value is taken from hidden $richFacesID+comboboxValue (in your case - exceptionSearchOptionForm3:uehIdConditioncomboboxValue)

    So to properly select value you should set both fields by js:
    create js function:
    Code:
    function setComboBoxValue(control, value) {
        document.getElementById(control.id + 'comboboxField').value = value;
        document.getElementById(control.id + 'comboboxValue').value = value;
    }
    and then use it in your jsp:
    Code:
    setComboBoxValue(#{rich:element('exceptionSearchOptionForm3:uehIdCondition')}
    rich:element(...) is needed if your control is deeper in DOM and you don't know its full path.

    Hope it will help.

  3. #3
    Join Date
    Oct 2009
    Posts
    2
    Cheers,
    I'll give this a go

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles