jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

constraint validation error messages translation not found #16525

Closed yelhouti closed 11 months ago

yelhouti commented 3 years ago
Overview of the issue

Validation in JHipster apps is both done client and server side which great, and allows to handle cases where the validation can't always be insured in the client. In that case we would expect constraint validations to return messages that match what the client/frontend can translate. For example this code for angular: https://github.com/jhipster/generator-jhipster/blob/198ac86f251491daa85e4501f7f1bf304040b4b7/generators/client/templates/angular/src/main/webapp/app/shared/alert/alert-error.component.ts.ejs#L75-L84 Which tries to translate what is in message.

Unfortunately, the @NotNull java annotation has a default message that is automatically translated server side, and the message contains must not be null which results in a message that client is unable to translate.

Motivation for or Use Case

Better error handling server side

Reproduce the error

create a new app with a sample jdl, this for example: https://github.com/jhipster/generator-jhipster/blob/main/test-integration/samples/jdl-default/app.jdl

change the client to remove a client side validation, for example in the department-update.component.ts remove the validator for name, the click on save.

It doesn't show that the error is not null, but the code tries to show that and fails gracefully.

Suggest a Fix

change default translation for messages when translation is enabled to @NotNull => "NotNull" the client will then handle it automatically.

JHipster Version(s)

7.2.0

JHipster configuration

INFO! Using JHipster version installed globally

JHipster Version(s)
jhipster-sample-application@0.0.1-SNAPSHOT /home/yelhouti/jhipster/test
└── generator-jhipster@7.2.0 
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "clientFramework": "angularX",
    "serverPort": "8080",
    "serviceDiscoveryType": false,
    "skipUserManagement": false,
    "withAdminUi": true,
    "baseName": "jhipsterSampleApplication",
    "buildTool": "maven",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "jhiPrefix": "jhi",
    "languages": ["en", "fr"],
    "messageBroker": false,
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "skipClient": false,
    "testFrameworks": ["gatling", "cypress"],
    "websocket": false,
    "enableGradleEnterprise": false,
    "gradleEnterpriseHost": "",
    "applicationType": "monolith",
    "packageName": "tech.jhipster.sample",
    "packageFolder": "tech/jhipster/sample",
    "nativeLanguage": "en",
    "jhipsterVersion": "7.2.0",
    "skipServer": false,
    "clientPackageManager": "npm",
    "dtoSuffix": "DTO",
    "entitySuffix": "",
    "reactive": false,
    "clientTheme": "none",
    "clientThemeVariant": "",
    "applicationIndex": 0,
    "entities": [
      "Bank",
      "BankAccount",
      "TheLabel",
      "Operation",
      "Department",
      "JobHistory",
      "Job",
      "Employee",
      "Location",
      "Task",
      "GoldenBadge",
      "SilverBadge",
      "Identifier",
      "Country",
      "Region"
    ],
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "blueprints": [],
    "otherModules": [],
    "pages": [],
    "creationTimestamp": 1633233867332,
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "devServerPort": 4200,
    "lastLiquibaseTimestamp": 1633234767000
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Bank {
  bankNumber Integer
}
entity BankAccount {
  name String required
  bankNumber Integer
  agencyNumber Long
  lastOperationDuration Float
  meanOperationDuration Double
  balance BigDecimal required
  openingDay LocalDate
  lastOperationDate Instant
  active Boolean
  accountType BankAccountType
  attachment AnyBlob
  description TextBlob
}
entity TheLabel {
  labelName String required minlength(3)
}
entity Operation {
  date Instant required
  description String
  amount BigDecimal required
}
entity Department {
  name String required
  description TextBlob
  advertisement AnyBlob
  logo ImageBlob
}
/**
 * JobHistory comment.
 */
entity JobHistory {
  startDate ZonedDateTime
  endDate ZonedDateTime
  language Language
}
entity Job {
  title String minlength(5) maxlength(25)
  type JobType
  minSalary Long
  maxSalary Long
}
/**
 * The Employee entity.\nSecond line in javadoc.
 */
entity Employee {
  /**
   * The firstname attribute.
   */
  firstName String
  lastName String
  email String
  phoneNumber String
  hireDate ZonedDateTime
  salary Long
  commissionPct Long
}
entity Location {
  streetAddress String
  postalCode String
  city String
  stateProvince String
}
entity Task {
  title String
  description String
}
entity GoldenBadge {
  name String
}
entity SilverBadge {
  name String
}
entity Identifier {
  name String required unique
}
entity Country {
  name String
}
entity Region {
  name String
}
enum BankAccountType {
  CHECKING (checking_account),
  SAVINGS (savings_account),
  LOAN (loan_account)
}
enum Language {
  FRENCH,
  ENGLISH,
  SPANISH
}
enum JobType {
  BOSS,
  SLAVE
}

relationship OneToOne {
  Department{location} to Location
  Employee{user(login)} to User
}
relationship OneToMany {
  BankAccount{operation} to Operation{bankAccount(name)}
  Employee{job} to Job{emp(lastName)}
  /**
   * A relationship
   */
  Department{employee} to
  /**
   * Another side of the same relationship,
   */
  Employee{department}
  Location{country} to Country{location}
  Country{area(name)} to Region{country}
}
relationship ManyToOne {
  BankAccount{user(login)} to User
  Employee{manager(lastName)} to Employee
  Employee{sibag(name) required} to SilverBadge
  Employee{gobag(name) required} to GoldenBadge
  GoldenBadge{iden(name) required} to Identifier
  SilverBadge{iden(name) required} to Identifier
}
relationship ManyToMany {
  Bank{account} to BankAccount{bank}
  Operation{theLabel(labelName)} to TheLabel{operation}
  JobHistory{department} to Department{history}
  JobHistory{job} to Job{history}
  JobHistory{emp(firstName)} to Employee{history}
  Job{chore(title)} to Task{linkedJob(title)}
}

dto BankAccount, Department, Employee, Location, GoldenBadge, SilverBadge, Identifier, Country, Region with mapstruct
service BankAccount, Location, Country with serviceImpl
service TheLabel, Department, Employee, GoldenBadge, SilverBadge, Identifier, Region with serviceClass
angularSuffix BankAccount with mySuffix
filter BankAccount, Employee
clientRootFolder BankAccount, TheLabel, Operation with test-root
paginate TheLabel, Job with pagination
paginate Operation, JobHistory, Employee with infinite-scroll

Environment and Tools

openjdk version "1.8.0_292" OpenJDK Runtime Environment (build 1.8.0_292-b10) OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

git version 2.31.1

node: v14.18.0

npm: 6.14.15

Docker version 20.10.7, build f0df350

docker-compose version 1.29.0, build 07737305

Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

github-actions[bot] commented 11 months ago

This issue is stale because it has been open for too long without any activity. Due to the moving nature of jhipster generated application, bugs can become invalid. If this issue still applies please comment otherwise it will be closed in 7 days