我正在尝试调用控制器中的函数save
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);
}
}
我seminaires.xhtml
里有<a></a>
. . .
<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>
. . .
并且由于某种原因,我的代码没有执行(我的数据库中没有更改,控制台中没有"HELLO")
我认为你应该替换
<a jsf:action = "#{seminaireControl.save(seminaire)}">MODIFIER</a>
跟
<h:commandLink value="MODIFIER" action="#{seminaireControl.save(seminaire)}">
您可能还需要将 h:dataTable 转换为 h:form
<h:form>
<h:dataTable >
..............
..............
</h:dataTable>
<h:form>