1

I'm new at stackoverflow and I hope you can help me. I have a xhtml page, that includes a composition. In the composition is a h:form with a p:commandbutton for submitting the h:form. The p:commandbutton has an action, that should trigger a bean methode, but it doesn't. When i try to put the p:commandbutton outside the composition, in the xhtml page, it works.

a little bit code, so you may unterstand my problem a bit better:

The part in the index.xhtml, that includes the composition (This works fine):

    <p:panel id="centerContentPanel" style="margin:0px; padding:0px; border:0px;">
          <ui:include src="#{nCWPBean.centerPanelPage}.xhtml" />
    </p:panel>

The composition:

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://primefaces.org/ui">

    <h:form id="newUserForm">
        <table border="0">
            <thead>
                <tr>
                    <th><h:outputText value="creating a new User"/></th>
                    <th></th>
                </tr>
            </thead> 
            <tbody>
                <tr>
                    <td><h:outputText value="User Name"/></td>
                    <td><p:inputText id="username" value="#{DBconBean.uname}"/></td>
                </tr>
                <tr>
                    <td><h:outputText value="Password"/></td>
                    <td><p:inputText type="password" id="passwordFirst" value="#{DBconBean.pw}"/></td>
                </tr>
                <tr>
                    <td><h:outputText value="confirm Password"/></td>
                    <td><p:inputText type="password" id="passwordSecond" value="#{DBconBean.pw2}"/></td>
                </tr>
                <tr>
                    <td><h:outputText value="Admin"/></td>
                    <td><p:selectBooleanCheckbox value="#{DBconBean.rights}" id="adminCheck"/></td>
                </tr>
                <tr>
                    <td><p:commandButton type="submit"  value="Submit"  action="#{DBconBean.insertNewUser()}" icon="ui-icon-check"/></td>
                    <td><p:commandButton type="reset" value="Reset"/></td>
                </tr>
            </tbody>
        </table>

     </h:form>
</ui:composition>

And when I put the whole p:commandbutton, with the action="#{DBconBean.insertNewUser()}"in the index.html, the methode runs. That really confuses me...

So, here is my question: How can I trigger a Bean Methode, from a Button in a Composition? Or what did I do wrong?

Oh, and when I try to put in an javascript function, that runs onsubmit or onclick, it works, until the function contains #{DBconBean.insertNewUser()};. In this case the methode is triggerd at the time, the composition loads, not at the time, when the function runs...

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jayam
  • 11
  • 1
  • *And when I put the whole `p:commandbutton`, with the `action="#{DBconBean.insertNewUser()}"` in the index.html, the methode runs* So if it works outside `ui:include` are you sure you don't have nested forms?. One `h:form` in page when you include your page and second in including page? Also you can check HTTP response in console (F12) for further debugging. You could find there info like *validation failed* if you had validation. – Geinmachi Nov 08 '15 at 12:55
  • Thanks for the answer, but i double checked it now for nested forms and there aren't any.. the last line before the three lines with the include, that i posted, was . And I checked the HTTP response as you said: everytime I click the submit button, i get a new HTTP request (I think this is good). The Status-Code is "HTTP/1.1 200 OK" and it contains all values I entered in the form.. This Problem really confuses me :/ – Jayam Nov 09 '15 at 23:40

0 Answers0