Onchange selectOneMenu [SOLVED]

UI Components for JSF
garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

23 Sep 2010, 17:23

Hi

How can i trigger a function in my bean after onchange selectOneMenu?
Example, i have a function call abc.

I have this code: onchange="jQuery('#form').submit()"

What must i modify the code above to call abc after onchange?

Thks
Last edited by garyyip on 23 Sep 2010, 21:02, edited 1 time in total.

User avatar
Daedalus
Posts: 164
Joined: 28 Jan 2010, 12:03

23 Sep 2010, 18:47

Hello garyyip,
You can use <p:ajax> for that. Here is an example:

http://www.primefaces.org/showcase/ui/ajaxifyAction.jsf
PrimeFaces 3.0, Glassfish 3.1.2, Mojarra 2.1.6,

garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

23 Sep 2010, 19:16

Thk for replying

i don't i can use <p:ajax> in 2.2M1. <p:ajax> has only Id attribute only.
Any suggestion?

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

24 Sep 2010, 09:24

for <p:ajax>'s attributes, view User Guide page 353.
if you don't get all attributes, it is because your IDE doesn't support them.
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

User avatar
Daedalus
Posts: 164
Joined: 28 Jan 2010, 12:03

24 Sep 2010, 09:58

So you are using eclipse :D.

I would suggest to change to Netbeans but if you need/want to use eclipse you can get help here:
http://cagataycivici.wordpress.com/2010 ... se-helios/
PrimeFaces 3.0, Glassfish 3.1.2, Mojarra 2.1.6,

xbotnk
Posts: 5
Joined: 20 Sep 2010, 07:43

24 Sep 2010, 20:39

I'm using NetBeans 6.9.1 and I have the same problem, only available attribute is id. :-/

Using PrimeFaces 2.2M1.

fayca121
Posts: 17
Joined: 27 Jun 2010, 12:46

26 Sep 2010, 11:05

Hi All, I've the same problem, any solution please!!!
this is my code

Code: Select all

                            <div class="div_texbox">
                                <h:selectOneMenu value="#{testBean.testCategory}">
                                    <f:selectItems id="cattest" var="cat" value="#{examenBean.testCategories}" itemLabel="#{cat.name}"
                                                   itemValue=""/>
                                    <p:ajax update="subtest" event="change" actionListener="#{testBean.handleCatChange}" process="cattest"/>
                                </h:selectOneMenu>
                            </div>
                            <div class="div_texbox">
                                <h:selectOneMenu id="subtest" value="#{testBean.testtype}">
                                    <f:selectItems var="test" value="#{examenBean.testTypes}" itemLabel="#{test.name}"
                                                   itemValue=""/>
                                </h:selectOneMenu>
                            </div>
I use pf 2.2 M1 and nb 6.9.1
Netbeans 6.9.1 , GlassFish 3.0.1, Mojarra 2.0.3 , primefaces 2.2 rc2

callahan
Posts: 768
Joined: 27 May 2010, 22:52

26 Sep 2010, 12:07

@fayca121

In 2.2.M1 the p:ajax tag has listener attribute. The actionListener attribute no longer exists. See the following example in the showcase: http://www.primefaces.org/showcase/ui/ajaxifyAction.jsf.

fayca121
Posts: 17
Joined: 27 Jun 2010, 12:46

26 Sep 2010, 13:49

Hi , the problem is when I put a value at itemValue attribute, the event (listener="#{testBean.handleCatChange}") doesn't fire.
it works only when itemValue is empty !!!!!

what's wrong please?
Netbeans 6.9.1 , GlassFish 3.0.1, Mojarra 2.0.3 , primefaces 2.2 rc2

callahan
Posts: 768
Joined: 27 May 2010, 22:52

26 Sep 2010, 15:21

The process attribute in the p:ajax tag is set to "cattest", but cattest is not the id of a component. Remove the process attribute from the p:ajax tag. Remove the id="cattest" from the f:selectItems tag also.

If a cat is an object of a type that has both a name and a value property, something similar to the following should work:

Code: Select all

<h:selectOneMenu value="#{testBean.testCategory}">
  <f:selectItems var="cat" value="#{examenBean.testCategories}" itemLabel="#{cat.name}" itemValue="#{cat.value}"/>
  <p:ajax update="subtest" event="change" listener="#{testBean.handleCatChange}"/>
</h:selectOneMenu>
I assume handleCatChange looks something like this:

Code: Select all

    public void handleCatChange() {
       ...
    }

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests