0

I'm trying to make a Java Project with JSF and PrimeFaces.

I have two tables. Person and Address with a relation one to one in database.

When I construct project with Netbeans, it created two separated create.xthml files. One for Address and one for Person. I'd like to mix them in a new single xhtml file.

My question is.. How can I save the data of two beans with only one commanbutton actionlistener?

I have that from two create.xhtml.

<p:commandButton actionListener="#{persona.create}" value="#{bundle.Save}" />
<p:commandButton actionListener="#{address.create}" value="#{bundle.Save}" />

and I need only one button.

Krish Munot
  • 1,093
  • 2
  • 18
  • 29
  • Even if im not rly confirm about the way you do it, you can achieve this with the possible duplicate of [JSF2 execute two methods in action](http://stackoverflow.com/questions/7912663/jsf2-execute-two-methods-in-action) – ceekay May 22 '15 at 11:43
  • 2
    why not create just one bean for the xhtml ? – Jordi Castilla May 22 '15 at 11:43

2 Answers2

0

Not sure about this but you can try

<p:commandButton action="#{address.create}" actionListener="#{persona.create}" value="#{bundle.Save}" />
Dev
  • 21
  • 5
0

You can call the second bean inside the first one and call create method inside.

public class address {
    public void create() {
        Persona persona = (Persona) FacesContext.getCurrentInstance().getApplication().getExpressionFactory()
            .createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{Persona}", Persona.class)
            .getValue(FacesContext.getCurrentInstance().getELContext());
        persona.create();
}
Joffrey Hernandez
  • 1,809
  • 3
  • 21
  • 39