IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

modalPanel edit/delete Richfaces


Sujet :

JSF Java

  1. #1
    Membre averti
    Inscrit en
    Février 2011
    Messages
    20
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 20
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  2. #2
    Membre averti
    Femme Profil pro
    Inscrit en
    Juin 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juin 2011
    Messages : 20
    Par défaut
    1- Dans ton fichier jsp: ajouter onRowClick (comme dans ce code), le paramètre à passer est licenceid que j'espère de type unique ou primary key

    <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}"
    onRowClick="myFunc('#{dataItem.licenceid}'); Event.stop(event);"
    >


    2- Après ça, il faut associer ce fonction myFunc dans onRowClick çi-dessus à a4j

    <a4j:jsFunction action="#{LicenceBean.editOrDel}" name="myFunc" ajaxSingle="true" reRender="tablelic">
    <a4j:actionparam name="current"/>
    </a4j:jsFunction>

    3- Dans ton bean LicenceBean il faut ajouter une méthode comme et tu recupère le licenceid ici

    public void editOrDel(){
    String lid = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("current");
    //si ton licenceid est de type int, il faut faire parserInt lid en int

    for(Licence l : dataList){

    if (l.licenceid==lid){
    //Tu as la ligne à éditer ou à supprimer, datalist.remove() ou Licence lic =l;

    find=true;
    break;
    }
    }

    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. combobox editable avec richfaces
    Par rabebIF5 dans le forum JSF
    Réponses: 1
    Dernier message: 20/05/2009, 18h07
  2. [RichFaces] ModalPanel et Calendar
    Par gcube dans le forum JSF
    Réponses: 1
    Dernier message: 11/06/2008, 11h59
  3. Réponses: 1
    Dernier message: 28/05/2008, 10h39
  4. Réponses: 4
    Dernier message: 23/01/2008, 11h35
  5. IBdataset edit, delete, update :help:
    Par nek_kro_kvlt dans le forum Bases de données
    Réponses: 2
    Dernier message: 05/10/2006, 14h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo