I'm using the selectOneMenu
component with the omnifaces converter. When I save my object in the database it works fine, but when I restore the information, it does not reflect on the screen, that is, the selectOneMenu
component is positioned in the first item or in the null item.
I've already confirmed with a log and a test inputText
and the information loads correctly. I am using selectItemsConverter
(I tried with SelectItemsIndexConverter
also) of Omnifaces 1.8.3 (I tried version 1.10 too).
AutomacaoEmail.java
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
...
@ManyToOne(fetch = FetchType.EAGER)
private ModeloEmail modeloEmail;
...
@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final AutomacaoEmail other = (AutomacaoEmail) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
@Override
public String toString() {
return String.format("%s[id=%d]", getClass().getSimpleName(), getId());
}
loadFromDatabaseMethod ()
List<ModeloEmail> modelosTemp = modeloEmailFacade.buscarTodos();
SelectItemsBuilder selectItemsBuilder = new SelectItemsBuilder();
if (modelosTemp != null) {
for (ModeloEmail modeloEmail : modelosTemp) {
selectItemsBuilder.add(modeloEmail, modeloEmail.getNome());
}
modelosEmails = selectItemsBuilder.buildList();
}
page.xhtml
<p:selectOneMenu value="#{automacaoEmailsController.automacaoEmail.modeloEmail}" converter="omnifaces.SelectItemsConverter">
<f:selectItem noSelectionOption="true" itemLabel="Selecionar um modelo"/>
<f:selectItems value="#{automacaoEmailsController.modelosEmails}"/>
</p:selectOneMenu>