1

I have a button called "Send" in a page that has a form, and I use this Form from two differents pages for send mails. From the first page I enter to this form and I must to use the methodOne. From the second page I enter to the same form and I must to use the methodTwo.

Mothod examples is like this:

public Navigation methodOne(){
    return Navigation.NAVIG_ONE;
}

public Navigation methodTwo(){
    return Navigation.NAVIG_TWO;
}

and the form example:

<h:form>
    <p:outputLabel id="email" value="#{service.Mail}"/>
    <p:inputText  id="subject" value="#{service.Subject}"/>
    <p:inputTextarea  id="body" value="#{service.Body}" />


    <p:commandButton value="send" action="#{service.methodOne}" />
</h:form>

I want to use the same Form for use two differents methods.

How to use the methodOne and methodTwo in the same action attrubite of tag <p:commandButton />?

0x5a4d
  • 750
  • 1
  • 7
  • 21
Jorge Avila
  • 149
  • 1
  • 9

2 Answers2

1

The simplest solution is to create a variable on which you will identify which page is open. To set this variable, use something like this. This variable may simply store the page number, such as 1,2 or the page name such as pageOne, pageTwo. Create a method in which just this variable will be checked:

public Navigation navigateMethod(){
    switch (page) {
    case "pageOne":
        return Navigation.NAVIG_ONE;
        break;

    case "pageTwo":
        return Navigation.NAVIG_TWO;
        break;

    default:
        return Navigation.DEFAULT
        break;
    }
}

and the your form:

<h:form>
    <p:outputLabel id="email" value="#{service.Mail}"/>
    <p:inputText  id="subject" value="#{service.Subject}"/>
    <p:inputTextarea  id="body" value="#{service.Body}" />


    <p:commandButton value="send" action="#{service.navigateMethod}">
    </p:commandButton>
</h:form>
0x5a4d
  • 750
  • 1
  • 7
  • 21
0

The cleanest solution is to create a composite component and pass pass the method expression in as an attribute

See also:

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47