@margor90 @Koziołek
Fragment widoku (id forma i tabów)
<h:form id="wniosekForm">
<p:tabView id="tabView">
<p:tab title="Wniosek" id="wniosekTab">
Fragment widoku (blok messages)
<p:messages showDetail="true" showSummary="true"/>
public void zatwierdz(WniosekDTO wniosekDTO) {
Set<ConstraintViolation<WniosekDTO>> violations = validator.validate(wniosekDTO, ZatwierdzWniosekGroup.class);
for (ConstraintViolation<WniosekDTO> violation : violations) {
addErrorMessage(formIdPrefix + violation.getPropertyPath(), violation.getMessage());
System.out.println(formIdPrefix + " " + violation.getPropertyPath() + " " + violation.getMessage());
}
if (violations.isEmpty()) {
//save czegos tam
addInfoMessage("", "success");
} else {
addErrorMessage("", violations.size() + " error(s)");
}
}
private void addErrorMessage(String id, String msg) {
addMessage(id, FacesMessage.SEVERITY_ERROR, "Error", msg);
}
private void addInfoMessage(String id, String msg) {
addMessage(id, FacesMessage.SEVERITY_INFO, "Info", msg);
}
private void addMessage(String clientId, FacesMessage.Severity severity, String summary, String detail) {
FacesMessage message = new FacesMessage(severity, summary, detail);
FacesContext.getCurrentInstance().addMessage(clientId, message);
}
Pola oznaczane mam mniej więcej tak:
@NotNull(groups = ZatwierdzWniosekGroup.class)
@NotBlank(groups = ZatwierdzWniosekGroup.class)
private String nazwa= "Przykładowa wartość nazwy";
I wygląda to tak, że pojawia mi się wszystko w bloku messages, ale nie podświetla mi pól na czerwono i w bloku messages nie ma nazw pól tylko jest tak:
Errormay not be null
Errormay not be null
Errormust be true
Errormust be true
Errormust be true
Errormay not be null
ErrorMusi być zaznaczone
Errormay not be empty
Errormust be true
Error9 error(s)
Co mam nie tak?
Jak zrobię tak:
private void addMessage(String clientId, FacesMessage.Severity severity, String summary, String detail) {
FacesMessage message = new FacesMessage(severity, summary, detail);
FacesContext.getCurrentInstance().addMessage(clientId, message);
UIViewRoot uiViewRoot = FacesContext.getCurrentInstance().getViewRoot();
if (!clientId.isEmpty()) {
UIComponent component = uiViewRoot.findComponent(clientId);
if (component instanceof UIInput) {
UIInput uiInput = (UIInput) component;
uiInput.setValid(false);
}
}
}
To nie działa mi potem button wyczyść :) I zostają errory.