Accessing value from WidgetVar

UI Components for JSF
Post Reply
drakula
Posts: 46
Joined: 20 Nov 2013, 15:56

24 Sep 2014, 15:07

Initially with primefaes 3.5

Code: Select all

<p:selectOneMenu id="testId"
					value="#{bean.value}" filter="true"
					filterMatchMode="contains" widgetVar="test" onchange="change(test);">
				 	<f:selectItems  value="#{bean.list}" />
	</p:selectOneMenu>
I could get the value selected in the dropdown

Code: Select all

<script type="text/javascript">
function change (test) {
var testValue = test.getSelectedValue();
}
</script>

But it seems to be no longer possible on upgrading to primefaces 5.0 : It gives an error saying 'test is undefined'

Is there a way to obtain value from a widgetVar
Primefaces 5.0
Jsf 2.2
Jboss eap 6.2
Primefaces Extension 2.0.0

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

24 Sep 2014, 15:35

Please try on PF5;

Code: Select all

<p:selectOneMenu id="testId"
               value="#{bean.value}" filter="true"
               filterMatchMode="contains" widgetVar="test" onchange="change();">
                <f:selectItems  value="#{bean.list}" />
   </p:selectOneMenu>

Code: Select all

<script type="text/javascript">
function change () {
    var testValue = PF("test").getSelectedValue();
}
</script>

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

24 Sep 2014, 16:16

I'd personally just (try to) change the onclick to:

onclick="change(PF('test'))"

More 're-usable'

Or (temporarily?) use the compatibility mode if you have access to an elite release

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests