-
1. Re: calendar value not save
mcmurdosound Nov 14, 2011 2:06 PM (in response to fengxiaofeng)"""
panelGrid = new HtmlPanelGrid();
HtmlCalendar calendar = new HtmlCalendar();
calendar = new HtmlCalendar();"""
No!
You have to use the FacesContext and Application to create UIComponents programmatically, like for example:
FacesContext facesContext = FacesContext.getCurrentInstance();
UIComponent component = facesContext.getApplication().createComponent(
HtmlPanelGroup.COMPONENT_TYPE);
You should use valuebinding in your calendar component instead of accessing it in the component tree directly.
-
2. Re: calendar value not save
fengxiaofeng Nov 20, 2011 1:30 AM (in response to mcmurdosound)calendar save, value is emtpy
<a4j:keepAlive beanName="bean"></a4j:keepAlive>
<h:form >
<rich:calendar binding="#{bean.richCalendar }"/>
<h:commandButton action="#{bean.save }"/>
</h:form>private HtmlCalendar richCalendar;
public HtmlCalendar getRichCalendar() {
if(richCalendar == null) {
FacesContext facesContext = FacesContext.getCurrentInstance();
UIComponent component = facesContext.getApplication().createComponent(HtmlCalendar.COMPONENT_TYPE);
richCalendar =(HtmlCalendar) component;
}
return richCalendar;
}public void save() {
System.out.println(richCalendar.getValue());
} -
3. Re: calendar value not save
mcmurdosound Nov 20, 2011 3:33 AM (in response to fengxiaofeng)What scope does your bean have?
Just use valuebinding!
<h:form>
<rich:calendar value="#{myBean.date}" />
<a4j:commandButton value="save" action="#{myBean.save}" />
</h:form>
Bean:
...
private Date date;
public getDate(){
return date;
}
public setDate(Date date){
this.date = date;
}
public String save(){
System.out.println("date is: " + date);
return "";
}