Lombok in Eclipse Neon - eclipse

I would like to use lombok 1.16.10 in Eclipse Neon in an EE project. When I create the simplest managed bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import lombok.Getter;
import lombok.Setter;
#ManagedBean
#SessionScoped
class IndexBean
{
#Getter
#Setter
private String name;
}
And I refer to it in the simplest JSP page:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:inputText value="#{indexBean.name}"> </h:inputText>
</h:form>
</f:view>
</body>
</html>
The compiler can not see the IndexBean.name field in the JSP. If I write the accessors manually, there is no problem (the lombok.jar is in the classpath of the project). What I missed?
Another questions:
Is there any way to create a JSF facelets instead of a JSP pages in Eclipse? This is an old fashioned and hard to maintain form.
How can I set that the code generation prefer the annotations against the dependencies? When I create a managed bean it does not contain the annotations.
All of this is working in NetBeans like a charm!

Related

"javax.servlet.jsp.tagext.SimpleTagSupport" was not found on the Java Build Path slice_new.tag

On JBoss server I have a slice_new.tag file
<%# attribute name="action" %>
<%# attribute name="icon" %>
<%# attribute name="pageId" %>
<%# attribute name="cost" %>
<%# attribute name="co2" %>
<%# attribute name="unit" %>
<%# tag language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
<title>${action}</title>
</head>
<body> ...
But I get this compilation error
The superclass "javax.servlet.jsp.tagext.SimpleTagSupport" was not found on the Java Build Path slice_new.tag
Please help me to fix it?
I recently solved this using the instructions from this site. Assuming you are using Eclipse: Right click on your project, select “Properties” -> “Project Facets” -> “Runtimes” , select your runtime container. Done, rebuild and refresh your project. See the link for screenshots.
Alternatively, I found this other solution as well. The class in question is from jsp-api.jar, so I added it as a provided dependency to my build. In maven this looks like this. Note that a 'provided' scope means not to bundle it in the WAR as it is expected to be provided by the container (e.g. Tomcat)
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>

spring-boot-starter-web vs spring-boot-starter-thymeleaf

I try understand how spring boot is working with html pages. I started following the guide from spring.io. This guide is showing how to work with html page and view technology Thymeleaf. It has page:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
I have changed it to simple
<!DOCTYPE HTML>
<html>
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
</body>
</html>
And following spring boot reference documentation changed spring-boot-starter-thymeleaf(that is not needed now) to spring-boot-starter-web, after that I cant see web page. I see result:
There was an unexpected error (type=Not Found, status=404).
No message available.
When I come back my Gradle dependencies to thymeleaf all works fine.
Controller src/main/java/hello/GreetingController.java
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class GreetingController {
#RequestMapping("/greeting")
public String greeting() {
return "greeting";
}
}
Application src/main/java/hello/Application.java
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Can someone explain me what is difference between web and thymeleaf dependencies for this only HTML page from src/main/resources/templates/greeting.html?
It should also work with the gradle dependency org.springframework.boot:spring-boot-starter-web:1.2.5.RELEASE instead of org.springframework.boot:spring-boot-starter-thymeleaf:1.2.5.RELEASE.
spring-boot-starter-web functions like a set of basic dependencies needed to develop web-applications with spring. These basic dependencies are:
jackson-databind
hibernate-validator
spring-core
spring-web
spring-webmvc
spring-boot-starter
spring-boot-starter-tomcat
spring-boot-starter-thymeleaf is based on spring-boot-starter-web and adds some additional dependencies like the thymeleaf template engine:
thymeleaf-layout-dialect
spring-core
spring-boot-starter
spring-boot-starter-web
thymeleaf-spring4
You could look this up on mvnrepository.com (for spring-boot-starter-thymeleaf and spring-boot-starter-web).

JSP strange error in eclipse

I am a newbie in JSP and this is my first JSP.
<%#page import="java.util.Date"%>
<%# page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Hello</title>
</head>
<body>
<h2>Hi There!</h2>
<br/>
<h3>Date=<%= new Date() %>
</h3>
</body>
</html>
On the line where I am creating Date object, Eclipse is giving error as
Syntax error on token ")", delete this token
My Eclipse version is:
Eclipse Java EE IDE for Web Developers.
Version: Kepler Release
Build id: 20130614-0229
problem got solved when I added jsp-api.jar into build path of the project.

JSF 2 template itself shows style, but template client shows plain text without style

I am trying to use JSF Facelet template/Facelet template client first time. I am creating template and template client with Netbeans 7.2.1. When I run that created JSF project and call http://localhost:8080/jpaweb/template.xhtml I can see template style, but when I call client template http://localhost:8080/jpaweb/client.xhtml I see plain text without style. Both files are in the same directory and created by Netbeans wizard. Please, help me with this issue.
template.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Facelets Template</title>
</h:head>
<h:body>
<div id="top" class="top">
<ui:insert name="top">Top</ui:insert>
</div>
<div>
<div id="left">
<ui:insert name="left">Left</ui:insert>
</div>
<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
</h:body>
</html>
client.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:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:composition template="./template.xhtml">
<ui:define name="top">
Welcome, to my website
</ui:define>
<ui:define name="left">
My links
</ui:define>
<ui:define name="content">
This page is created for testing
</ui:define>
</ui:composition>
</body>
</html>
If you have Netbeans creating JSF project and JSF template and template client will get you this result. I tried in Netbeans 1.7.0 also. Same problem.
Edit: I run page not like http://localhost:8080/jpaweb/client.xhtml but likehttp://localhost:8080/jpaweb/faces/client.xhtml it worked. There is no "faces" directory in my project. Do we have to add "faces" to all JSF links?
Edit 2: I think netbeans auto-configures that all jsf files are kept in faces directory even there is no such directory in my project. And in Project properties -> Frameworks -> JavaServer Faces -> Configuration there is field JSF Servlet URL Pattern with value assigned /faces/*. I think that means one must call jsf files as if it is in faces directory. Trying to force it work as it appears in my project was a mistake :)
Solved. Changed value of Project properties -> Frameworks -> JavaServer Faces -> Configuration -> JSF Servlet URL Pattern from /faces/* to *.xhtml, and that worked OK.
Your client.xhtml content file is not properly composed. Don't include html tags, as JSF doesn't parse anything out from ui:composition tags here.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="./template.xhtml">
<ui:define name="top">
Welcome, to my website
</ui:define>
<ui:define name="left">
My links
</ui:define>
<ui:define name="content">
This page is created for testing
</ui:define>
</ui:composition>
I tested with your template and it works.

No tag "link" defined in tag library imported with prefix "h" | tomcat | eclipse

I was working in Netbeans IDE and switched to Eclipse.
I created a simple JSF 2.0 based using wizard in eclipse. The complete file is this.
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<h1>Hi, This is my JSF 2. Applicaiton</h1>
<br />
Click <h:link outcome="UserLogin">here</h:link> to go to login
</f:view>
</body>
</html>
When I deploted this app in tomcat 7.0 server, I am getting the following error message,
org.apache.jasper.JasperException: /index.jsp(14,6) No tag "link" defined in tag library imported with prefix "h"
In my IDE also I can see the
Help appreciated.
The <h:link> was new in JSF 2.0 and didn't exist in JSF 1.x. This error can thus have the following causes:
You've actually JSF 1.x libraries in your /WEB-INF/lib, not JSF 2.0 libraries.
Your faces-config.xml is declared as JSF 1.x instead of JSF 2.0. Ensure that it is declared conform JSF 2.0 spec.
<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">
A few quick questions:
Where is your JSF library located?
I think you meant more after:In my
IDE also I can see the which leads
into.
Eclipse is usually pretty good
at being able to find your tag
libraries. Is it complaining about
the use of these libraries in your
jsp editor page?
Let us know some more info about your setup first.
I'll throw out the obvious solution: You've lost the reference to your JSF jar(jsf-impl.jar). Including it in your Tomcat lib folder should fix it.
I'm in the middle of this problem too, I would like to find some solution, but I don't manage. As I found you are at the same step like me.
If you use facelets then you are able to see that tag, instead if you use normal "JSF" it gives the error as you mentioned.
You could try this procedure to solve your problem.
Try to understand how to configure facelets on your web app. For example for my webapp files that ends with *.xhtml are processed by facelets engine.
Rename file to *.xhtml.
Prepend this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
and
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
instead of normal html.
Remove any of the directive
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
Detailed instructions can be found here: http://wiki.apache.org/myfaces/MigrateFromJspToFacelets
Then you should be able to process h:link.