Can't call controller function from jsf:action

390 views Asked by At

I'm trying to call the function save in my controller SeminaireControl.java

package be.helha.aemt.control;

import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

import be.helha.aemt.ejb.GestionSeminaireEJB;
import be.helha.aemt.entities.Seminaire;

@SessionScoped
@Named
public class SeminaireControl implements Serializable{

    private static final long serialVersionUID = 1L;
    @EJB
    private GestionSeminaireEJB bean;

    public List<Seminaire> getAll()
    {
        return bean.getAll();
    }

    public void save(Seminaire seminaire)
    {
        System.out.println("HELLO");
        bean.save(seminaire);

    }
}

with the <a></a> in my seminaires.xhtml

. . .

    <h:dataTable class="seminaire" value = "#{seminaireControl.getAll()}" var = "seminaire">
        <h:column>
            <f:facet name="header">Id</f:facet>
            <h:form>
               #{seminaire.id_student}
             </h:form>
        </h:column>
        <h:column>
            <f:facet name="header">Nom</f:facet>
            #{studentControl.getNameById(seminaire.id_student)}
        </h:column>
        <h:column>
            <f:facet name="header">Séminaire 1</f:facet>
            <h:inputText value="#{seminaire.seminaire1}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Séminaire 2</f:facet>
            <h:inputText value="#{seminaire.seminaire2}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Séminaire 3</f:facet>
            <h:inputText value="#{seminaire.seminaire3}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Séminaire 4</f:facet>
            <h:inputText value="#{seminaire.seminaire4}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Save</f:facet>
            <a jsf:action = "#{seminaireControl.save(seminaire)}">MODIFIER</a> // THIS LINE
        </h:column>
        <h:column>
            <f:facet name="header">Total</f:facet>
            0
        </h:column>
    </h:dataTable>
. . .

and for some reason, my code isn't executed (no changes in my database & no "HELLO" in my console)

1

There are 1 answers

0
mfe On BEST ANSWER

I think you shold replace

<a jsf:action = "#{seminaireControl.save(seminaire)}">MODIFIER</a>

with

<h:commandLink value="MODIFIER" action="#{seminaireControl.save(seminaire)}">

You may also need take h:dataTable into h:form

<h:form>
   <h:dataTable >
   ..............
   ..............
   </h:dataTable>
<h:form>