我有一个实体类,其中包含三种不同类型的字段,一种用于String
值,一种用于Integer
值,另一种用于Date
值。
@Column(name = "EVDE_VALUE_STR")
private String evdeValueStr;
@Column(name = "EVDE_VALUE_INT")
private Integer evdeValueInt;
@Column(name = "EVDE_VALUE_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date evdeValueDate;
我创建了一个JSF表单来从我的entity
创建新实例。如您所见,我根据我希望<h:inputText>
类存储的数据类型创建不同类型的entity
字段。
<h:form>
<ui:repeat value="#{mainWorkerMB.showAvailableEventDetailTypes()}" var="eventDetail">
<tr>
<td>
<h:outputText value="#{eventDetail.edtyId.edtyName}"></h:outputText>
</td>
<td>
<h:inputText id="str_tst" rendered="#{eventDetail.edtyId.edtyDetailType == 'STR'}"
styleClass="form-control" value="#{eventDetail.evdeValueStr}" >
</h:inputText>
<h:inputText id="int_tst" rendered="#{eventDetail.edtyId.edtyDetailType == 'INT'}"
styleClass="form-control number_mask" value="#{eventDetail.evdeValueInt}" >
</h:inputText>
<h:inputText id="dat_tst" rendered="#{eventDetail.edtyId.edtyDetailType == 'DAT'}"
styleClass="form-control datepicker_base" value="#{eventDetail.evdeValueDate}">
<f:convertDateTime pattern="yyyy.mm.dd" />
</h:inputText>
</td>
</tr>
</ui:repeat>
<p:commandButton styleClass="btn btn-primary" actionListener="#{mainWorkerMB.createNewEvent()}" value="Save" />
</h:form>
这是jsf生成的html:
<table class="table table-bordered table-hover">
<tr>
<td>
dummy str
</td>
<td>
<input id="j_idt57:j_idt64:0:str_tst" type="text" name="j_idt57:j_idt64:0:str_tst" class="form-control" />
</td>
</tr>
<tr>
<td>
dummy int
</td>
<td><input id="j_idt57:j_idt64:1:int_tst" type="text" name="j_idt57:j_idt64:1:int_tst" class="form-control" />
</td>
</tr>
<tr>
<td>dummy dat
</td>
<td><input id="j_idt57:j_idt64:2:dat_tst" type="text" name="j_idt57:j_idt64:2:dat_tst" class="form-control" />
</td>
</tr>
</table>
因为我看到所有类型的字段都正确生成了。
这是我的支持bean方法,它返回entity
个实例:
public List<BtrEventDetail> showAvailableEventDetailTypes() {
log.debug("invoked..");
List<BtrDEventDetailType> detailTypeList = sessionBucketMB.getAvailableEventDetailList();
detailList.clear();
if (detailTypeList != null) {
for (BtrDEventDetailType detTyInstance : detailTypeList) {
BtrEventDetail newDetail = new BtrEventDetail();
log.debug("setting detail instance detTyInstance: " + detTyInstance.getEdtyDetailType());
newDetail.setEdtyId(detTyInstance);
detailList.add(newDetail);
}
}
return detailList;
}
这是我的createNewEvent()
方法的第一行:
public void createNewEvent() {
log.debug("invoked...");
try {
newEvent = new NewEvenDTO();
for (BtrEventDetail detail : detailList) {
log.debug("detail: " + detail.getEdtyId().getEdtyName() + " value: " + detail.getEvdeValueStr());
}
..
..
点击“保存”按钮后,我在webconsole的POST
中看到了这一点:
javax.faces.partial.ajax true
javax.faces.source j_idt57:j_idt71
javax.faces.partial.execute @all
j_idt57:j_idt71 j_idt57:j_idt71
j_idt57 j_idt57
j_idt57:j_idt60 18
j_idt57:j_idt64:0:str_tst zzzz
j_idt57:j_idt64:1:int_tst 111
j_idt57:j_idt64:2:dat_tst 2017.11.11
javax.faces.ViewState -2967681892162587485:-6016297341844807895
这在我的支持bean中:
2017-09-12 09:13:19 createNewEvent DEBUG MainWorkerMB:277 - invoked...
2017-09-12 09:13:19 createNewEvent DEBUG MainWorkerMB:283 - detail: dummy str value: zzzz
2017-09-12 09:13:19 createNewEvent DEBUG MainWorkerMB:283 - detail: dummy int value: null
2017-09-12 09:13:19 createNewEvent DEBUG MainWorkerMB:283 - detail: dummy dat value: null
这意味着,只有我的String
字段发布数据。所有其他字段的值都为空。
更新<!/强>
在我的支持bean中,我之前只记录了StringValue。所以没有任何错误,我的支持bean日志中没有看到缺失的值。
log.debug("detail: " + detail.getEdtyId().getEdtyName() + " value: " + detail.getEvdeValueStr());
在我添加这两行后,我的值显示在支持bean日志中:
log.debug("detail: " + detail.getEdtyId().getEdtyName() + " value: " + detail.getEvdeValueInt());
log.debug("detail: " + detail.getEdtyId().getEdtyName() + " value: " + detail.getEvdeValueDate());
感谢您的帮助,对不起。
答案 0 :(得分:0)
检查eventDetail.edtyId.edtyDetailType
。它可能无法呈现。所有三个输入元素都不会同时渲染。