0

I am trying to update a database entry.

When clicking on the edit button, the page just reloads and changes aren't saved and just reset.

When printing content of _speise to the console. the old value is printed, and not the one I wanted to change it to.


My Code:

SpeiseBean:

public void updateSpeise(ActionEvent event){
    Speise _speise = (Speise) event.getComponent().getAttributes().get("speise");
    speiseManager.updateSpeise(_speise);
}

xhtml page:

<h:form>
    <h:dataTable value="#{SpeiseBean.speisen}" var="speise">
        <h:column>
            <f:facet name="header">Name</f:facet>
            <h:inputText value="#{speise.name}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Tag</f:facet>
            <h:selectOneMenu value="#{speise.merkmal}">
                <f:selectItem itemValue="Mon"/>
                <f:selectItem itemValue="Tue"/>
                <f:selectItem itemValue="Wed"/>
                <f:selectItem itemValue="Thu"/>
                <f:selectItem itemValue="Fri"/>
            </h:selectOneMenu>
        </h:column>
        <h:column>
            <f:facet name="header">Preis</f:facet>
            <h:inputText value="#{speise.preis}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Beschreibung</f:facet>
            <h:inputText value="#{speise.beschreibung}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Merkmal</f:facet>
            <h:selectOneMenu value="#{speise.merkmal}">
                <f:selectItem itemValue="Nichts"/>
                <f:selectItem itemValue="vegan"/>
                <f:selectItem itemValue="vegetarisch"/>
                <f:selectItem itemValue="laktosefrei"/>
                <f:selectItem itemValue="glutenfrei"/>
            </h:selectOneMenu>
        </h:column>
        <h:column>
            <f:facet name="header">Bewertung</f:facet>
            <h:inputText value="#{speise.bewertung}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Aktion</f:facet>
            <h:commandButton value="Edit" actionListener="#{SpeiseBean.updateSpeise}">
                <f:attribute name="speise" value="#{speise}"/>
            </h:commandButton>
        </h:column>
        <h:column>
            <f:facet name="header">Aktion</f:facet>
            <h:commandButton value="Delete" action="#{SpeiseBean.deleteSpeise(speise)}"/>
        </h:column>
    </h:dataTable>
</h:form>
fuggerjaki61
  • 822
  • 1
  • 11
  • 24
L30N74
  • 23
  • 3
  • You should first learn how JSF works. https://www.tutorialspoint.com/jsf/index.htm – Simon Martinelli Jul 08 '20 at 14:37
  • Read https://stackoverflow.com/tags/jsf/info, https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope and https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes – Jasper de Vries Jul 08 '20 at 14:42
  • yeah.. and I was wondering why you were using an attribute on edit and not on delete.. see the duplicate – Jasper de Vries Jul 08 '20 at 14:46
  • I was using an attribute on edit because I was trying things out, and neither of them worked out. – L30N74 Jul 08 '20 at 14:51

0 Answers0