|
39 | 39 | import jakarta.persistence.NamedNativeQuery; |
40 | 40 | import jakarta.persistence.OneToMany; |
41 | 41 | import jakarta.persistence.OrderBy; |
| 42 | +import jakarta.persistence.PostLoad; |
42 | 43 | import jakarta.persistence.SqlResultSetMapping; |
43 | 44 | import jakarta.persistence.Table; |
44 | 45 | import jakarta.persistence.Transient; |
@@ -153,10 +154,19 @@ public class FileMetadata implements Serializable { |
153 | 154 | @OneToMany (mappedBy="fileMetadata", cascade={ CascadeType.REMOVE, CascadeType.MERGE,CascadeType.PERSIST}) |
154 | 155 | private Collection<VariableMetadata> variableMetadatas; |
155 | 156 |
|
| 157 | + // A transient field is needed for JSF UI - validation errors on label do not get routed directly to the input for labelNoExtension, causing rollback. |
| 158 | + // With a separate transient field kept in sync with label, the validation can be done on the labelNoExtension field, which avoids the issue and allows proper validation. |
156 | 159 | @Transient |
157 | 160 | @ValidateDataFileLabel(message = "{filename.illegalCharacters}") |
158 | 161 | @NotBlank(message = "{filename.blank}") |
159 | 162 | String labelNoExtension; |
| 163 | + |
| 164 | + // Initialize the labelNoExtension from label after loading the entity |
| 165 | + @PostLoad |
| 166 | + public void postLoad() { |
| 167 | + getLabelNoExtension(); |
| 168 | + } |
| 169 | + |
160 | 170 | /** |
161 | 171 | * Creates a copy of {@code this}, with identical business logic fields, making the bi-drectional connections to the specified version. |
162 | 172 | * |
@@ -219,9 +229,6 @@ public String getLabelForOriginal() { |
219 | 229 | public FileMetadata() { |
220 | 230 | variableMetadatas = new ArrayList<VariableMetadata>(); |
221 | 231 | varGroups = new ArrayList<VarGroup>(); |
222 | | - int last = label.lastIndexOf("."); |
223 | | - labelNoExtension = (last == -1) ? label : label.substring(0, last); |
224 | | - |
225 | 232 | } |
226 | 233 |
|
227 | 234 | public String getDirectoryLabel() { |
|
0 commit comments