Primefaces Calendar not rendered

被刻印的时光 ゝ 提交于 2019-12-13 07:10:57

问题


I'm trying to create a primefaces panel from backend. This is what I've written -

Calendar calendar = new Calendar();
String expression = "#{calendarBean.date1}";
boolean _showButtonPanel = true;
calendar.setValue(expression);
calendar.setShowButtonPanel(_showButtonPanel );
Panel.getChildren().add(calendar);

But i'm able to retrieve only a textbox without the "calendar.setValue(expression);" but with the line it throws an exception -

com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit
SEVERE: java.lang.IllegalArgumentException: Cannot format given Object as a Date

回答1:


You need to set a fullworthy ValueExpression as component's value, not a plain vanilla string.

FacesContext facesContext = FacesContext.getCurrentInstance();
ValueExpression valueExpression = facesContext.getApplication().getExpressionFactory()
    .createValueExpression(facesContext.getELContext(), "#{calendarBean.date1}", Date.class);
calendar.setValueExpression("value", valueExpression);
// ...

Don't forget to set an ID as well, or JSF won't process the submitted value.

calendar.setId("date1");
// ...


来源:https://stackoverflow.com/questions/7398765/primefaces-calendar-not-rendered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!