modalPanel edit/delete Richfaces
Bonjour,
J'essaie en vain d'editer et de supprimer une ligne de ma <rich:dataTable> dans des <rich:modalPanel>. J'ai essayé plusieurs méthodes, récupérer la ligne courante grâce au composant UIData, récupérer l'id de l'élément en JS, ...
J'aimerais avoir une méthode qui marche et qui soit simple.
mon bean:
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
|
package com.atosorigin.gestionlicence.controller;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import org.ajax4jsf.model.KeepAlive;
import com.atosorigin.gestionlicence.dao.DemandeLicenceDao;
import com.atosorigin.gestionlicence.dao.LicenceDao;
import com.atosorigin.gestionlicence.dao.impl.DemandeLicenceDaoImpl;
import com.atosorigin.gestionlicence.dao.impl.LicenceDaoImpl;
import com.atosorigin.gestionlicence.form.Demandelicence;
import com.atosorigin.gestionlicence.form.Licence;
@KeepAlive
public class LicenceBean {
private List<Licence> dataList;
private int Index;
private UIData table;
private Licence currentItem;
private LicenceDao ldao = new LicenceDaoImpl();
@PostConstruct
public void init() {
dataList = ldao.listDemandeLicence();
}
public void setDataList(List<Licence> dataList) {
this.dataList = dataList;
}
public List<Licence> getDataList() {
dataList = ldao.listDemandeLicence();
return dataList;
}
public void delete() {
Licence lic = (Licence) table.getRowData();
long id = lic.getLicenceid();
ldao.deleteLicence(id);
}
public void store() {
dataList.set(Index, currentItem);
}
public int getIndex() {
return Index;
}
public void setIndex(int index) {
Index = index;
}
public UIData getTable() {
return table;
}
public void setTable(UIData table) {
this.table = table;
}
public Licence getCurrentItem() {
return currentItem;
}
public void setCurrentItem(Licence currentItem) {
this.currentItem = currentItem;
}
} |
et ma page jsp :
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
|
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<h:form>
<rich:panel style="border:0;width:60%;text-align:center">
<rich:panel>
<rich:dataTable cellpadding="0" cellspacing="0" border="0"
value="#{LicenceBean.dataList}" var="dataItem" id="tablelic"
style="text-align:center;" width="100%" rowKeyVar="row"
binding="#{LicenceBean.table}">
<f:facet name="header">
<rich:columnGroup>
<rich:column>
<h:outputText styleClass="headerText" value="LicenceID" />
</rich:column>
<rich:column>
<h:outputText styleClass="headerText" value="NumGPL" />
</rich:column>
<rich:column>
<h:outputText styleClass="headerText" value="Etat" />
</rich:column>
<rich:column>
<h:outputText styleClass="headerText" value="Actions" />
</rich:column>
</rich:columnGroup>
</f:facet>
<rich:column headerClass="filter" filterEvent="onkeyup"
filterBy="#{dataItem.licenceid}">
<f:facet name="header"></f:facet>
<h:outputText value="#{dataItem.licenceid}" />
</rich:column>
<rich:column headerClass="filter" filterEvent="onkeyup"
filterBy="#{dataItem.numgpl}">
<f:facet name="header"></f:facet>
<h:outputText value="#{dataItem.numgpl}" id="numgpl" />
</rich:column>
<rich:column headerClass="filter" filterEvent="onkeyup"
filterBy="#{dataItem.etat}">
<f:facet name="header"></f:facet>
<h:outputText value="#{dataItem.etat}" id="etat" />
</rich:column>
<rich:column>
<a4j:commandLink ajaxSingle="true" id="editlink"
oncomplete="#{rich:component('editPanelLic')}.show()" reRender="info">
<h:graphicImage value="/img/edit.gif" style="border:0" />
<f:setPropertyActionListener value="#{dataItem}"
target="#{LicenceBean.currentItem}" />
<f:setPropertyActionListener value="#{row}"
target="#{LicenceBean.Index}" />
</a4j:commandLink>
<rich:toolTip for="editlink" value="Edit" />
<a4j:commandLink ajaxSingle="true" id="deletelink"
oncomplete="#{rich:component('deletePanelLic')}.show()">
<h:graphicImage value="/img/delete.gif" style="border:0" />
<f:setPropertyActionListener value="#{row}"
target="#{LicenceBean.Index}" />
</a4j:commandLink>
<rich:toolTip for="deletelink" value="Delete" />
<a4j:commandLink ajaxSingle="true" id="addlink"
oncomplete="#{rich:component('addPanel')}.show()">
<h:graphicImage value="/img/add.png" style="border:0" />
<f:setPropertyActionListener value="#{dataItem}"
target="#{LicenceBean.currentItem}" />
<f:setPropertyActionListener value="#{row}"
target="#{LicenceBean.Index}" />
</a4j:commandLink>
<rich:toolTip for="addlink" value="Add" />
</rich:column>
</rich:dataTable>
<rich:datascroller renderIfSinglePage="true" maxPages="5" for="tablelic"></rich:datascroller>
</rich:panel>
</rich:panel>
</h:form>
<a4j:keepAlive beanName="LicenceBean" />
<rich:modalPanel id="editPanelLic" autosized="true" width="450">
<f:facet name="header">
<h:outputText value="Edit Current Row" />
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/img/close.png" id="hidelinkLic"
styleClass="hidelink" />
<rich:componentControl for="editPanelLic" attachTo="hidelinkLic"
operation="hide" event="onclick" />
</h:panelGroup>
</f:facet>
<h:form>
<rich:messages style="color:red;"></rich:messages>
<h:panelGrid columns="1">
<a4j:outputPanel ajaxRendered="true">
<h:panelGrid columns="2">
<h:outputText value="Numéro GPL" />
<h:inputText value="#{LicenceBean.currentItem.numgpl}" />
<h:outputText value="Etat" />
<h:inputText value="#{LicenceBean.currentItem.etat}" />
</h:panelGrid>
</a4j:outputPanel>
<a4j:commandButton ajaxSingle="true" value="Store"
action="#{LicenceBean.store}" reRender="tablelic"
oncomplete="#{rich:component('editPanelLic')}.hide();" />
</h:panelGrid>
</h:form>
</rich:modalPanel>
<rich:modalPanel id="deletePanelLic" autosized="true" width="200">
<f:facet name="header">
<h:outputText value="Delete this item from list?"
style="padding-right:15px;" />
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/img/close.png" styleClass="hidelink"
id="hidelinkLic2" />
<rich:componentControl for="deletePanel" attachTo="hidelinkLic2"
operation="hide" event="onclick" />
</h:panelGroup>
</f:facet>
<h:form>
<table width="100%">
<tbody>
<tr>
<td align="center" width="50%"><a4j:commandButton value="Yes"
ajaxSingle="true" action="#{LicenceBean.delete}"
oncomplete="#{rich:component('deletePanelLic')}.hide();"
reRender="tablelic" /></td>
<td align="center" width="50%"><a4j:commandButton
value="Cancel"
onclick="#{rich:component('deletePanelLic')}.hide();return false;" />
</td>
</tr>
</tbody>
</table>
</h:form>
</rich:modalPanel> |
Pour info : JEE5, richfaces 3.3.2, JSF 1.2.
Merci d'avance pour votre aide :)