0

i'm trying to call a result of Struts2 action after getting inputs from a form and putting them in an object to stock in the database my struts.xml is

<action name="showForm" class="com.web.SalarieAction" method="afficherSalarie">
        <result name="success">/pages/form.jsp</result>
</action>

<action name="ajouterSalarie" class="com.web.SalarieAction" method="ajoutSalarie">
    <result name="input">/pages/form.jsp</result> 
    <result name="success">/pages/addBookOk.jsp</result>
</action>

the default action is going well it's giving me the form but it cannot be validated

my class action is

public class SalarieAction extends BaseAction {

    private Salarie salarie ;

    private SalarieService salarieService;

    public String ajoutSalarie() {
        salarieService.addSalarie(salarie);
        System.out.println("a salarieaction - ajoutsalarie method");

        return SUCCESS;
    }

    public Salarie getSalarie() {
        return this.salarie;
    }

    public void setSalarie(Salarie salarie) {
        this.salarie = salarie;
    }

    public SalarieService getSalarieService() {
        return salarieService;
    }

    public void setSalarieService(SalarieService salarieService) {
        this.salarieService = salarieService;
    }

    public String deletSalarie(int id_sal) throws EntityNotFoundException {
        this.salarieService.deleteSalarie(id_sal);
        return SUCCESS;
    }

    public String authentifier(String Salarie, String id_sal,int id_sal_num){

         this.salarieService.authentifier(Salarie,id_sal,id_sal_num);
         return SUCCESS;
    }

    public String afficherSalarie(){
            return SUCCESS;
    }

the class service to stock with it is the following

public class SalarieServiceImpl implements SalarieService {

    private SalarieDao SalarieDao;

    public SalarieDao getSalarieDao() {
        return SalarieDao;
    }

    public void setSalarieDao(SalarieDao salarieDao) {
        SalarieDao = salarieDao;
    }

    public void addSalarie(Salarie salarie) {
        // TODO : probabelement du code permettant de vérifier les régles
        // métiers
        System.out.println("a salarieserviceimpl - addsalarie");
        SalarieDao.create(salarie);

        //TODO : eventuellement du code metier à ajouter
    }

    public void deleteSalarie(int id_sal) throws EntityNotFoundException {
        // TODO : probabelement du code permettant de vérifier les régles
        // métiers

        SalarieDao.delete(id_sal);

        //TODO : eventuellement du code metier à ajouter
    }

    public Salarie  authentifier(String Salarie, String id_sal,int id_sal_num) {
        Salarie salarie= SalarieDao.getEntityByColumn(Salarie, id_sal, id_sal_num);
        return  salarie;
    }

the dao class is

public class SalarieDaoImpl extends GenericDaoImpl<Salarie, Integer> implements SalarieDao {

    public SalarieDaoImpl() {
        // car on travail sur des objets de la classe metier, il y a des méthodes
        // hibernate qui auront besoin de cette information cf. le code de
        // generic dao
        super(Salarie.class);
    }

    public Salarie getEntityByColumn(String Salarie, String id_sal,int id_sal_num) {
        // Une requete HQL simple pour faire la selection
        String HqlQuery = "from " + Salarie + " where " + id_sal
                + " = ?";

        List l = getHibernateTemplate().find(HqlQuery, id_sal_num);
        if (l == null || l.size() == 0)
            throw new ObjectRetrievalFailureException(Salarie, null);
        return (com.bo.Salarie) l.get(0);
    }

my form in jsp is

    `<%@taglib uri="/struts-tags" prefix="s"%>
    <%@ taglib uri="http://displaytag.sf.net" prefix="d"%>
    <%@ taglib prefix="sj" uri="/struts-jquery-tags" %>


    <jsp:include page="inc/header.jsp" flush="true" />

    <jsp:include page="inc/menu.jsp" flush="true" />

<h1>Ajout d'un salarie</h1>

<div style="width: 500px;">




    <s:form action="ajouterSalarie" method="POST">
        <s:textfield label="id_sal" name="salarie.id_sal" required="true" />
        <s:textfield label="nom_sal " name="salarie.nom_sal" required="true" />
        <s:textfield label="Prenom_sal" name="salarie.prenom_sal" />
        <s:textfield label="adresse_sal" name="salarie.adresse_sal" />
        <s:textfield label="email_sal " name="salarie.email_sal" />
        <s:textfield label="date_recrutement " name="salarie.date_recrutement" />
        <s:textfield label="salaire" name="salarie.salaire"/>
        <s:textfield label ="grade" name="salarie.grade"/>
        <s:textfield label="note" name="salarie.note" />










        <s:submit value="Valider" cssClass="btn btn-primary" />

    </s:form>

</div>
<jsp:include page="inc/footer.jsp" />


</body>
</html>`

my salarie calss is `package com.bo; import java.util.*;

public class Salarie {


        private int id_sal;


        private String nom_sal;


        private String prenom_sal;

        private String adresse_sal;


        private String email_sal;

        private Date date_recrutement;

        private float salaire;

        private int grade;



        private float note;
        private List<Demander> demande;

        public List<Demander> getDemande() {
            return demande;
        }

        public void setDemande(List<Demander> demande) {
            this.demande = demande;
        }

        public Salarie() {
            System.out.println("objet salarie est instancie");
        }

        public Salarie(int id_sal, String nom_sal, String prenom_sal, String adresse_sal, String email_sal,
                       Date date_recrutement, float salaire, int grade,List<Demander>demande)

        {
            this.id_sal = id_sal;
            this.nom_sal = nom_sal;
            this.prenom_sal = prenom_sal;
            this.adresse_sal = adresse_sal;
            this.email_sal = email_sal;
            this.date_recrutement = date_recrutement;
            this.salaire = salaire;
            this.demande=demande;
        }

    public String getNom_sal() {
        return nom_sal;
    }

    public void setNom_sal(String nom_sal) {
        this.nom_sal = nom_sal;
    }

    public String getPrenom_sal() {
        return prenom_sal;
    }

    public void setPrenom_sal(String prenom_sal) {
        this.prenom_sal = prenom_sal;
    }

    public String getAdresse_sal() {
        return adresse_sal;
    }

    public void setAdresse_sal(String adresse_sal) {
        this.adresse_sal = adresse_sal;
    }

    public String getEmail_sal() {
        return email_sal;
    }

    public void setEmail_sal(String email_sal) {
        this.email_sal = email_sal;
    }

    public Date getDate_recrutement() {
        return date_recrutement;
    }

    public void setDate_recrutement(Date date_recrutement) {
        this.date_recrutement = date_recrutement;
    }

    public float getSalaire() {
        return salaire;
    }

    public void setSalaire(float salaire) {
        this.salaire = salaire;
    }

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }



    public int getId_sal() {
        return id_sal;
    }

    public void setId_sal(int id_sal) {
        this.id_sal = id_sal;
    }

    public float getNote() {
        return note;
    }




    public void setNote(float note) {
        this.note = note;
    }

} `

  • What is your error? do you have any stacktrace or log ? – Abass A Jul 02 '17 at 08:20
  • Comment the line `salarieService.addSalarie(salarie);` and see what happens. – Roman C Jul 02 '17 at 08:24
  • @AbassA the result of ajouterSalarie action don't work, i cannot stock in object from a form.jsp – youssef loukili Jul 02 '17 at 08:59
  • @RomanC i need this salarieService.addSalarie(salarie) to creat in the dao object how can i do it without it ?? – youssef loukili Jul 02 '17 at 09:04
  • Could you provide source code of your form.jsp and also your Salarie class ? – Abass A Jul 02 '17 at 09:16
  • @RomanC i need this salarieService.addSalarie(salarie) to creat in the dao object how can i do it without it ?? – youssef loukili Jul 02 '17 at 09:16
  • @youssefloukili Does it return a resource that is not found? – Roman C Jul 02 '17 at 09:21
  • @RomanC it's giving me a result jsp that i asked when i commented what you mentioned but the attributs ar not stcked it's useless because i have no more dao object to stocked in it – youssef loukili Jul 02 '17 at 09:26
  • @youssefloukili Please correct your formatting, and the form.jsp source code is not displayed. – Abass A Jul 02 '17 at 09:27
  • @AbassA form.jsp is displayed because it's given from the default action but when i put values in it id dosen't work lik i want : the object service that i called don't responde – youssef loukili Jul 02 '17 at 09:33
  • @youssefloukili I was talking about source code that you've added, i can see Salarie class but not the form.jsp source code, you probably have a validation issue in form.jsp – Abass A Jul 02 '17 at 09:35
  • @AbassA it's done you can read it – youssef loukili Jul 02 '17 at 09:50
  • @RomanC i readed the answer that you suggested but it seems it's not the same problem because i'm workin on worked project just i modified the inputs and outputs of classes and views – youssef loukili Jul 02 '17 at 10:36
  • @youssefloukili if struts2 is looking for the resource it should be available to server let dispatcher, other wise the server let will return resource not found error, read more [here](https://stackoverflow.com/q/36231946/573032). – Roman C Jul 02 '17 at 19:06

0 Answers0