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 :

Passage de données entre deux pages


Sujet :

JSF Java

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2014
    Messages : 1
    Points : 2
    Points
    2
    Par défaut Passage de données entre deux pages
    Bonjour , je suis nouvel en JSF . je travaille avec primefaces 5.3 .
    En fait , je veux à partir d'une première page ou une liste des projets est affiché récupérer a chaque fois l'ID d'un tel projet pour par la suite chercher en fonction de cet ID la liste des testCases de ce projet avec la méthode "FindByID" et afficher cette liste dans une deuxieme page (TestCasesList.xhtml)
    J'ai essayer avec l'event les données recupérées sont bien reçus mais lorsque j'arrive à la deuxiem page rien ne s'affiche.
    Remarque:Un projet contient une liste des testCases.
    Voici mes pages et merci

    ProjectList.xhtml:
    Code xml : 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
    <ui:composition template="./template1.xhtml">
     
    	<ui:define name="content">
    		<h:head>
    			<title>List</title>
    			<h:outputStylesheet library="css" name="design.css" />
     
    		</h:head>
     
    		<h:body styleClass="body-list-user">
     
    			<h:form id="form">
     
    				<p:panel var="Projects" id="ProjectList">
    					<f:facet name="header">
     
    						<p:link value="#{msg.MenuBarNewProject}" href="NewProject.xhtml"></p:link>
     
    						<h:outputLabel for="dd" value="#{msg.ListSortBy}"
    							styleClass="userslist-btn-sortby " />
    						<p:autoComplete id="dd" dropdown="true"
    							completeMethod="#{autoCompleteView.completeText}" />
    						<p:inputText styleClass="userslist-btn-search"
    							placeholder="#{msg.ListSearch}" />
     
    					</f:facet>
     
    					<p:accordionPanel multiple="true"
    						value="#{projectMB.projectsList()}" var="project">
    						<f:param id="p" value="project" />
    						<p:ajax event="tabChange"
    							listener="#{projectMB.getProjectTesCases}" />
     
    						<p:tab closable="false">
     
    							<f:facet name="title"> #{project.projectName} 
     
     
    								<p:commandButton value="#{msg.ListDelete}" icon="ui-icon-close"
    									styleClass="userslist-btn-delete"
    									onmousedown="PF('DeleteProjectDialog').show()" />
     
    								<p:commandButton value="#{msg.ListExplore}"
    									icon="ui-icon-search" styleClass="userslist-btn-explore">
     
     
    								</p:commandButton>
     
    							</f:facet>
     
    							<h:panelGrid columns="2" cellpadding="10">
     
     
    								<h:outputText value="Description:  #{project.description}" />
     
    							</h:panelGrid>
     
    						</p:tab>
    						<p:dialog header="DeleteProject" widgetVar="DeleteProjectDialog"
    							modal="true" showEffect="fade" hideEffect="fade"
    							resizable="false">
                                                   You are sure you want to delete this Project? 
     
    				<p:commandButton value="#{msg.ListDelete}" icon="ui-icon-disk"
    								action="#{projectMB.deleteProject(project.id)}" />
     
    							<p:commandButton value="#{msg.Cancel}"
    								onclick="PF('DeleteProjectDialog').hide()" icon="ui-icon-close" />
     
    						</p:dialog>
    					</p:accordionPanel>
    				</p:panel>
     
    				<p:dialog header="#{msg.MenuBarNewProject}"
    					widgetVar="NewProjectDialog" modal="true" showEffect="fade"
    					hideEffect="fade" resizable="false">
    					<ui:include src="NewProject.xhtml" />
    				</p:dialog>
                                  </h:form>
    		</h:body>
    	</ui:define>
    </ui:composition>

    ProjectManagedBean

    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
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    package com.focus.seleniumfactory.managedController;
     
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.RequestScoped;
    import javax.faces.bean.SessionScoped;
    import javax.faces.bean.ViewScoped;
    import javax.faces.context.FacesContext;
     
    import org.primefaces.event.TabChangeEvent;
    import org.springframework.dao.DataAccessException;
     
    import com.focus.seleniumfactory.spring.model.Project;
    import com.focus.seleniumfactory.spring.model.TestCase;
    import com.focus.seleniumfactory.spring.service.ProjectService;
    import com.focus.seleniumfactory.spring.service.TestCaseService;
     
    @ManagedBean(name = "projectMB")
    @SessionScoped
    public class ProjectManagedBean implements Serializable {
     
    	private static final long serialVersionUID = 1L;
    	private static final String SUCCESS = "/pages/NewTC.xhtml";
    	private static final String ERROR = "/pages/TCList.xhtml";
    	private static final String SAMEPAGE = "null";
     
    	@ManagedProperty(value = "#{ProjectService}")
    	ProjectService projectService;
    	public List<TestCase> getTestC() {
    		return testC;
    	}
     
     
     
     
    	public void setTestC(List<TestCase> testC) {
    		this.testC = testC;
    	}
     
    	@ManagedProperty(value = "#{TestCaseService}")
    	TestCaseService testCaseService;
     
    	private String testcaseName;
    	private String testcaseDescription;
    	private int id;
    	public List<TestCase> testC ;
     
     
     
    	public List<TestCase> getProjectTesCases( TabChangeEvent event)
    	{	
    		Project p = (Project)event.getData();
    		testC= getTestCaseService().getProjectTestCases(p.getId());
    		System.out.println(testC.get(0).getId());
    		System.out.println(testC.get(0).getTestCaseName());
    		System.out.println(testC.get(0).getDescription());
    		return testC;
     
     
    	}
     
     
     
     
     
     
    	public String addTC ()
    	{
    		TestCase tc = new TestCase();
    		try{
     
    			tc.setTestCaseName(getTestcaseName());
    			tc.setDescription(getTestcaseDescription());
     
    			getTestCaseService().addTestCase(tc);
    			return SUCCESS;
     
    		}catch (DataAccessException e) {
                e.printStackTrace();
            }   
     
            return ERROR;
     
    	}
     
    	public List<Project> projectsList(){
    		return getProjectService().getProjects();
    	} 
     
     
     
    	public void deleteProject(int id)
    	{
     
    		getProjectService().deleteProject(id);
     
    	}
     
    	private String projectName;
    	private String projectBaseURL;
    	private String projectBasePath;
    	private String projectDescription;
     
     
    	public String addproject(){
    		try{
    			Project project=new Project();
    			project.setProjectName(getProjectName());
    			project.setBaseUrl(getProjectBaseURL());
    			project.setBasePath(getProjectBasePath());
    			project.setDescription(getProjectDescription());
    			getProjectService().addProject(project);
     
     
    			return SUCCESS;
    		}catch (DataAccessException e) {
                e.printStackTrace();
            }   
     
            return ERROR;
    	}
     
    	public Project search(String projectname){
    		return  getProjectService().getProjectByProjectName(projectname);
     
    	}
     
    	public void update(Project project)
    	{
    		getProjectService().updateProject(project);
     
    	}
     
     
     
    	public ProjectService getProjectService() {
    		return projectService;
    	}
     
    	public void setProjectService(ProjectService projectService) {
    		this.projectService = projectService;
    	}
     
    	public String getProjectName() {
    		return projectName;
    	}
     
    	public void setProjectName(String projectName) {
    		this.projectName = projectName;
    	}
     
     
    	public String getProjectBaseURL() {
    		return projectBaseURL;
    	}
     
    	public void setProjectBaseURL(String projectBaseURL) {
    		this.projectBaseURL = projectBaseURL;
    	}
     
    	public String getProjectBasePath() {
    		return projectBasePath;
    	}
     
    	public void setProjectBasePath(String projectBasePath) {
    		this.projectBasePath = projectBasePath;
    	}
     
    	public String getProjectDescription() {
    		return projectDescription;
    	}
     
    	public void setProjectDescription(String projectDescription) {
    		this.projectDescription = projectDescription;
    	}
     
     
    	public String getTestcaseName() {
    		return testcaseName;
    	}
     
    	public void setTestcaseName(String testcaseName) {
    		this.testcaseName = testcaseName;
    	}
     
    	public String getTestcaseDescription() {
    		return testcaseDescription;
    	}
     
    	public void setTestcaseDescription(String testcaseDescription) {
    		this.testcaseDescription = testcaseDescription;
    	}
     
    	public TestCaseService getTestCaseService() {
    		return testCaseService;
    	}
     
    	public void setTestCaseService(TestCaseService testCaseService) {
    		this.testCaseService = testCaseService;
    	}
    	public int getId() {
    		return id;
    	}
     
     
    	public void setId(int id) {
    		this.id = id;
    	}
     
     
    }

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 804
    Points
    48 804
    Par défaut
    Dans ta page de sélection de projet tu lie le selectonemenu à une propriété d'un bean session scoped. Ensuite dans le reste de ton code tu utilise ce bean pour accéder à l'information.

Discussions similaires

  1. Passage de paramètre entre deux pages?
    Par fabszn dans le forum JSF
    Réponses: 18
    Dernier message: 01/11/2007, 00h15
  2. passage d'information entre deux pages
    Par hamham dans le forum Interfaces Graphiques en Java
    Réponses: 4
    Dernier message: 30/01/2007, 16h36
  3. Réponses: 2
    Dernier message: 23/06/2006, 21h45
  4. Passage de données entre deux pages
    Par spica92 dans le forum ASP
    Réponses: 2
    Dernier message: 08/09/2005, 14h38
  5. passage de parametre entre deux page asp
    Par tomtom25 dans le forum ASP
    Réponses: 4
    Dernier message: 01/04/2005, 16h16

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