0
我有一個問題:當我將對象保存到數據庫時,它工作正常,但是當我想從數據庫中檢索它時,它不起作用。我使用selectItemsConverter
從Omnifaces 1.8.3(我試過1.10太)SelectItemsConverter從數據庫中預選的Omnifaces
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>
我也試過SelectItemsIndexConverter
。
我正在使用eclipselink。在我的情況下它從來沒有工作。它不適用於建議的修改。 –
然後到目前爲止所提供的信息中看不到問題。哪臺服務器?哪個PF版本?如果用'itemValue =「#{null}」'替換'noSelectionOption =「true」'會怎麼樣?如果用''替換'
'會怎麼樣? – BalusC
即時通訊使用: -Glassfish服務器4.x的 -PF 4.0.21 我已經除去這一行:'的'沒有工作。 我改成''..沒有工作。 我試過: '列表','列表','SelectItem []'..didnt的工作。 沒有錯誤發生。 我把一個inputText放在'select'旁邊,並且值顯示正確。 我創建了一個方法來充值和更新表單,但沒有奏效。 我重新創建了數據庫中的表格,並且僅使用相關組件創建了空白頁面。不工作。 –