[Javaa EE] Problème modification ligne datatable
Bjr à tous.
J'ai re-écris mon post pour plus de clarté.
Je suis debutant , j'ai generé un projet CRUD par Netbeans 6 avec bdd mysql pour gerer un stock.
Mais quand j'edite un ligne d'une facture fournisseur pour le modifier: je tombe toujours su la meme ligne, en l'occurence la 1ère ligne.
Soit, ma methode est inadequate , soit mon code bug. Merci de m'aider.
Mon bout de code est ci bas posté.Les etapes du programme sont numerotés de maniere chronologique selon les fichiers concernés..
Ma methode consite à cliquer sur les boutons( ecritures soulignées en gras ) selon la numérotation de ces fichiers:
voici mes fichiers :
1-livraisonfournisseur/list.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
| <h:panelGroup rendered="#{livraisonfournisseurController.items.rowCount > 0}">
<p:dataTable value="#{livraisonfournisseurController.items}" var="item"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15"> <p:column sortBy="#{item.codeLivrf}" headerText= bundle.ListLivraisonfournisseurTitle_codeLivrf}"/> <h:outputText value="#{item.codeLivrf}"/>
</p:column>
<p:columnheaderText= ="#{bundle.ListLivraisonfournisseurTitle_dateLivrf}"/>
<h:outputText value="#{item.dateLivrf}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
</p:column>
<p:column sortBy="#{item.idAct}" headerText="id Act">
<h:outputText value="#{item.idAct}"/>
</p:column>
<p:columnheaderText= ="#{bundle.ListLivraisonfournisseurTitle_actType}"/>
<h:outputText value="#{item.codeDep}"/>
</p:column>
<p:columnheaderText= =" "/>
<h:commandLink action="#{livraisonfournisseurController.prepareView}" value="#{bundle.ListLivraisonfournisseurViewLink}"/>
<h:outputText value=" "/>
<h:commandLink action="#{livraisonfournisseurController.prepareEdit}" value="#{bundle.ListLivraisonfournisseurEditLink}"/> <h:outputText value=" "/>
<h:commandLink action="#{livraisonfournisseurController.destroy}" value="#{bundle.ListLivraisonfournisseurDestroyLink}"/>
</p:column>
</p:dataTable>
</h:panelGroup> |
2-livraisonforunisseurcontroller.java
Code:
1 2 3 4 5 6 7 8
|
public String prepareEdit() {
current = (Livraisonfournisseur) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
// return "Edit";
recreateModel();
return "/entreestock/Create";
} |
3-entreestock.create.jsf:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<h:panelGroup id="print">
<h:form>
<p:dataTable value="#{entreestockController.details}" var="item" id="details">
<!-- border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px"> -->
<p:column style="width: 138px" >
<h:outputText style="width: 138px" value="#{item.codeProd}" />
</p:column>
<p:column style="width: 185px; right:auto">
<h:outputText style="width: 185px; right:auto" value="#{item.qteRecue}" styleClass="jsfcrud_even_rowright"/>
</p:column>
<p:column style="width: 185px" >
<h:outputText style="width: 185px" value="#{item.snProdestock}" styleClass="jsfcrud_even_rowright"/>
</p:column>
<p:column >
<h:commandLink action="#{entreestockController.prepareDetailsEdit()}" value="Edit" immediate="true"/> </p:column>
</p:dataTable>
</h:form>
</h:panelGroup> |
4-entreestockcontroller.java:
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
|
public String prepareDetailsEdit() {
recreateModel();
current = (Entreestock)getDetails().getRowData();
return "Edit";
}
public DataModel getDetails() {
recreateModel();
if(details==null){
details=new ListDataModel();
details.setWrappedData(detailFacture());
}
return details;
}
private void recreateModel() {
details=null;
items = null;
dataItem=null;
}
public List<Entreestock> detailFacture(){
try {
String a= "select e from Entreestock e where"
+ " e.codeLivrf =:num";
return getFacade().ListDetailsFacture(a, "num", CodeLF);
} catch (Exception ex) {
Logger.getLogger(EntreestockController.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
public String update() {
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("EntreestockUpdated"));
// return "View";
return "Create";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
} |
5-entreestock:edit.jsf:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="#{bundle.EditEntreestockLabel_numLigneblf}" for="numLigneblf" />
<h:inputText disabled="true" id="numLigneblf" value="#{entreestockController.selected.numLigneblf}" title="#{bundle.EditEntreestockTitle_numLigneblf}" required="true" requiredMessage="#{bundle.EditEntreestockRequiredMessage_numLigneblf}"/>
<h:outputLabel value="#{bundle.EditEntreestockLabel_qteRecue}" for="qteRecue" />
<h:inputText id="qteRecue" value="#{entreestockController.selected.qteRecue}" title="#{bundle.EditEntreestockTitle_qteRecue}" required="true" requiredMessage="#{bundle.EditEntreestockRequiredMessage_qteRecue}"/>
<h:outputLabel value="#{bundle.EditEntreestockLabel_snProdestock}" for="snProdestock" />
<h:inputText id="snProdestock" value="#{entreestockController.selected.snProdestock}" title="#{bundle.EditEntreestockTitle_snProdestock}" required="true" requiredMessage="#{bundle.EditEntreestockRequiredMessage_snProdestock}"/>
<h:outputLabel value="#{bundle.EditEntreestockLabel_codeProd}" for="codeProd" />
<h:selectOneMenu disabled="true" id="codeProd" value="#{entreestockController.selected.codeProd}" title="#{bundle.EditEntreestockTitle_codeProd}" required="true" requiredMessage="#{bundle.EditEntreestockRequiredMessage_codeProd}">
<f:selectItems value="#{produitsController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="#{bundle.EditEntreestockLabel_codeLivrf}" for="codeLivrf" />
<h:selectOneMenu disabled="true" id="codeLivrf" value="#{entreestockController.selected.codeLivrf}" title="#{bundle.EditEntreestockTitle_codeLivrf}" required="true" requiredMessage="#{bundle.EditEntreestockRequiredMessage_codeLivrf}">
<f:selectItems value="#{livraisonfournisseurController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
</h:panelGrid>
<p:commandButton type="submit" action="#{entreestockController.update}" value="Enregistrer" style="width: 200px" ajax="false"/> </h:form> |
Desolé pour la longueur du code, toute aide est le bienvenu.