When trying to reach "hostname:8080/WebTest1/users" I get this error below:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/7.0.42
My web.xml looks thusly:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>WebTest1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<!-- Added these for the freemarker templates to work with the servlet -->
<servlet-name>freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
<!-- FreemarkerServlet settings: -->
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html; charset=UTF-8</param-value>
<!-- Forces UTF-8 output encoding! -->
</init-param>
<!-- FreeMarker settings: -->
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value>
<!-- 0 is for development only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<!-- <param-value>ISO-8859-1</param-value> -->
<param-value>UTF-8</param-value>
<!-- The encoding of the template files. -->
</init-param>
<init-param>
<param-name>number_format</param-name>
<param-value>0.##########</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>hello_servlet</servlet-name>
<servlet-class>com.fivetech.freemarker.examples.HelloServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>user_servlet</servlet-name>
<servlet-class>com.fivetech.webtest1.servlets.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello_servlet</servlet-name>
<url-pattern>/hello-ftl</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>user_servlet</servlet-name>
<url-pattern>/users</url-pattern>
</servlet-mapping>
<!--
Prevent the visiting of MVC Views from outside the servlet container.
RequestDispatcher.forward/include should and will still work. Removing
this may open security holes!
-->
<security-constraint>
<web-resource-collection>
<web-resource-name>FreeMarker MVC Views</web-resource-name>
<url-pattern>*.ftl</url-pattern>
</web-resource-collection>
<auth-constraint>
<!-- Nobody is allowed to visit these -->
</auth-constraint>
</security-constraint>
My bean User.java looks like:
package com.fivetech.webtest1.models;
public class User {
public String firstname;
public String lastname;
public String username;
public String password;
public User(String firstname, String lastname, String username, String password) {
this.firstname = firstname;
this.lastname = lastname;
this.username = username;
this.password = password;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstname() {
return this.firstname;
}
public String getLastname() {
return this.lastname;
}
public String getUsername() {
return this.username;
}
public String getPassword() {
return this.password;
}
}
The Servlet class (UserServlet.java) looks like:
package com.fivetech.webtest1.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UserServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/users.ftl").forward(request, response);
}
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//nothing here yet
}
}
I have a 404 from this but I'm sure I am missing something small but I haven't been able to figure it out yet. Any ideas?
Related
I am trying to build a simple Restful api which returns user details.
I have refered this link.
Following are my classes:
API Service class:
package com.demoapp;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.omg.Messaging.SyncScopeHelper;
#Path("/AddUserApi")
public class AddUserApi {
#GET
#Path("/users")
#Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
return UserUtil.getUserList();
}
}
Dao Class:
package com.demoapp;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
String name="";
String u_name="";
String password="";
String email="";
String user_type="";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getU_name() {
return u_name;
}
public void setU_name(String u_name) {
this.u_name = u_name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUser_type() {
return user_type;
}
public void setUser_type(String user_type) {
this.user_type = user_type;
}
}
Utils class:
package com.demoapp;
import java.util.List;
public class UserUtil {
public static String mysql_ip="jdbc:mysql://10.119.32.86/";
public static String metadata_database="haas";
public static String mysql_username="root";
public static String mysql_password="";
public static List<User> getUserList(){
List<User> users=new ArrayList<User>();
User user=new User();
user.setName("abc");
user.setU_name("ab_c");
user.setPassword("1234");
user.setUser_type("normal");
user.setEmail("abc#gmail.com");
users.add(user);
return users;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>UserAPI</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.demoapp</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
I have downloaded the jersey jar from the site and extracted 3 folders and added those jars in build path.
I have done everything according to the tutorial.
Still its showing this error:
Could you please suggest a way of solving this issue?
Provided the server is up and running and the application is deployed without errors, your endpoint should be available in the following URL:
http://[host]:[port]/[context]/rest/AddUserApi/users
Where:
[context] is the name of your WAR file (without the .war extension).
/rest comes from the web.xml: <url-pattern>/rest/*</url-pattern>.
/AddUserApi comes from the #Path annotation on the AddUserApi class.
/users comes from #Path annotation on the getUsers() method.
Your URL should be: localhost:8082/UserAPI/rest/AddUserApi/users
I'm getting this error: MessageBodyWriter not found for media type=application/json, type=class SalesService.Item, genericType=class SalesService.Item.
What I want to do is let my restful service method return a custom object, in this case object: Item. But im getting this error and in the browser error 500.
Im using JAX-RS version 2.25.1 libraries in netbeans
I know there are allot of questions like this but i could not find any solution that worked exactly for me.
Thanks in advance!
WEB.XML
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>examples.rest.school</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>SalesService</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Resources Service class:
package SalesService;
import java.util.ArrayList;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import DB.DBConnecter;
import javax.ws.rs.PathParam;
import java.util.List;
import javax.ws.rs.Consumes;
#Path("Sales")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public class SalesResources {
private final DBConnecter dbConnector;
public SalesResources() {
dbConnector = new DBConnecter();
}
#GET
#Path("session/{sessionID}")
#Produces(MediaType.APPLICATION_JSON)
public Item GetItem(#PathParam("sessionID") String sessionID) {
List<Item> items = new ArrayList<>();
if(dbConnector.CheckSessionID(sessionID)){
items = dbConnector.GetItems();
return items.get(0);
}
return new Item();
}
}
Item class:
package SalesService;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Item {
private int id;
private String name;
private int quantity;
private double price;
private String type;
public Item(){}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void AddQuantity() {
this.quantity = quantity + 1;
}
public void RemoveQuantity() {
this.quantity = quantity - 1;
}
public Item(int id, String name, int quantity, double price, String type) {
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
this.type = type;
}
}
StackTrace
04-Mar-2017 21:03:06.273 SEVERE [http-nio-8080-exec-1] org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/json, type=class SalesService.Item, genericType=class SalesService.Item.
This was resolved adding
org.codehaus.jackson.jaxrs
In web.xml like this
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>examples.rest.school</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>SalesService,org.codehaus.jackson.jaxrs</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
After adding 4 jackson .JAR files which are these
And also adding them in libraries folder (reference)
I'm trying to send JSON data to my RESTful web service. Configuration is working fine for a simple GET type. Only the issue is for POST type.
My Angular code
var app = angular.module('myApp', []);
app.controller('MyController', function($scope,$http) {
$scope.pushDataToServer = function() {
$http({
method: 'POST',
url: 'rest/Board/autoSave',
headers: {'Content-Type': 'application/json'},
data:'{"firstName":"Syed", "lastName":"Chennai"}',
}).success(function (data){
$scope.status=data;
}).error(function(data, status, headers, config) {
alert("error");
});
};
});
My Java code
#Path("/Board")
public class BoardAutoSaveService {
#POST
#Path("/autoSave")
#Consumes({MediaType.APPLICATION_JSON})
#Produces({MediaType.TEXT_PLAIN})
public String autoSave(Message msg) throws Exception{
System.out.println("Calling Autosave.");
System.out.println("First Name = "+msg.getFirstName());
System.out.println("Last Name = "+msg.getLastName());
return null;
}
}
Message class
package com.intu;
import java.util.Date;
public class Message {
private String firstName;
private String lastName;
private int age;
private Date date;
private String text;
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;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>iNTU-1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.dao</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Am I missing anything?
The error is
SEVERE: A message body reader for Java class com.intu.Message, and Java type class com.intu.Message, and MIME media type application/json was not found.
The registered message body readers compatible with the MIME media type are:
application/json ->
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
*/* ->
You only have the default Jersey JSON providers, which require #XmlRootElement on your model class. You can see the available providers, one of which is the JSON**RootElement**Provider
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
This provider is used to (de)serialize classes annotated with #XmlRootElement.
If you have the following dependency
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
then it should also pull in the Jackson provider, which doesn't require #XmlRootElement, but you still need to configure Jersey to use Jackson instead of its default provider. To configure it you need to add this to your web.xml Jersey servlet configuration, as seen here
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
Or if you are not using a web.xml, add the following inside your ResourceConfig subclass constructor
public class AppConfig extends PackagesResourceConfig{
public AppConfig() {
getProperties().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
}
}
I now use is jersey2.13 and spring4.X, and can't get jersey bean validation to work.
The following is my configuration and code snippets:
web.xml
<servlet>
<!-- jersey ServletContainer -->
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- jersey resource packages-->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.wordnik.swagger.jaxrs.json,
com.ghca.easyview.server.api.resource
</param-value>
</init-param>
<!-- jersey provider classnames-->
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
com.wordnik.swagger.jersey.listing.ApiListingResourceJSON,
com.wordnik.swagger.jersey.listing.JerseyApiDeclarationProvider,
com.wordnik.swagger.jersey.listing.JerseyResourceListingProvider
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.wadl.disableWadl</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.ghca.easyview.server.api.context.JerseyApplication</param-value>
</init-param>
<!-- jersey beanValidation -->
<init-param>
<param-name>jersey.config.beanValidation.enableOutputValidationErrorEntity.server</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/se/rest/*</url-pattern>
</servlet-mapping>
<!-- jersey swagger UI -->
<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://10.143.132.99:4000/api/se/rest</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Bootstrap</servlet-name>
<servlet-class>com.ghca.easyview.server.api.plugin.swagger.Bootstrap2</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
JerseyApplication.java:
package com.ghca.easyview.server.api.context;
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.ContextResolver;
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.validation.ValidationConfig;
import org.glassfish.jersey.server.validation.internal.InjectingConstraintValidatorFactory;
/**
* ContactCard application configuration
* JAX-RS application
*/
public class JerseyApplication extends ResourceConfig{
public JerseyApplication(){
property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
property(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
property(ServerProperties.BV_FEATURE_DISABLE, true);
// Resource Package Address
packages("com.ghca.easyview.server.api.resource");
//Validation.
register(ValidationConfigurationContextResolver.class);
}
/**
*/
public static class ValidationConfigurationContextResolver implements ContextResolver<ValidationConfig>{
#Context
private ResourceContext resourceContext;
#Override
public ValidationConfig getContext(final Class<?> type) {
return new ValidationConfig().constraintValidatorFactory(resourceContext.getResource(InjectingConstraintValidatorFactory.class));
}
}
}
PersonResource.java:
package com.ghca.easyview.server.api.resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.springframework.stereotype.Component;
import com.ghca.easyview.server.api.request.validation.model.Person;
import com.wordnik.swagger.annotations.Api;
#Component
#Path("/person")
#Api(value = "/person", description = "person", position = 1)
#Produces({ "application/json", "application/xml" })
public class PersonResource {
#POST
public Response create(#Valid #NotNull Person person) {
System.out.println(person);
return Response.ok().build();
}
}
Person.java:
package com.ghca.easyview.server.api.request.validation.model;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
public class Person {
#NotNull
private Integer id;
#NotNull
#Length(min = 2, max = 20)
private String name;
#Email(message = "{contact.wrong.email}", regexp = "[a-zA-Z0-9._%-]+#[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")
private String email;
#Pattern(message = "{contact.wrong.phone}", regexp = "[0-9]{3,9}")
private String phone;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
#Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", email=" + email
+ ", phone=" + phone + "]";
}
}
Not sure why you are disabling everything, but after testing, removing the disable properties makes it work
//property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
//property(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
//property(ServerProperties.BV_FEATURE_DISABLE, true);
Those properties are false by default, which allows auto-discovery. You are disabling it.
I am working with Spring and I have a problem with a bean, here is my code:
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.grh.bo.ICollaborateurBo;
import com.grh.bo.IUserBo;
import com.grh.entities.Collaborateur;
#Component
#Scope("session")
public class CollaborateurBean implements Serializable {
private static final long serialVersionUID = 1L;
#Autowired
private ICollaborateurBo collaborateurBo;
private String nom;
private String prenom;
private String sflag = "";
private int currentProjectIndex;
private int page = 1;
public List<Collaborateur> listOfCollaborateur = new ArrayList<Collaborateur>();
private Collaborateur Collaborateurr = new Collaborateur();
List<Collaborateur> lis = new ArrayList<Collaborateur>(collaborateurBo.getAllCollaborateur());
#PostConstruct
public void init() {
setListOfCollaborateur(recupererCollaborateur());
Collaborateurr=new Collaborateur();
}
public List<Collaborateur> getLis() {
return collaborateurBo.getAllCollaborateur();
}
public void setLis(List<Collaborateur> lis) {
this.lis = lis;
}
public List<Collaborateur> getCollaborateurList() {
return collaborateurBo.getAllCollaborateur();
}
private List<Collaborateur> recupererCollaborateur() {
List<Collaborateur> ps = collaborateurBo.getAllCollaborateur();
return ps;
}
public CollaborateurBean() {
super();
}
public CollaborateurBean(ICollaborateurBo collaborateurBo, String nom,
String prenom, String sflag, int currentProjectIndex, int page,
List<Collaborateur> listOfCollaborateur,
Collaborateur collaborateurr, List<Collaborateur> lis) {
super();
this.collaborateurBo = collaborateurBo;
this.nom = nom;
this.prenom = prenom;
this.sflag = sflag;
this.currentProjectIndex = currentProjectIndex;
this.page = page;
this.listOfCollaborateur = listOfCollaborateur;
Collaborateurr = collaborateurr;
this.lis = lis;
}
public Collaborateur getCollaborateurr() {
return Collaborateurr;
}
public void setCollaborateurr(Collaborateur collaborateurr) {
Collaborateurr = collaborateurr;
}
public List<Collaborateur> getListOfCollaborateur() {
return listOfCollaborateur;
}
public void setListOfCollaborateur(List<Collaborateur> listOfCollaborateur) {
this.listOfCollaborateur = listOfCollaborateur;
}
public String getSflag() {
return sflag;
}
public void setSflag(String sflag) {
this.sflag = sflag;
}
public void setCollaborateurBo(ICollaborateurBo collaborateurBo) {
this.collaborateurBo = collaborateurBo;
}
public ICollaborateurBo getCollaborateurBo() {
return collaborateurBo;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getCurrentProjectIndex() {
return currentProjectIndex;
}
public void setCurrentProjectIndex(int currentProjectIndex) {
this.currentProjectIndex = currentProjectIndex;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
in this page collaborateur.xhtml i Can't display data from my DATABASE collaborateur.xhtml:
<h:dataTable value="#{CollaborateurBean.getLis()}" var="item">
<h:column>
<h:outputText value="#{item.nom}" />
</h:column>
<h:column>
<h:outputText value="#{item.prenom}" />
</h:column>
</h:dataTable>
When I test the collaborateurBo i display data from my DATABASE. This is the code that gives data from database:
<h:dataTable value="#{collaborateurBo.getAllCollaborateur()}" var="item">
<h:column>
<h:outputText value="#{item.nom}" />
</h:column>
<h:column>
<h:outputText value="#{item.prenom}" />
</h:column>
</h:dataTable>
This means that the problem is in the Collaborateur bean not in collaborateurBo or CollaborateurDao.
Here my configurations :
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>GRH</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/web-application-config.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/web-application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>spring/main-flow</welcome-file>
</welcome-file-list>
<error-page>
<error-code>403</error-code>
<location>/spring/acces-interdit-flow</location>
</error-page>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>ruby</param-value>
</context-param>
</web-app>
faces-config:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<resource-bundle>
<base-name>com.grh.prop.messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
<managed-bean>
<managed-bean-name>currentDate</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
web-application-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- Scans for application #Components to deploy -->
<context:component-scan base-package="org.springframework.webflow.samples.booking" />
<context:component-scan base-package="com.grh" />
<!-- Database Configuration -->
<import resource="DataSource.xml" />
<import resource="Hibernate.xml" />
<!-- Spring Configuration -->
<import resource="webmvc-config.xml" />
<import resource="webflow-config.xml" />
<!-- Spring security 3.0.5 -->
<import resource="security-config.xml" />
</beans>
Please help me, thanx in advance,