0

I got a problem where one of my commandbuttons doesn't call the method I gave it and I have no idea why:

<p:layoutUnit position="center">
    <h:form>
        <p:dialog position="center" widgetVar="benutzerErstellen" visible="true" closable="false" resizable="false" draggable="false">
            <h:panelGrid columns="2" cellpadding="5" styleClass="noBorders">
                <h:outputLabel for="nachname" value="Nachname:" />  
                <p:inputText id="nachname" value="#{benutzerverwaltung.nachname}" required="true"/>
                <h:outputLabel for="vorname" value="Vorname:" />  
                <p:inputText id="vorname" value="#{benutzerverwaltung.vorname}" required="true"/>
                <h:outputLabel for="benutzername" value="Benutzername:" />  
                <p:inputText id="benutzername" value="#{benutzerverwaltung.benutzername}" required="true" validator="#{benutzerverwaltung.benutzerUeberschneidungValidate}"/>
                <h:outputLabel for="teams" value="Teams:" />
                <p:selectCheckboxMenu id="teams" label="Teams" scrollHeight="200" panelStyle="width:300px">
                        <f:selectItems/>
                </p:selectCheckboxMenu>
                <h:outputLabel for="passwort" value="Passwort:" />  
                <p:password id="passwort" feedback="true" value="#{benutzerverwaltung.passwort}" required="true" match="passwortBestaetigung" promptLabel="Bitte geben Sie ein Passwort ein." weakLabel="Schwach" goodLabel="Gut" strongLabel="Stark"/>
                <h:outputLabel for="passwortBestaetigung" value="Passwort bestätigen:" />  
                <p:password id="passwortBestaetigung" value="#{benutzerverwaltung.passwort}" required="true"/>
                <f:facet name="footer">  
                    <p:commandButton id="erstellen" value="Benutzer erstellen" action="#{benutzerverwaltung.erstelleBenutzer()}"/>  
                </f:facet>  
            </h:panelGrid>
        </p:dialog>
        <p:growl/>
    </h:form>
</p:layoutUnit>

This is the corresponding code:
erstelleBenutzer:

public void erstelleBenutzer(){
    Benutzer benutzer = new Benutzer();
    System.out.println(vorname);
    benutzer.setVorname(vorname);
    benutzer.setNachname(nachname);
    benutzer.setBenutzername(benutzername);
    benutzer.setPasswort(passwort);
    this.benutzer.add(benutzer);
    FacesMessage message = new FacesMessage("Benutzer wurde erstellt.");
    message.setSeverity(FacesMessage.SEVERITY_INFO);
    throw new ValidatorException(message);
}

benutzerUeberschneidungValidate:

public void benutzerUeberschneidungValidate(FacesContext ctx, UIComponent component, Object value) throws ValidatorException {
    if (benutzerExistiert((String) value) || adminExistiert((String) value)) {
        FacesMessage message = new FacesMessage("Benutzer existiert bereits.");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
}

I tried removing the validator, I tried removing the Exception from benutzerErstellen(), I tried giving the dialog it's own h:form and much more, but nothing worked. Anyone got an idea?

  • Everything seems to be fine. Try isolating this code in a single page and execute it. – Luiggi Mendoza Nov 22 '13 at 14:34
  • 1
    Are you sure the data you used is valid? Try to remove all required attributes and the validator and the match attribute of the password field. Or add `autoUpdate="true"` to the `p:growl` to see validation errors. – user1983983 Nov 22 '13 at 14:38
  • @7SpecialGems since JSF 2 the method used in `action` can *return void* to tell the framework it won't navigate outside the view. And this is the preferred way when using ajax invoked methods. – Luiggi Mendoza Nov 22 '13 at 14:47
  • @7SpecialGems sorry, this was the link: http://stackoverflow.com/q/3909267/1065197. – Luiggi Mendoza Nov 22 '13 at 14:53
  • @Luiggi Mendoza Thankyou - the link to a Generics question made no sense at all! – 8bitjunkie Nov 22 '13 at 14:54
  • You need to execute `commandButton` with `process=@this` when you doing ajax on `commandButton` – SRy Nov 22 '13 at 15:16
  • Okay, the problem was simply that I had nested forms... You couldn't see this in the code because I didn't paste everything. Thanks, everyone for helping. – SirAnducar Nov 29 '13 at 11:36

2 Answers2

0

Earlier versions of PrimeFaces 3 have a bug wherein a commandButton or commandLink doesn't fire the action listener if it is located in the header or the footer.

See the post I have listed at the bottom.

p:commandButton action and f:setpropertyactionlistener not invoked in p:columngroup

Community
  • 1
  • 1
patstuart
  • 1,931
  • 1
  • 19
  • 29
0

I solved this like that

     <p:dataTable>
...
<p:column>
...
<p:commandButton id="selectButton" update=":form:dataTable" icon="ui-icon-circle-     close" title="Delete" action="#{myBean.doSomething}">
                    <p:ajax event="click" listener="#{mainPageBean.doRemoveEmployee(employee)}"/>
                    </p:commandButton>
...
</p:column>
...
</p:dataTable>
Vadym Roganin
  • 343
  • 1
  • 3
  • 10