bonne question à propos de l'attribut RENDERED
bonjour,
j'expérimente JSF (icefaces), spring & hibernate et j'ai créer une micro-appli-crud dans laquelle j'ai voulu influencer l'affichage de mes différents composants via l'attribut rendered car je voulais réaliser toute mes opérations sur une même page et de ce fait jouer avec ajax mais sans résultat.
voilà comment j'ai procédé :
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| dans ma page jsf :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<head>
<ice:outputDeclaration doctypeRoot="HTML"
doctypePublic="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctypeSystem="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>view</title>
</head>
<f:view>
<ice:form>
<ice:messages id="messages" globalOnly="true" styleClass="message" rendered="#{showGlobalMessages != 'false'}"
errorClass="messageErreurPage" infoClass="messagePage" warnClass="messageAttentionPage">
</ice:messages>
<table>
<tr style="vertical-align: top;">
<td>
<ice:commandButton action="#{personneBean.createPersonneAction}" value="Create" rendered="#{personneBean.view==true}"/>
<br />
<ice:dataTable value="#{personneBean.personnes}" var="people">
<ice:column>
<f:facet name="header">
<h:outputText value="id" />
</f:facet>
<ice:outputText value="#{people.id}" />
</ice:column>
<ice:column>
<f:facet name="header">
<h:outputText value="nom" />
</f:facet>
<ice:outputText value="#{people.nom}" />
</ice:column>
<ice:column>
<f:facet name="header">
<h:outputText value="prenom" />
</f:facet>
<ice:outputText value="#{people.prenom}" />
</ice:column>
<ice:column>
<f:facet name="header">
<h:outputText value="date de naissance" />
</f:facet>
<ice:outputText value="#{people.naissance}" />
</ice:column>
<ice:column>
<f:facet name="header">
<h:outputText value="province" />
</f:facet>
<ice:outputText value="#{people.province}" />
</ice:column>
<ice:column>
<f:facet name="header">
<h:outputText value="update" />
</f:facet>
<ice:commandButton value="edit" actionListener="#{personneBean.selectRow}"/>
</ice:column>
<ice:column>
<f:facet name="header">
<h:outputText value="delete" />
</f:facet>
<ice:commandButton value="delete" actionListener="#{personneBean.deleteRow}"/>
</ice:column>
</ice:dataTable>
</td>
<td>
<h:panelGrid columns="2" rendered="#{personneBean.view!=true}">
<h:inputHidden value="#{personneBean.personne.id}" />
<h:outputText value="nom" />
<h:inputText value="#{personneBean.personne.nom}" />
<h:outputText value="prenom" />
<h:inputText value="#{personneBean.personne.prenom}" />
<h:outputText value="date de naissance" />
<h:inputText value="#{personneBean.personne.naissance}" />
<h:outputText value="province" />
<h:inputText value="#{personneBean.personne.province}" />
<ice:commandButton action="#{personneBean.savePersonneAction}" rendered="#{personneBean.create==true}"
value="Create" />
<ice:commandButton action="#{personneBean.updatePersonneAction}" rendered="#{personneBean.update==true}"
value="Update" />
</h:panelGrid>
</td>
</tr>
</table>
</ice:form>
</f:view>
</html> |
j'avais un bouton create tout en haut, puis un tableau reprenant tout les enregistrements de la bd et à chaque fois un bouton edit et delete.
j'ai voulu créer un événement lorsque je cliquais sur create pour faire apparaitre une zone de saisie avec un bouton nommer add.
ensuite, j'ai également ajouter un événement sur le bouton edit pour faire apparaitre cette même zone de texte mais dans ce cas ci avec un bouton update.
add et update étant le même bouton et j'influençais leur nom visant un test style " #{personneBean.update==true?'update':'add'} "+ fonction d'hibernate derrière (saveOrUpdate).
Ensuite la zone de saisie disparaisait lorsqu'on cliquait sur le bouton.
Depuis lors, les événements fonctionne mais ! je n'ajoute plus, je ne sais plus modifier, par contre je sais supprimer. Donc j'ai créer 2 boutons distinct en pensant que c'était le problème (peut etre) mais le mécanisme restait le même.
pour ce faire, j'ai utiliser des booléens : view, update, create. Sachant qu'eclipse ne génère mais de getX pour les boolean mais des isX, j'ai tenter les deux l'un après l'autre pour savoir ce qui se passe sous le manteau avec jsf.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| voici mon bean "personneBean :
package backEndBean;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import javax.faces.model.ListDataModel;
import service.PersonneService;
import service.PersonneServiceImpl;
import dao.Personne;
public class PersonneBean extends AbstractBackingBean {
private static final long serialVersionUID = -4627945985562218855L;
private String personneId;
private ListDataModel personnes = null;
private Personne personne;
private PersonneService personneService;
/***/
private boolean view, create, update;
public boolean isView() {
return view;
}
public void setView(boolean view) {
this.view = view;
}
public boolean isCreate() {
return create;
}
public void setCreate(boolean create) {
this.create = create;
}
public boolean isUpdate() {
return update;
}
public void setUpdate(boolean update) {
this.update = update;
}
/**/
public PersonneBean() {
personne = new Personne();
personneService = new PersonneServiceImpl();
/**/
this.create=false;
this.update=false;
this.view=true;
/**/
}
public Personne getPersonne() {
return personne;
}
public void selectRow(ActionEvent event) {
/**/
this.create=false;
this.update=true;
this.view=false;
/**/
UIData uiData = (UIData) event.getComponent().getParent().getParent();
Personne row = (Personne) uiData.getRowData();
System.out.println(row.getNom());
this.personne = row;
}
public void deleteRow(ActionEvent event) {
/**/
this.create=false;
this.update=false;
this.view=true;
/**/
UIData uiData = (UIData) event.getComponent().getParent().getParent();
Personne row = (Personne) uiData.getRowData();
System.out.println(row.getNom());
this.personneService.deletePersonne(row);
}
public ListDataModel getPersonnes() {
try {
System.out.println();
System.out.println("getPersonnes");
personnes = new ListDataModel(personneService.getPersonnes());
} catch (Exception e) {
System.out.println("exception " + e.getMessage());
e.getStackTrace();
}
return personnes;
}
public String createPersonneAction() {
this.personne = new Personne();
/**/
this.create=true;
this.update=false;
this.view=false;
/**/
return "succes";
}
public String savePersonneAction() {
/**/
this.create=false;
this.update=false;
this.view=true;
/**/
try {
this.personneService.savePersonne(this.personne);
return "success";
} catch (Exception e) {
e.printStackTrace();
return "failure";
}
}
public String updatePersonneAction() {
/**/
this.create=false;
this.update=false;
this.view=true;
/**/
try {
this.personneService.updatePersonne(this.personne);
return "success";
} catch (Exception e) {
e.printStackTrace();
return "failure";
}
}
public void setPersonneService(PersonneService personneService) {
this.personneService = personneService;
}
public String getPersonneId() {
return personneId;
}
public void setPersonneId(String id) {
this.personneId = id;
if (personneId != null && !personneId.equals("")) {
Integer persId = new Integer(id);
}
}
} |
sachez que dans mon application j'ai une couche dao, service et backendbean (BackingBean ou BeanJSF).
Pourriez-vous me dire quelles sont mes erreurs possibles dans l'éventualité où quelqu'un l'aurait déjà tenté ?
merci