我有两个日历,一个用于开始日期,一个用于结束日期。当我单击commandButton来触发方法updateAccount
时,我收到错误消息:
Conversion Error setting value 'Tue Feb 26 16:41:43 EST 2013' for 'null Converter'.Conversion Error setting value 'Tue Feb 26 16:41:43 EST 2013' for 'null Converter'.
Conversion Error setting value 'Tue Feb 25 16:41:43 EST 2014' for 'null Converter'.Conversion Error setting value 'Tue Feb 25 16:41:43 EST 2014' for 'null Converter'.
commandButton应该使用selectmenu和calendars中的值作为SQL查询的参数重新加载页面。分配给日历的值是Date类型。是否导致此错误是因为日历的输出是String类型并尝试分配给Date类型的变量?从我在网上发现的例子中不需要转换器。这是不正确的?如果是这样,我该如何解决此错误消息。
我的JSF页面:
<f:metadata>
<f:viewParam name="account" value="#{accountAnalysisBean.account}" />
<f:viewParam name="start" value="#{accountAnalysisBean.start}" />
<f:viewParam name="end" value="#{accountAnalysisBean.end}" />
<f:viewAction action="#{accountAnalysisBean.pullData}" />
</f:metadata>
<h:form>
<p:panelGrid columns="6">
<f:facet name="header">
<p:selectOneMenu id="pickAccount" value="#{accountAnalysisBean.pickAccount}" required="true" >
<f:selectItems value="#{editAccountBean.allAccounts}" />
</p:selectOneMenu>
<h:outputLabel value="Start Date: " />
<p:calendar id="start" value="#{accountAnalysisBean.start}" pattern="MM/dd/yyyy" navigator="true" />
<h:outputLabel value="End Date: " />
<p:calendar id="end" value="#{accountAnalysisBean.end}" pattern="MM/dd/yyyy" navigator="true" />
<p:commandButton value="Get Account" action="#{accountAnalysisBean.updateAccount}" >
<f:param name="start" value="#{accountAnalysisBean.start}"/>
<f:param name="end" value="#{accountAnalysisBean.end}"/>
<f:param name="account" value="#{accountAnalysisBean.id}"/>
</p:commandButton>
</f:facet>
</p:panelGrid>
</h:form>
我的豆子:
@ManagedBean
@ViewScoped
public class AccountAnalysisBean {
private String account = "";
private String id = "";
private String pickAccount = "";
private Date start;
private Date end;
//gettters and setters
public void pullData() {
if (account != "") {
//pull various fields from database given account value
} else {
//set default null values
}
}
public void updateAccount() {
fix = DAOFactory.getInstance("fix_site2.jdbc");
datalist = fix.getMyDataDAO();
id = datalist.findAccountID(pickAccount); //returns an ID from a DB given account selected from menu
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/AccountAnalysis.xhtml?account=" + id +
"&start=" + start + "&end=" + end + "&includeViewParams=true");
}
//remained of code omitted for clarity
}
我正在使用JSF 2.2和Primefaces 4
答案 0 :(得分:1)
您正在使用
<f:viewParam name="start" value="#{accountAnalysisBean.start}" />
<f:viewParam name="end" value="#{accountAnalysisBean.end}" />
,这些属性是Date
个对象,而请求参数是String
,所以你需要一个转换器。
<f:viewParam name="start" value="#{accountAnalysisBean.start}" converter="javax.faces.DateTime">
应该有用。