2

I am having trouble because I have a method in Java, I need the function to receive 2 values, String and ItemSelectEvent because I use the same funciton several times.

How can I send the event from the XHTML?

Here's how I tried to do it:

<p:chart type="donut" model="#{bean.donut}">
    <p:ajax event="itemSelect" listener="#{bean.createModel("P", event)}" 
         update="grap"/>
</p:chart>

The bean method:

public void createModel(String str, ItemSelectEvent event){
...
}

But the method always receives the "event" as null, only receives the event when I call it like this

<p:chart type="donut" model="#{bean.donut}">
    <p:ajax event="itemSelect" listener="#{bean.createModel}" 
         update="grap"/>
</p:chart>

Bean

public void createModel(ItemSelectEvent event){
...
}

But i need it to send the extra String, thanks in advance

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • does it fail on another type of component to? Does it fail on plain jsf to (h:component and f:ajax) ? – Kukeltje Apr 28 '16 at 16:01
  • Is this solution acceptable: http://stackoverflow.com/questions/4782430/how-to-pass-additional-parameters-in-ajax-request-on-change-value-in-hselectone – Kukeltje Apr 28 '16 at 16:01
  • this is what it sends when I try sending anything createModel(java.lang.String, null) how can I send the event, I tried doing org.primefaces.event.ItemSelectEvent, event, ItemSelectEvent and everything sends null, except when I send nothing, but I need to send the String with the event – Ivan Chavarria Apr 28 '16 at 16:25

2 Answers2

1

Here's how I solved the problem, instead of

<p:chart type="donut" model="#{bean.donut}">
    <p:ajax event="itemSelect" listener="#{bean.createModel("P", event)}" 
         update="grap"/>
</p:chart>

I did

<p:chart type="donut" model="#{bean.donut}">
    <p:ajax event="itemSelect" listener="#{bean.createModel}" onStart="bean.str('T')" 
         update="grap"/>
</p:chart>

and on the bean I made it an attribute instead of a parameter

-----------------Edit-------------------

So I was having problems with the time of execution and what I ended up doing was call a method like this:

<p:ajax ... listener="#{bean.method}"/>

and the method was declared like this

method(itemSelectEvent e){
     method2("P", e);
}
method2(String option, itemSelectEvent e){
     ...
}

and made one method for each option I wanted to call

0

Try to put the string attribute in a f:attribute inside p:chart and then catch it in your backing bean method:

event.getComponent().getAttributes.get("attributeName");
Jaumzera
  • 2,305
  • 1
  • 30
  • 44