问题
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