1 Reply Latest reply on Nov 26, 2012 3:58 PM by Warley Mendes

    Error to put a calendar inside a dynamic toolbar

    Warley Mendes Newbie

      Hi,

       

      I'm try to put a calendar inside the dynamic toolbar, but i'm getting JavaScript error : RichFaces.ui.Calendar is null

      And the calendar don't show de dates.

       

      That is my bean:

       

       

      package br.com.jsf.presentation;

      import java.io.Serializable;
      import java.util.Date;

      import javax.el.MethodExpression;
      import javax.el.ValueExpression;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.ViewScoped;
      import javax.faces.component.html.HtmlGraphicImage;
      import javax.faces.context.FacesContext;
      import javax.faces.event.ValueChangeEvent;

      import org.richfaces.component.UICalendar;
      import org.richfaces.component.UICommandLink;
      import org.richfaces.component.UIToolbar;
      import org.richfaces.component.UIToolbarGroup;


      @ManagedBean(name="toolbarBean")
      @ViewScoped
      public class ToolbarBean implements Serializable{

       

      private static final long serialVersionUID = -2508286822425855408L;

       

      private UIToolbar menuBar;

       

      private Date data = new Date();
      private String textoPesquisa;

       

      public void processaData(ValueChangeEvent event){
        System.out.println("Data selecionada: "+ data);
      }

      public void salvar(){
       
        System.out.println("Método Salvar...");
      }

       

      public void abrir(){
       
        System.out.println("Método Abrir...");
      }

       

      public void motrarGrafico(){
       
        System.out.println("Método Motrar Gráfico...");
      }

       

      public void exportarRelatorio(){
       
        System.out.println("Método Exportar Relatório...");
      }

       

      public void pesquisar(){
       
        System.out.println("Método Pesquisar... Texto da pesquisa: "+ this.textoPesquisa);
      }

       

      public UIToolbar getMenuBar() {
       
        FacesContext ctx = FacesContext.getCurrentInstance();
       
         menuBar = (UIToolbar) ctx.getApplication()
                    .createComponent(ctx, UIToolbar.COMPONENT_TYPE,
                    "org.richfaces.ToolbarRenderer");
        
         UIToolbarGroup toolGroup1 = this.newUIToolbarGroup(ctx, "tg1");
        
        
         UICalendar calendar = (UICalendar)ctx.getApplication()
                    .createComponent(ctx, UICalendar.COMPONENT_TYPE,
                    "org.richfaces.component.UICalendar");
        
         calendar.setId("c1");
         //calendario.setDatePattern("dd/MM/yyy");
         //calendario.setInputStyle("width:100px");
         //calendario.setFirstWeekDay(0);
         //calendario.setShowWeeksBar(false);
         //calendario.setShowApplyButton(false);
         //calendario.setEnableManualInput(false);
         calendar.setValue(this.data);
         calendar.setValueExpression("value", this.newValueExpression(ctx, "#{toolbarBean.data}", Date.class));

         toolGroup1.getChildren().add(calendar);
        
         
         //Adiciona os grupos á barra de ferramenta 
         menuBar.getChildren().add(toolGroup1);
        
         return menuBar;
      }

       

      private UIToolbarGroup newUIToolbarGroup(FacesContext ctx, String id){
       
        UIToolbarGroup tGroup = (UIToolbarGroup)ctx.getApplication()
           .createComponent(ctx, UIToolbarGroup.COMPONENT_TYPE,
           "org.richfaces.component.UIToolbarGroup");
        tGroup.setId(id);
       
        return tGroup; 
      }

       

      private UICommandLink newUICommandLink(FacesContext ctx, String id){
       
        UICommandLink commandLink = (UICommandLink)ctx.getApplication()
           .createComponent(ctx, UICommandLink.COMPONENT_TYPE,
           "org.richfaces.component.UICommandLink");
       
        commandLink.setId(id);
       
        return commandLink;
      }

       

      private HtmlGraphicImage newHtmlGraphicImage(FacesContext ctx, String id, String icone){
       
        HtmlGraphicImage graphicImage = (HtmlGraphicImage)ctx.getApplication()
                      .createComponent(ctx, HtmlGraphicImage.COMPONENT_TYPE,
                              "javax.faces.component.html.HtmlGraphicImage");
       
        graphicImage.setId(id);
        graphicImage.setValue(icone);
       
        return graphicImage;
      }

       

      private MethodExpression newMethodExpression(FacesContext ctx, String action){
       
        MethodExpression me = ctx.getApplication()
                      .getExpressionFactory()
                      .createMethodExpression(ctx.getELContext(),
                        action, String.class, new Class[0]);
       
        return me; 
      }

       

      private ValueExpression newValueExpression(FacesContext ctx, String valueExpression, Class<?> valueType) {
           return ctx.getApplication().getExpressionFactory()
               .createValueExpression(ctx.getELContext(), valueExpression, valueType);
      }

      public void setMenuBar(UIToolbar menuBar) {
        this.menuBar = menuBar;
      }

      public Date getData() {
        return data;
      }

      public void setData(Date data) {
        this.data = data;
      }

      public String getTextoPesquisa() {
        return textoPesquisa;
      }

      public void setTextoPesquisa(String textoPesquisa) {
        this.textoPesquisa = textoPesquisa;
      }
      }

       

       

      The page:

       

       

      <h:form id="form">   

      <rich:toolbar binding="#{toolbarBean.menuBar}" />

      </h:form>

       

       

      What is wrong in my code?

      Thanks.

        • 1. Re: Error to put a calendar inside a dynamic toolbar
          Warley Mendes Newbie

          The problem is that:

           

          I was using this:

           

          UICalendar calendar = (UICalendar)ctx.getApplication()

                        .createComponent(ctx, UICalendar.COMPONENT_TYPE,

                        "org.richfaces.component.UICalendar");

           

          But the right code is:

           

          UICalendar calendar = (UICalendar)ctx.getApplication()

                            .createComponent(ctx, UICalendar.COMPONENT_TYPE,

                            "org.richfaces.CalendarRenderer");

           

           

           

          Thanks