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...