terça-feira, 23 de março de 2021

Mensagens de erros comuns do Java JSF

Segue lista de erros comuns ao iniciar um projeto em JAVA com JSF + PRIMEFACES com o TOMCAT 


  1. Factory 'javax.faces.lifecycle.ClientWindowFactory


Erro do Tomcat na Console:

com.jun.faces.config.ConfigurationException: Factory 'javax.faces.lifecycle.ClientWindowFactory' was not configured properly.



Solução:

Esse erro ocorre quando esquece de criar o "beans.xml".

Criar o "/src/main/webapp/WEB-INF/beans.xml"


<?xml version="1.0" encoding="UTF-8"?>

<beans 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/beans_2_0.xsd"

    version="2.0" bean-discovery-mode="annotated">

</beans>



  1. java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet


No Log:

GRAVE: Servlet [Faces Servlet] in web application [/com.example] threw load() exception

java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet


Solução: 

Após clicar em "Maven -> Update" esse erro pode ocorrer, porque o projeto não consegue mais encontrar as bibliotecas baixadas pelo Maven.

Adicionar as bibliotecas do Maven do Path:

Clique direito no projeto -> Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Maven Dependencies.




Isso ocorre no Updade do Maven porque o pom.xml deve especificar a versão 1.8 do java, sem essa configuração durante o "Maven Update" ele volta sozinho para versão 1.5 nas configurações.


<!-- Parâmetros de execução -->

<build>

<!-- Nome do arquivo empacotado (.war) que você vai entregar para o cliente -->

<finalName>CursoJSF</finalName>

<plugins>

<!-- Compilador do Maven na versão 3.3 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.8.1</version>

      <!-- Compilador do Java na versão 8 -->

<configuration>

<source>1.8</source>

<target>1.8</target>

</configuration>

</plugin>

</plugins>

</build>


Verificar aba "Problems" do Eclipse:

Mensagens do tipo "Cannot change version of project facet Dynamic Web Module to x.x" é causado porque o Eclipse muda a versão do web-app automaticamnete no web.xml após um "Maven Update".

Verifique se a versão do web-app está em 4_0, senão corrija no "web.xml"


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

id="WebApp_ID" version="4.0">



TOMCAT NÃO INICIA - ERRO  WELD-000075

APARECE NO LOG:

Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field:  [EnhancedAnnotatedFieldImpl] public projetoweb.ComandoExterno.saidaDoComando


Explicação:

Erro: 

The motivation of WELD-000075 is technical. Access to a public field cannot be proxied. So a bean is required to be either pseudo scoped (@dependent, @singleton) or to guarantee access through public methods (which shouldn't be hard to achieve).

 

Resumindo:

EXISTE UM ATRIBUTO PÚBLICO NO BEAN QUE CAUSA UM ERRO NO CDI.

 

ERRADO:

public class ComandoExterno {

public String saidaDoComando;

 

 

Solução:

TODOS OS ATRIBUTOS DO BEAN DEVEM SER PRIVATE COM ACESSO ATRAVÉS DE GET SET!!!


CERTO:


public class ComandoExterno {

           private String saidaDoComando;




ERRO WELD-000072 - Bean declaring a passivating scope must be passivation capable.


O Bean quando é @SessionScoped ou @ViewScoped é OBRIGATÓRIO implementar Serializable!!!



Solução: SEMPRE IMPLEMENTAR SERIALIZABLE EM TODOS OS BEANS!!!


@Named

@SessionScoped

public class BotaoTeste implements Serializable{

...











segunda-feira, 15 de março de 2021

Jshell problem with PageUp and PageDown not working on Linux Ubuntu/CentOS

A very common problem in Java Shell Tool (jshell) are the Page-Up and Page-down keyboard keys that do not work properly when accessing through SSH terminal.

When you press page-up key, the terminal show "[1~" characters and when you press page-down key, the terminal show "[4~" characters. 

 This problem happended to me in Linux Ubuntu and Centos distributions, and I believe that it must occur with almost all other distributions. 

TROUBLESHOOTING

1) Temporary solution: 
Change TERM variable to "linux" before start jshell.

$ TERM=linux

$ jshell 
|  Welcome to JShell -- Version 11.0.10
|  For an introduction type: /help intro
jshell>   // Now PgUp and PgDown works. 


2) Permanent solution:
Change TERM variable at terminal startup in ~/.bashrc


 
$ echo "e
xport TERM=linux"  >> ~/.bashrc



Now close your SSH connection, and connect again. 
Show TERM envirounment variable must be "linux"

$ echo $TERM

linux

Start jshell:

 $ jshell 

|  Welcome to JShell -- Version 11.0.10
|  For an introduction type: /help intro
jshell>   // Now PgUp and PgDown works. 


3) Alternative solution:
Use terminal multiplexers like screen or tmux:

$ screen
$ jshell 

|  Welcome to JShell -- Version 11.0.10
|  For an introduction type: /help intro
jshell>   // Now PgUp and PgDown works. 








Atualização DELL INSPIRON 15R com Update para Windows 10 22H2 travado em 61% ou 99%

 Como atualizar notebook DELL INSPIRON 15R com Windows 10 que está com a atualização travada em 61% ou 99%: Processo de atualização manual d...