我是Jsf的新手,我正在尝试在Jsf应用程序中创建以下功能。
以下是我目前开发的代码。请原谅任何错误,因为它仍然是WIP,但我完全愿意接受任何改进代码的建议。
<h:dataTable value="#{personInfo.profileForm.serviceDateList}" var="serviceDateObj" id="servideTblId">
<h:column>
<p:calendar id="#{serviceDateObj}" binding="#{bindingVar}" value="#{serviceDateObj.fromDate}" size="10" pattern="yyyy-MM-dd" readonlyInput="true" navigator="true" yearRange="1900:2050" required="true" requiredMessage="#{msg['msg.veteran.service.start.required']}" valueChangeListener="#{personInfo.addDirtyFields}">
<f:attribute name="fieldName" value="Active Duty Service Start Date"/>
</p:calendar>
</h:column>
<h:column>
<h:outputText value="to"/>
</h:column>
<h:column>
<p:calendar value="#{serviceDateObj.toDate}" size="10" pattern="yyyy-MM-dd" readonlyInput="true" navigator="true" yearRange="1900:2050" required="true" requiredMessage="#{msg['msg.veteran.service.end.required']}" valueChangeListener="#{personInfo.addDirtyFields}">
<f:validator validatorId="toDateInPastValidator" />
<f:attribute name="errMsgNameToField" value="Active Duty Service End Date" />
<f:attribute name="errMsgNameFromField" value="Active Duty Service Start Date" />
<f:attribute name="fromDate" value="#{bindingVar}"/>
<f:attribute name="fieldName" value="Active Duty Service End Date"/>
</p:calendar>
</h:column>
<h:column>
<h:commandButton value="Add" rendered="#{personInfo.profileForm.serviceDateList.size() lt 5}">
<f:ajax event="click" render="servideTblId" listener="#{personInfo.profileForm.addServiceDate}"/>
</h:commandButton>
</h:column>
<h:column>
<h:commandButton value="Remove " rendered="#{personInfo.profileForm.serviceDateList.size() ne 1}">
<f:ajax event="click" render="servideTblId" listener="#{personInfo.profileForm.removeServiceDt(serviceDateObj)}"/>
</h:commandButton>
</h:column>
public void addServiceDate(AjaxBehaviorEvent event){
++serviceDtCount;
ServiceDate sDate = new ServiceDate(null, null, serviceDtCount);
serviceDateList.add(sDate);
}
public void removeServiceDt(ServiceDate sDate){
--serviceDtCount;
if(sDate != null){
serviceDateList.remove(sDate);
}
}
public class ServiceDate implements Serializable{
private static final long serialVersionUID = 6963595158386578748L;
private Date fromDate;
private Date toDate;
private int id;
ServiceDate(){
super();
}
ServiceDate(Date fromDate, Date toDate, int count){
this.fromDate = fromDate;
this.toDate = toDate;
this.id=count;
}
public Date getFromDate() {
return fromDate;
}
public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}
public Date getToDate() {
return toDate;
}
public void setToDate(Date toDate) {
this.toDate = toDate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
以下是我遇到的问题。
非常感谢任何帮助。