您好我使用primefaces尝试了以下功能。 在我的xhtml中,我有一个输入字段,它接受输入并保存到db.A完成保存后,我将显示保存的数据在primefaces的数据表中。 到目前为止工作正常。现在我将单个选择添加到数据表。当用户单击该行时,我将使用所选数据更新相同的输入列。 为此,我使用以下代码
<h:form id="form">
<p:growl id="messages" />
<p:panel id="panel" header="Currency">
<h:panelGrid columns="2" id="currencyGrid">
<p:outputLabel value="Currency :"/>
<p:inputText value="#{currencyBean.currencyMaster.currDesc}"/>
</h:panelGrid>
<p:commandButton value="Add" action="#{currencyBean.saveCurrency}"
update="currencytable">
</p:commandButton>
<p:dataTable id="currencytable" var="cur"
value="#{currencyBean.currencyList}" widgetVar="dlg"
selection="#{currencyBean.currencyMaster}"
selectionMode="single" rowKey="#{cur.currId}">
<p:ajax event="rowSelect" listener="#{currencyBean.onRowSelect}"
update=":form:currencyGrid" />
<p:column headerText="ID" style="font-size:12px;">
<h:outputText value="#{cur.currId}" />
</p:column>
<p:column headerText="Description" style="font-size:12px;">
<h:outputText value="#{cur.currDesc}" />
</p:column>
</p:dataTable>
</h:form>
我的Bean代码是:
@managedBean
@viewScoped
@component
public class CurrencyBean implements Serializable{
private static final long serialVersionUID = 1L;
@Autowired
private CurrencyMaster currencyMaster;
private List<CurrencyMaster> currencyList;
public CurrencyMaster getCurrencyMaster() {
return currencyMaster;
}
public void setCurrencyMaster(CurrencyMaster currencyMaster) {
this.currencyMaster = currencyMaster;
}
public void saveCurrency(){
try{
currencyService.saveCurrency(currencyMaster);
}catch(Exception e){
e.printStackTrace();
}
}
@PostConstruct
public void currencyList(){
setCurrencyList(currencyService.getCurrencyList());
}
public void onRowSelect(SelectEvent event) {}
public void onRowUnselect(UnselectEvent event) {}
}
因此,当我点击currrencytable行时,输入字段正确填充并更新操作。
问题是当我直接将数据输入到输入列时,我的globalMaster属性将为null。
发生以下错误;
尝试使用null entity
创建saveOrUpdate事件我改变了bean的范围,但我找不到解决方案。
我找到了上述异常的更多解决方案,但我的问题是新值未设置为currencymaster。
在这种背景下我是否有任何错误。请指导我......