Skip to content

Commit

Permalink
Atualizações
Browse files Browse the repository at this point in the history
  • Loading branch information
Roknauta committed Nov 27, 2024
1 parent 796cb8f commit af895d8
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 47 deletions.
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -19,7 +19,7 @@

<properties>
<java.version>21</java.version>
<joinfaces.version>5.2.3.1</joinfaces.version>
<joinfaces.version>5.4.0</joinfaces.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -85,6 +85,10 @@
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

</project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.roknauta.pilot.service.PessoaService;
import com.roknauta.pilot.util.JsfUtils;
import jakarta.faces.view.ViewScoped;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -11,7 +12,8 @@
import java.io.Serializable;

@Component
@RequestScope public class PessoaController implements Serializable {
@ViewScoped
public class PessoaController implements Serializable {

@Setter @Getter private String nome;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/roknauta/pilot/model/Pessoa.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Pessoa {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;

Expand Down
80 changes: 80 additions & 0 deletions src/main/java/com/roknauta/pilot/suport/Msg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.roknauta.pilot.suport;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.ApplicationScope;

import java.text.MessageFormat;
import java.util.HashMap;

@ApplicationScope // qdo for multilíngua tem que rever
@Component
/*
* Resolve referências internas de properties e cacheia todos os properties.
*/
public class Msg extends HashMap<String, String> {

@Autowired
@Lazy
private MessageSource messageSource;

private static final String START_REFERENCE = "${";
private static final String END_REFERENCE = "}";

/*
* obtém o valor da chave, priorizando o properties da configuração.
*/
private String _internalGet(final String key) {
try {
return messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
} catch (NoSuchMessageException e) {
return key;
}

}

private String _get(final String key) {

return _get(key, "");
}

private String _get(final String key, String cacheKey) {

if (super.containsKey(cacheKey)) {
// se a chave já está cacheada, retorna
return super.get(cacheKey);
} else {
// substitui as referências internas ${}
String tmpKey = key;
String message = _internalGet(tmpKey);
// procura referência ${} e substitui.
do {
tmpKey = StringUtils.substringBetween(message, START_REFERENCE, END_REFERENCE);
if (tmpKey == null) {
break;
}
message = message.replace(START_REFERENCE + tmpKey + END_REFERENCE, _internalGet(tmpKey));
} while (true);

// coloca a chave e valor no cache
super.put(cacheKey, message);

return message;
}
}

@Override
public String get(Object key) {
return this._get((String) key);
}

public String get(String key, Object... params) {
final MessageFormat format = new MessageFormat(this._get(key));
return format.format(params);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/roknauta/pilot/util/JsfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static public FacesContext getFacesContext() {
}

static public void addMessage(final String clientId, final FacesMessage.Severity severity, final String message) {
getFacesContext().addMessage(clientId, new FacesMessage(severity, message, null));
getFacesContext().addMessage(clientId, new FacesMessage(severity, null, message));
}

static public void addMessage(final FacesMessage.Severity severity, final String message) {
Expand Down
16 changes: 9 additions & 7 deletions src/main/resources/META-INF/resources/faces-config.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
<faces-config version="4.0" xmlns="https://jakarta.ee/xml/ns/jakartaee"
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">
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_0.xsd">
<application>
<resource-bundle>
<base-name>messages</base-name>
<var>msg</var>
</resource-bundle>
<locale-config>
<default-locale>pt_BR</default-locale>
<supported-locale>pt</supported-locale>
<supported-locale>pt_BR</supported-locale>
</locale-config>
<!-- <el-resolver>com.logOne.agendamento.web.support.EmptyToNullStringELResolver</el-resolver>-->
</application>
</faces-config>
48 changes: 31 additions & 17 deletions src/main/resources/META-INF/resources/index.xhtml
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
<?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:h="http://java.sun.com/jsf/html"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

<ui:composition template="layout/template.xhtml">
<ui:define name="content">
<h:form>
<p:messages id="messages" showDetail="true" closable="true">
<p:autoUpdate />
</p:messages>
<h:panelGrid columns="1">
<p:outputLabel value="#{msg['name']}" for="nome"/>
<p:inputText id="nome" value="#{pessoaController.nome}"/>
<p:commandButton value="#{msg['save']}" action="#{pessoaController.salvar}"/>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
<h:head>
<title>#{msg['title']}</title>
</h:head>
<h:body>
<h:form>
<p:messages id="messages" showDetail="true" closable="true">
<p:autoUpdate/>
</p:messages>
<p:tabView dynamic="true">
<p:tab title="Cadastro">
<p:panel header="Painel">
<h:panelGrid columns="1">
<p:outputLabel value="#{msg['name']}" for="@next"/>
<p:inputText id="nome" value="#{pessoaController.nome}"/>
</h:panelGrid>
<p:commandButton value="#{msg['save']}" action="#{pessoaController.salvar()}"/>
</p:panel>
</p:tab>
<p:tab title="Dat">
<!--<p:panel header="Painel">
<h:panelGrid columns="1">
<p:outputLabel value="#{msg['name']}" for="@next"/>
<p:inputText id="nome" value="#{pessoaController.nome}"/>
</h:panelGrid>
<p:commandButton value="#{msg['save']}" action="#{pessoaController.salvar()}"/>
</p:panel>-->
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/resources/layout/header.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
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:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<h:outputStylesheet library="css" name="custom.css"/>
<h:outputStylesheet library="css" name="primefaces-custom.css"/>
<!--<h:outputStylesheet library="css" name="custom.css"/>
<h:outputStylesheet library="css" name="primefaces-custom.css"/>-->
<title>#{msg['title']}</title>
</h:head>
</html>
8 changes: 3 additions & 5 deletions src/main/resources/META-INF/resources/layout/template.xhtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?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:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
Expand All @@ -12,14 +10,14 @@
<h:body>
<h:form id="locale">
<p:outputPanel style="float: right">
<p:selectOneMenu value="#{inicioController.language}">
<!--<p:selectOneMenu value="#{inicioController.language}">
<f:selectItems value="#{inicioController.locales}" var="bean" itemLabel="#{bean.displayLanguage}"
itemValue="#{bean.language}"/>
<p:column style="width:10%">
<h:graphicImage library="images" styleClass="ui-theme" value="pt.jpg"/>
&lt;!&ndash; <h:graphicImage library="images" styleClass="ui-theme" value="pt.jpg"/>&ndash;&gt;
</p:column>
<p:ajax event="change" listener="#{inicioController.changeLanguage}" update="@all"/>
</p:selectOneMenu>
</p:selectOneMenu>-->
</p:outputPanel>
</h:form>
<ui:insert name="content"/>
Expand Down
13 changes: 8 additions & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ spring:
thymeleaf:
enabled: false
datasource:
url: jdbc:hsqldb:hsql://localhost:9010/pilot
url: jdbc:hsqldb:hsql://localhost/pilot
username: sa
password: sa
password:
hikari:
driver-class-name: org.hsqldb.jdbc.JDBCDriver
transaction-isolation: 1
jpa:
hibernate:
ddl-auto: create-drop
ddl-auto: create
show-sql: true
database: hsql
jooq:
sql-dialect: org.hibernate.dialect.HSQLDialect

joinfaces:
primefaces:
theme: saga
faces:
project-stage: Development
myfaces:
resource-bundle-control: jsf
3 changes: 0 additions & 3 deletions src/main/resources/messages.properties

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/resources/messages_en.properties

This file was deleted.

0 comments on commit af895d8

Please sign in to comment.