-1

I saw there is a lot of similar questions and answers for my situation, but the problem is none of them worked for me! I'm trying to learn JSF and Spring boot and I've used some tutorials for them to manage this little simple code, but It does not work. The problem is Eclipse knows my Managed Bean and it's properties in jsf page, and my page renders perfectly, but when I enter numbers and click on any of my command buttons, the error appears! I thought maybe it cannot find target classes, so I tried to define it with

<build>
    <outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory>

but nothing different happened! Would you please help me? My pom.xml is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.tebmahani</groupId>
  <artifactId>Memorist</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencies>

    <!-- https://mvnrepository.com/artifact/javax/javaee-api -->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0.1</version>
        <!-- <scope>provided</scope> -->
    </dependency>   

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <!-- <scope>provided</scope> -->
    </dependency>  

    <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.20</version>
    </dependency>   

    <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.20</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <!-- <scope>provided</scope> -->
    </dependency>   

    <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.3</version>
       <!--  <scope>provided</scope> -->
    </dependency>   

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>2.0</version>
        <!-- <scope>provided</scope> -->
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.sun.el/el-ri -->
    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
    </dependency>


<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-catalina</artifactId>
    <version>9.0.35</version>
</dependency>

    <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <failOnMissingWebXml>true</failOnMissingWebXml>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

and my Managed Bean is:

package com.tebmahani.tinyCalculator;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named("tinyCalculator")
@RequestScoped
public class TinyCalculator {

private double _param1;
private double _param2;
private double _result;

public TinyCalculator() {}

public TinyCalculator(double param1, double param2, double result) {
    super();
    this._param1 = param1;
    this._param2 = param2;
    this._result = result;
}

public double getParam1() {
    return _param1;
}

public void setParam1(double param1) {
    this._param1 = param1;
}

public double getParam2() {
    return _param2;
}

public void setParam2(double param2) {
    this._param2 = param2;
}

public double getResult() {
    return _result;
}

public void setResult(double result) {
    this._result = result;
}

public String add() {
    this._result = _param1 + _param2;
    return "";
}

public String subtract() {
    this._result = _param1 - _param2;
    return "";
}

public String multiply() {
    this._result = _param1 * _param2;
    return "";
}

public String divide() {
    this._result = _param1 / _param2;
    return "";
}

}

TEB
  • 7
  • 1
  • 7
  • 99.99% certainty one of them will work for you. Most likely you did not fully read them or understood things wrong. But what you certainly do wrong is not showing and stating that you did all things mentioned in the otger questions. I'm going to vote to close this question as a duplicate if the most upvoted one. I you wnatvto prevent it getting closed, improve the question... a lot! – Kukeltje Jun 09 '20 at 17:47

1 Answers1

1

I'm going to write an answer that does not solve your problem but there is soo much wrong in your pom that it does not fit in a comment...

<outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory>

Using a src folder as an output folder is wrong... never do this. There is a target folder and if some things do not end up there for a weird reason, add them to the right target location, not a src folder. And checking if the classes were there or not was simple to do.

    <!-- https://mvnrepository.com/artifact/javax/javaee-api -->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0.1</version>
        <!-- <scope>provided</scope> -->
    </dependency>

This is the full blown java ee api, needed if you run a real java-ee server. It should then have scope of provided... Always. If you don't run a java-ee server but something like tomcat, it is waaay to broad There is a 'web profile' api but that should be for the light versions of real application servers, still not something like tomcat. So this api should be removed.

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <!-- <scope>provided</scope> -->
    </dependency>  

    <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.20</version>
    </dependency> 

So suppose the javaee api 8 jar is now present in your application. Then these two previous api's are already there, most likely in other versions (JSF on version 2.3, inject identical) which very likely cause problems.

    <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.20</version>
    </dependency>

There is a JSF 2.3 version and you have a 2.3 api. So you start your journey with 'old' versions already.

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <!-- <scope>provided</scope> -->
    </dependency>   

    <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.3</version>
       <!--  <scope>provided</scope> -->
    </dependency>   

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>2.0</version>
        <!-- <scope>provided</scope> -->
    </dependency>

The libraries mentioned here are also already in the javaee api, so duplication as well. And even if you did not have the java ee api, the only one needed would be the cdi one. The others should always be provided.

    <!-- https://mvnrepository.com/artifact/com.sun.el/el-ri -->
    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
    </dependency>


<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-catalina</artifactId>
    <version>9.0.35</version>
</dependency>

This one duplicates several of the previous apis again... And since they have different maven groupId, artifactId they will be include. Implementation ok but for some api's you now have three jars...

So please start with cleaning all this up... Using 'joinfaces' to have all this done for you is a good thing!

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Thank you @Kukeltje. Obviously I am very new in JSF and I don't know dependencies welll too. I seeked for answer for a long time and even read papers you mentioned above, and add things that I thought maybe help me. It seems I made it worse and should try from first step again. Thank you for good tips about dependencies. I will check and modify them and try again. – TEB Jun 10 '20 at 04:25
  • 1
    No problem, but most of this is not really jsf related. Try joinfaces and make sure you initially run your application in development mode – Kukeltje Jun 10 '20 at 05:54
  • Ok thanks. Is it OK if I delete this question? It seems It doesn't help anyone but me! :) – TEB Jun 12 '20 at 12:07
  • Just leave it. The manven things might help others... If 'the commuity' want's it to be deleted, it will. Cheers – Kukeltje Jun 12 '20 at 13:08
  • OK then. :) @Kukeltje . When I found the solution and it worked, then I'll tell it here. – TEB Jun 15 '20 at 15:41