[debutant]probleme recuperation d'un bean
bonjour,
mon probleme est le suivant.
je suis entrain de developper une petite application en jsf,
dans une page client.jsp j'affiche l'ensemble des clients que j'ai dans ma base.
jusque la tout marche bien,dans une 2eme partie je veux ajouter une fonctionalite qui me permet de modifier un client.
donc devant chaque client j'ai ajoute un lien qui m'envoie vers une autre page "ficheClient.jsp" qui contient des champs pour modifier les informations concernant le client choisi
Code:
1 2 3
| <html:commandButton type="submit" image="http://localhost:8080/magazin/images/delete.gif"
action="#{controller.modifierClient}"/>
<core:param value="#{client.id}" binding="#{clientView.id_client}" /> |
la methode modifierClient dans la classe "Controller" est comme suit:
Code:
1 2 3 4 5 6 7 8 9 10
| public String modifierClient()throws HibernateException{
FacesContext facesContext = FacesContext.getCurrentInstance();
ApplicationFactory appFactory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application app = appFactory.getApplication();
//facesContext.setResponseWriter()
ClientView clientView=(ClientView)app.createValueBinding("#{clientView}").getValue(facesContext);
ClientService service=new ClientService();
service.getOneClient(Integer.parseInt(clientView.getId_client().getValue().toString()));
return "modifierClient";
} |
la methode getOneClient de la classe ClientService est la suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| //**************************recuperer un enregistrement********************************//
public ClientBean getOneClient(int id)throws HibernateException{
Session session=HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Client client=(Client)session.load(Client.class,new Integer(id));
ClientBean clientBean=new ClientBean(client.getId().intValue(),client.getNom(),client.getPrenom(),client.getTel(),client.getProfession(),client.getAdresse(),client.getDateNaissance());
System.out.println("**nom du client a modifier est:"+clientBean.getNom());
tx.commit();
HibernateUtil.closeSession();
return clientBean;
} |
et le faces-config est comme suit:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| faces-config>
<managed-bean>
<managed-bean-name>clientBean</managed-bean-name>
<managed-bean-class>view.ClientBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>controller</managed-bean-name>
<managed-bean-class>controller.Controller</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>clientView</managed-bean-name>
<managed-bean-class>binding.ClientView</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/jsp/clients.jsp</from-view-id>
<navigation-case>
<from-action>#{controller.modifierClient}</from-action>
<from-outcome>modifierClient</from-outcome>
<to-view-id>/jsp/ficheClient.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<locale-config>
<default-locale>fr</default-locale>
</locale-config>
</application>
</faces-config> |
Le probleme c'est que quand je veux afficher les information concernant le client dans la page ficheClient.jsp je trouve que le bean clientBean est vide "j ai des valeurs nulle" pourtant je l ai remplie dans la methode getOneClient de la classe ClientService et je l ai mis en scope session.
je crois que le bean ne reste plus en session et qu'il s'instantie de nouveau.
merci de votre aide