Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to integrate JSF2.2 page with REST endpoint class even with code written by you tried on Netbeans IDE8.1 using glassfish4.1.. #22

Open
ankitshende opened this issue Aug 18, 2016 · 0 comments

Comments

@ankitshende
Copy link

web.xml

javax.faces.PROJECT_STAGE Development javax.faces.CLIENT_WINDOW_MODE url
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>com.mycompany.movieplex7.rest.ApplicationConfig</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
com.mycompany.movieplex7.rest.ApplicationConfig /webresources/* 30 faces/index.xhtml

booking.xhtml

    <ui:composition template="./../WEB-INF/template.xhtml">

        <ui:define name="content">
            <h2>Pick a Movie</h2>
            <h:form prependId="false">
                <h:selectOneRadio value="#{booking.movieId}" layout="pageDirection" required="true">
                    <f:selectItems value="#{movieFacadeREST.all}" var="movie" itemValue="#{movie.id}" itemLabel="movie.name"/>
                </h:selectOneRadio>

                <h:commandButton id="shows" value="Pick a time" action="showtimes"/>
            </h:form>
        </ui:define>

    </ui:composition>

MovieFacadeREST
package com.mycompany.movieplex7.rest;

import com.mycompany.movieplex7.entities.Movie;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
*

  • @author justme
    */
    @stateless
    @path("movie")
    public class MovieFacadeREST extends AbstractFacade {

    @PersistenceContext(unitName = "movieplex7PU")
    private EntityManager em;

    public MovieFacadeREST() {
    super(Movie.class);
    }

    @post
    @OverRide
    @consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void create(Movie entity) {
    super.create(entity);
    }

    @put
    @path("{id}")
    @consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void edit(@PathParam("id") Integer id, Movie entity) {
    super.edit(entity);
    }

    @delete
    @path("{id}")
    public void remove(@PathParam("id") Integer id) {
    super.remove(super.find(id));
    }

    @get
    @path("{id}")
    @produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Movie find(@PathParam("id") Integer id) {
    return super.find(id);
    }

    @get
    @OverRide
    @produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List findAll() {
    return super.findAll();
    }

    @get
    @path("{from}/{to}")
    @produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
    return super.findRange(new int[]{from, to});
    }

    @get
    @path("count")
    @produces(MediaType.TEXT_PLAIN)
    public String countREST() {
    return String.valueOf(super.count());
    }

    @OverRide
    protected EntityManager getEntityManager() {
    return em;
    }

}

ApplicationConfig
package com.mycompany.movieplex7.rest;

import java.util.Set;
import javax.ws.rs.core.Application;

/**
*

  • @author justme
    */
    @javax.ws.rs.ApplicationPath("webresources")
    public class ApplicationConfig extends Application {

    @OverRide
    public Set<Class> getClasses() { Set> resources = new java.util.HashSet<>();
    addRestResourceClasses(resources);
    return resources;
    }

    /**

    • Do not modify addRestResourceClasses() method.
    • It is automatically populated with
    • all resources defined in the project.
    • If required, comment out calling this method in getClasses().
      */
      private void addRestResourceClasses(Set<Class<?>> resources) {
      resources.add(com.mycompany.movieplex7.rest.MovieFacadeREST.class);
      resources.add(com.mycompany.movieplex7.rest.SalesFacadeREST.class);
      resources.add(com.mycompany.movieplex7.rest.ShowTimingFacadeREST.class);
      resources.add(com.mycompany.movieplex7.rest.TheaterFacadeREST.class);
      resources.add(com.mycompany.movieplex7.rest.TimeslotFacadeREST.class);
      resources.add(org.glassfish.movieplex7.json.MovieReader.class);
      resources.add(org.glassfish.movieplex7.json.MovieWriter.class);
      }

}

Pom.xml

4.0.0
<groupId>com.mycompany</groupId>
<artifactId>movieplex7</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>movieplex7</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I have already tried this example three times but everytime its getting stuck with same problem...

Next the JSF2.2 fileuploadexample is also not working I have tried atleast twice once with my own code and second time I used your code as mentioned over here plz help me with both the issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant