0

With the following code with primefaces 6.0

<p:diagram  value="#{myBean.model}" var="m" >
    <f:facet name="element">
        <h:commandButton value="#{m.id}" action="#{myBean.test(m.id)}"/>
    </f:facet>
</p:diagram>

and

@Named
@SessionScoped
public class MyBean implements Serializable {
    .....
    private  DefaultDiagramModel model;
    //getter and setter

    public String test(int id) {
        System.out.println("ID IS : " + id);
        return null;
    }
    ....
}

I get the value of the id on the button label (rendered on the xhtml page).

But I get always the number

ID IS : 0

on the IDE console

If I change my code with action="#{myBean.test(4)}" I get in the IDE console

4

If I change my code with action="#{myBean.test(6)}" I get in the IDE console

6

But when I come back to action="#{myBean.test(m.id)}" I get always in the IDE console the number 0

But the value if the id is well rendered on button label on the xhtml page

Non Exception is thrown!

Any help please?

Hicham
  • 170
  • 2
  • 16

1 Answers1

0

Take a look into how-to-pass-a-parameter-along-with-hcommandbutton. I've checked example with <f:param> and it works like a charm in your case.

So in your case

<p:diagram  value="#{myBean.model}" var="m" >
   <f:facet name="element">
       <h:commandButton value="#{m.id}" action="#{myBean.test}">
           <f:param name="elementId" value="#{m.id}" />
       </h:commandButton>
   </f:facet>
</p:diagram>

And in bean

public String test() {
    String elementId= FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("elementId");
    System.out.println("ID IS : " + elementId);
    return null;
}
Community
  • 1
  • 1
rkarczmarczyk
  • 327
  • 5
  • 13
  • Posting just a link might answer the question but isn't very useful at all. If the link were to ever go offline or become invalid your answer becomes useless. Remember links are meant to improve your answer not meant to replace writing high quality answers. – Charlie Fish Oct 10 '16 at 23:37
  • Thanks for advice, I've extended answer with example how to use example in this particular question. – rkarczmarczyk Oct 11 '16 at 05:38