Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a widgetVar?

If i have a primefaces component, like

<p:selectOneMenu id="myComponent">
...
</p:selectOneMenu>

In the html, it will generate something like this:

<div id="myFormName:myComponent" widgetVar="lollipop">
...A lot of things in here...
</div>
<script id="myFormName:myComponent_s">
   $(function(){PrimeFaces.cw('SelectOneMenu','lollipop',.......
</script>

Inside the script tag, you can notice the widget var name(if i dont provide it in the component, it will be generated). I want to know how can i get the widget var element, or if this is not possible, how can i get that "" tag so i can get the name of this widget var.

------ EDIT ------ I will try to explain why i need this. i have this function:

function simulaTabManoBrow(event){
    var focusedComponent=document.activeElement;
    if(event.keyCode==13){
        //Cancel th edefault enter event(submit the form)
        event.preventDefault();
        event.stopPropagation();
        event.returnValue = false;
        event.cancelBubble = true;
        if((focusedComponent.tagName.toLowerCase()=="input" && focusedComponent.type.toLowerCase()=="button") || focusedComponent.tagName.toLowerCase()=="button"){
            //If the focused component is a button, click the button.
            focusedComponent.click();
        }else{
            //Press the tab key programatically
            $.emulateTab();
            verifyOneMenu(campoFocado);
        }
    }
}

This function is executed on the body's onkeydown event. The goal of this is to replace the default behavior of the enter key by the tab key. The only problem of this is, when the focused component is a selectOneMenu and the user hits enter, it correctly behaves like the tab key, but the selectOneMenu previously focused is opened(because this is the default behavior of the component).

So, what i am trying to do, is to call the close() method of the selectOneMenu widget var of that previously focused component.

like image 374
Mateus Viccari Avatar asked Jun 28 '13 17:06

Mateus Viccari


1 Answers

You can get the widgetVar object by id using this handy function:

Function

function getWidgetVarById(id) {
   for (var propertyName in PrimeFaces.widgets) {
     if (PrimeFaces.widgets[propertyName].id === id) {
       return PrimeFaces.widgets[propertyName];
     }
   }
}

Usage

getWidgetVarById('myFormName:myComponent');

Example

getWidgetVarById('dialogId').show();

See More:

  • Get widgetVar by Id
  • Intro To PrimeFaces widgetVar
like image 182
Hatem Alimam Avatar answered Sep 22 '22 07:09

Hatem Alimam