String boot getVideo always returns NullPointerException - spring

Good Morning. Can someone help me please?
I followed this tutorial https://www.knowledgefactory.net/2021/09/spring-boot-webflux-video-streaming.html to create a video streaming app. Inside the resources folder there is a subfolder which has two MP4 files inside.
The problem happens when I hit the getVideo inside the next class:
package net.javaguides.springboot.implementations;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
#Service
public class StreamingService {
private static final String FORMAT = "classpath:videos/%s.mp4";
private ResourceLoader resourceLoader;
public Mono<Resource> getVideo(String title) {
return Mono.fromSupplier(() -> resourceLoader.getResource(String.format(FORMAT, title)));
}
}
The controller uses a configuration bean which is as follows:
package net.javaguides.springboot.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import net.javaguides.springboot.implementations.StreamingService;
import reactor.core.publisher.Mono;
#Configuration
public class EndPointConfig {
#Autowired
private StreamingService service;
#Bean
public RouterFunction<ServerResponse> router() {
return RouterFunctions.route().GET("video/{title}", this::videoHandler).build();
}
private Mono<ServerResponse> videoHandler(ServerRequest serverRequest) {
String title = serverRequest.pathVariable("title");
return ServerResponse.ok().contentType(MediaType.valueOf("video/mp4")).body(service.getVideo(title),
Resource.class);
}
}
And Controller endpoint that retrieves video stream is as follows:
#Controller
#AllArgsConstructor
public class VideoController {
private StreamingService streamingService;
#GetMapping(value = "video/{title}", produces = "video/mp4")
#ResponseBody
public Mono<Resource> getVideos(#PathVariable String title, #RequestHeader("Range") String range) {
System.out.println("Range in bytes = " + range);
return streamingService.getVideo(title);
}
#GetMapping("show")
public String show() {
return "video";
}
}
And finally, the application has an html file that has a video tag whose src attribute points to the show method of the controller to display the player as follows:
<!DOCTYPE html>
<html
lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout_navigation.html}">
<head>
<meta charset="UTF-8">
<title>OBR-VIDEOTHEQUE</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="styles.css"> -->
<style type="text/css">
#video-player {
display: none;
}
#video-form {
width: 60%;
}
.error {
color: red;
}
.success {
color: green;
}
</style>
</head>
<body>
<section layout:fragment="content">
<meta charset="utf-8">
<div class="container mt-5">
<h2>Video streaming</h2>
<video src="video/movie" type="video/mp4" width="720" height="480" controls preload="none">
</video>
</div>
</section>
<section layout:fragment="footer">
<footer class="container py-5 text-center footer">
<div class="row">
<div class="col-md-12">
<p class="text-muted">© 2022. Tous
droits réservés.</p>
</div>
</div>
</footer>
</section>
<section layout:fragment="scripts">
<script th:src="#{/js/jQuery-min.js}"></script>
<script
type="text/javascript"
th:src="#{/js/dropdown.js}"></script>
<script th:src="#{/js/bootstrap.bundle.js}"></script>
<script th:src="#{/js/bootstrap.min.js}"></script>
<script th:src="#{/js/select2.min.js}"></script>
<!-- <script th:src="#{/js/main.js}"></script> -->
</section>
</body>
</html>
After running the application, in the url i type http://localhost:8082/show
From that Url, the video player shows up. When I hit the play button, i get 500 Error saying this:
java.lang.NullPointerException: null
at net.javaguides.springboot.implementations.StreamingService.lambda$0(StreamingService.java:17)
This is third day i tried to spot where is the error with no success.
Can someone tell me where I'm getting things wrong.
I highly thank in advance anybody that will take time to help me.
Regards,

You have a not initialized ResourceLoader.
Change this line of code
private ResourceLoader resourceLoader;
in these ones:
#Autowired
private ResourceLoader resourceLoader;
This will tell Spring Context to inject an instance of ResourceLoader in your attribute.

Related

How to pass individual variables to view in thymeleaf?

Hi I'm building a skeleton of a car renting webapp and I'm trying to create a view that shows some details like location name, car name etc.
View code- car-list.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Vehicle List</title>
<h2 th:text="${location1}">Locations</h2>
<table class="table table-stripped">
<thead>
<td th:text="${vehicle1Name}">Vehicle Name</td>
</tr>
</thead>
<td th:text="${vehicle2Name}">Vehicle Name</td>
</tr>
</table>
</head>
<body>
</body>
</html>
And heres my controller
package com.project.CS4125.controller;
import com.project.CS4125.model.*;
import com.project.CS4125.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList;
import java.util.List;
#Controller
#RequestMapping("/car-list")
public class VehicleController {
#GetMapping("/car-list")
public String carList(Model model){
Vehicle VWGolf = new BasicCar();
Vehicle Duster = new SUVDecorator(new BasicCar());
Location limerick= new Location("Limerick");
model.addAttribute("location1", limerick.getLocationName());
model.addAttribute("vehicle1Name", "Volkswagen Golf");
model.addAttribute("vehicle2Name", "Dacia Duster");
return "index";
}
}
My problem is the view comes up completely empty, any help appreciated.
EDIT
Before this page I have a register and login page
index.html (register page
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<form action="#" th:action="#{/register}" th:object="${user}"
method="post">
<p>User Name <input type="text" name="name"></p>
<p>Password <input type="password" name="password"></p>
<button type="submit">Register</button>
</form>
<button>Login Here</button>
</body>
</html>
login.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<form action="#" th:action="#{/login}" th:object="${user}"
method="post">
<p>User Name <input type="text" name="name"></p>
<p>Password <input type="password" name="password"></p>
<button type="submit">Login</button>
</form>
<button>Register Here</button>
</body>
</html>
And heres the controller for these
#Controller
#RequestMapping("/")
public class IndexController {
#Autowired
private UserService userService;
#Autowired
private CustomerFactory userFactory;
#PostMapping("/register")
public String registerUser(#ModelAttribute User user){
User u = userFactory.createUser(user.getName(), user.getPassword());
userService.saveUser(u);
return "login";
}
#GetMapping("/login")
public String login(){
return "login";
}
#PostMapping("/login")
public String loginUser(#ModelAttribute User user){
User authenticatedUser = userService.authenticate(user.getName(), user.getPassword());
System.out.println(authenticatedUser.toString());
return "car-list";
}
}
Even after adding the code from the answer below I'm still getting an empty page, after submitting the login form moving to the car list page its still empty.
I also noticed in the answer the URL is http://localhost:8080/car-list but when I try it its http://localhost:8080/login
I've just tested your code and you have two problems.
The first one is at your:
#Controller
#RequestMapping("/car-list")
public class VehicleController {
#GetMapping("/car-list")
In this GetMapping you're saying that you want to access your template at /car-list/car-list.
The seccond one is with your template name. You're returning "index" when you should return "car-list", at this you're returning the template name.
So, editting your code like this:
#Controller
#RequestMapping("/car-list")
public class VehicleController {
#GetMapping
public String carList(Model model){
model.addAttribute("location1", "Answer");
model.addAttribute("vehicle1Name", "Volkswagen Golf");
model.addAttribute("vehicle2Name", "Dacia Duster");
return "car-list";
}
}
I got:
Template working and returning

Web.servlet.PageNotFound - No mapping for GET

I'm learnig how Spring boot + MVC works. I can display a message on the screen, but I can not modifying the style. The js e css file don't map with Spring.
2020-04-17 14:38:29.169 WARN 9552 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound : No mapping for GET /js/main.js
2020-04-17 14:38:29.169 WARN 9552 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping for GET /css/main.css
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
#Controller
public class HelloController {
#GetMapping("/")
public String index() {
return "index";
}
#PostMapping("/hello")
public String sayhello(#RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "hello";
}
#GetMapping({"/helloworld", "/helloname"})
public String hello(Model model, #RequestParam(value="name", required=false, defaultValue="WORLD") String name) {
model.addAttribute("name", name);
return "helloname";
}
}
I've tryied to modify the path in the application.properties, but it didn't change anything.
spring.mvc.view.prefix = /WEB-INF/view/
spring.mvc.view.suffix = .jsp
spring.mvc.static-path-pattern = /resources/**
This is my jsp page. When I run this page , I get the error message, that I've posted before
<!DOCTYPE html>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css"
href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
<c:url value="/css/main.css" var="jstlCss" />
<link href="${jstlCss}" rel="stylesheet" />
</head>
<body>
<div class="container">
<header>
<h1>Spring MVC + JSP + JPA + Spring Boot 2</h1>
</header>
<div class="starter-template">
<h1>Users List</h1>
<table
class="table table-striped table-hover table-condensed table-bordered">
<tr>
<th>Date</th>
<th>Device</th>
<!-- <th>Amount</th>
<th>OEE</th> -->
</tr>
<c:forEach items="${OEE}" var="oee">
<tr>
<!-- <td>${oee.oeeID.date}</td>
<td>${oee.oeeID.device}</td> -->
<td>${oee.amount}</td>
<td>${oee.oee}</td>
</tr>
</c:forEach>
</table>
</div>
</div>
<script type="text/javascript"
src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
use this
#Configuration
#EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}

Cannot upload file to Spring Boot REST using Axios and FormData

I try to upload file from page using axios and can't get it on my controller.
In fromt-end I use Vue.js with axios, and at the back end Spring MVC Controller. It seems that my controller can`t convert FormData() to MultipartFile in spring. I read a lot of questions but have no answer. here is my code:
<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- Vue.js development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!--Axios dependency-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!--Bootstrap-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</head>
<body>
<h4>Uploading files with Vue.js</h4>
<div id="uploadSingle" class="container">
<h5>Single file uploading</h5>
<div class="large-12 medium-12 small-12 cell">
<div class="form-row" >
<div class="col-md-4 mb-3">
<input type="file" ref="file" id="customFile"
v-on:change="handleFileUpload($event)"
class="custom-file-input"
enctype="multipart/form-data">
<label class="custom-file-label" for="customFile">{{chosenFile}}</label>
</div>
</div>
<button v-on:click="submitFile()" class="btn btn-primary">Submit</button>
</div>
</div>
<div id="uploadMultiple" class="container">
<h5>Multiple files uploading</h5>
</div>
<script >
var app = new Vue({
el: '#uploadSingle',
data() {
return {
message: 'Hello Vue!',
singleFile: '',
refFile: '',
chosenFile: 'Chose file'
};
},
methods:{
handleFileUpload(event){
this.singleFile = event.target.files[0];
this.chosenFile=this.singleFile.name;
},
submitFile(){
var formData = new FormData();
formData.append("file", this.singleFile);
axios.post( '/single-file',
formData,{
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(function(){console.log('SUCCESS!')})
.catch((error) => console.log( error ) )
},
},
})
</script>
</body>
</html>
and controller file:
package com.yurets_y.webdevelopment_uploading_file_with_vue.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
#CrossOrigin("*")
#Controller
public class UploadController {
#Value("${upload.path}")
private String uploadPath;
#ResponseBody
#PostMapping(value="/single-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> uploadSingle(
#RequestParam(name="file", required = false) MultipartFile file
) {
System.out.println("uploaded");
System.out.println(file);
return ResponseEntity.ok().build();
}
}
I will be very grateful for the advice.
P.S.
when I use #RequestParam(name="file", required=true) MultipartFile file I get error POST http://localhost:8080/single-file 400 (Bad Request), It looks like spring cannot get MultipartFile file from FormData. At back end I don't get any errors, only MultipartFile file = null
After two days, that I spent to solve my promlem I fount a couple of working projects, compare all files and found, that my problem was in dependencies,
I used dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
And when I change dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Now it's working exactly how I need.

Spring and Hibernate Form Validation Error not show

This is my customer.java class using for as bean
package com.zeeshan.form;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
public class Customer {
private String firstName;
#NotNull(message="is required")
#Size(min=1)
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
CustomerController.java
package com.zeeshan.form;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
#RequestMapping("/customer")
public class CustomerController {
#RequestMapping("/showForm")
public String showFormModel(Model theModel) {
theModel.addAttribute("customer", new Customer());
return "customer-form";
}
#RequestMapping("/processForm")
public String processForm(#ModelAttribute("customer") #Valid Customer theCustomer, BindingResult theBindingresult) {
if(theBindingresult.hasErrors()) {
return "customer-form";
}
else {
return "customer-confirmation";
}
}
}
customer-form.jsp
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style>
.error{
color: red;
}
</style>
</head>
<body>
<h2>Customer Registeration Form</h2>
<form:form action="processForm" modelAttribute="customer">
First Name : <form:input path="firstName"/>
<br><br>
Last Name (*) : <form:input path="lastName"/>
<form:errors path="lastName" cssClass="error" />
<br><br>
<input type="submit" value="Submit" />
</form:form>
</body>
</html>
Hibernate validator doesn't work.
my code run properly but doesn't show any error
I am attaching file structure
following libraries are being used
hibernate version 6.0.2
spring version 5.0.6
The code looks fine. Reading your question, it seems that you might be a little confused between these two:
Hibernate ORM: Implementation of JPA
Hibernate Validator: Implementation of Bean Validation
So, for Bean Validation to work, you need to add Hibernate Validator in classpath. Means simply add it in dependencies of your build.gradle/pom.xml i.e. the build script of your build tool.

PrimeFaces p:ajax event=“change” not fired

I want to generate second selecOneMenu content when the user triggers an event on the first selecOneMenu, but it doesn't work.
Here is the navigation rule in face-config.xml
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{contact_.inscription_fournisseur}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>xhtml/Inscription_user.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
here is my index page : whene i click on S'inscrire it initiates the first list and redirects me to Inscription_user.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<!-- <link href="${request.contextPath}/css/style.css" rel="stylesheet" type="text/css"/>-->
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/ao.js" />
<h:head>
<title><h:outputText value="#{En_Fr.titre_page_index_fr}"/></title>
</h:head>
<body class="box_center" >
<div style="border:0px #888 solid; margin-top:40px; margin-left:10%; margin-right:10%">
<div class="box_fournisser">
<div class="titre_site" style="text-align:right">Accs fournisseur</div>
<div class="pwd_oublie font-label" style="text-align:right; color: #666;"> <label>Mot de passe oublié</label></div><div class="pwd_oublie font-label" style="text-align:right; text-decoration: underline;">
<label><h:form>
<h:commandLink action="#{contact_.inscription_fournisseur}" styleClass="pwd_oublie font-label" style="text-align:left; margin-left: 15px; text-decoration: underline;" >
S'inscrire
</h:commandLink>
</h:form>
</label>
</div></div>
<div class="statistic_ background_site_unselected " ><label class="nombre_statistic">1236</label><label class="label_statistic">appel d'offre</label></div>
<div class="statistic_ background_site_unselected " style="top:10%" ><label class="nombre_statistic">15985</label><label class="label_statistic">demande de devis</label></div>
<div class="statistic_ background_site_unselected " style="top:15%" ><label class="nombre_statistic">4859</label><label class="label_statistic">visite par moi</label></div></div>
</body>
</html>
my Inscription_user.xml
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<link href="../css/inscription.css" rel="stylesheet" type="text/css"/>
<h:head>
<title><h:outputText value="#{En_Fr.titre_page_index_fr}"/></title>
</h:head>
<body>
<div></div>
<f:view>
<h:form>
<h:messages>d :</h:messages>
<div class="ligne_inscription" >
<div class="label_inscription">Direction</div>
<div>
<p:selectOneMenu effect="fade" value="#{contact_.organisme.selectedDirection}" style="width:110;">
<f:selectItem itemLabel="Select One" itemValue="0"/>
<f:selectItems value="#{contact_.organisme.directions}" var="direction" itemLabel="#{direction.direction}" itemValue="#{direction.idDirection}"/>
<p:ajax update="lstfonct" listener="#{contact_.organisme.initFonction}" />
</p:selectOneMenu>
</div></div>
<div class="ligne_inscription" >
<div class="label_inscription">Fonction</div><div>
<p:selectOneMenu effect="fade" value="#{contact_.organisme.selectedFonction}" id="lstfonct">
<f:selectItem itemLabel="Select One" itemValue="0"/>
<f:selectItems value="#{contact_.organisme.fonctions}" var="fonction" itemLabel="#{fonction.fonction}" itemValue="#{fonction.idEmploi}"/>
</p:selectOneMenu>
</div></div>
<h:commandButton type="submit" value="Valider" action="#{contact_.inscription_choix_alerte()}" />
</h:form>
</f:view>
</body>
</html>
here is my bean Contact_
package beans;
// Generated 23 oct. 2012 21:51:42 by Hibernate Tools 3.2.1.GA
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import Dao.Emploi_dao;
/**
* Contact generated by hbm2java
*/
#ManagedBean(name="contact_")
#RequestScoped
public class Contact_ implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 493917875769565440L;
#ManagedProperty(value="#{organisme_}")
private Organisme_ organisme;
public Organisme_ getOrganisme() {
return organisme;
}
public void setOrganisme(Organisme_ organisme) {
this.organisme = organisme;
}
public String inscription_fournisseur() {
organisme.setDirections(Emploi_dao.List_direction());
return "success";
}
}
my bean organisation_
package beans;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import Dao.Activite_dao;
import Dao.Emploi_dao;
import Dao.Organisme_dao;
import hibernate.Activite;
import hibernate.Adresse;
import hibernate.Emploi;
import hibernate.Organisme;
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.event.AjaxBehaviorEvent;
/**
*
*
*/
#ManagedBean (name="organisme_")
#RequestScoped
public class Organisme_ implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 4579411552477526993L;
private List<Emploi> directions = new ArrayList <Emploi>(0);
private List<Emploi> fonctions = new ArrayList <Emploi>(0);
private String SelectedDirection;
private String SelectedFonction;
public List<Emploi> getDirections() {
return directions;
}
public void setDirections(List<Emploi> directions) {
this.directions = directions;
}
public List<Emploi> getFonctions() {
return fonctions;
}
public void setFonctions(List<Emploi> fonctions) {
this.fonctions = fonctions;
}
public String getSelectedDirection() {
return SelectedDirection;
}
public void setSelectedDirection(String selectedDirection) {
SelectedDirection = selectedDirection;
}
public String getSelectedFonction() {
return SelectedFonction;
}
public void setSelectedFonction(String selectedFonction) {
SelectedFonction = selectedFonction;
}
public void initFonction()
{
System.out.println("------------debut-----------");
fonctions=Emploi_dao.List_fonction(SelectedDirection);
}
}
there is one solution by removing the initialization on the directions list from the method inscription_fournisseur() on the contact_ bean class, and make it in the default constructor of the organisation_ bean class, in this case it works, but I don't prefer this solution, I prefer the first scenario, please help me.
youre using the wrong namespace <f:ajax> should be <p:ajax>
Instead u should change update to update what you want and set the selected value in a method defined by the listener to change your other selectMenu's data
see the showcase example

Resources