2 Replies Latest reply on Aug 23, 2010 7:40 AM by kapil29

    HtmlModalPanel on rerendering hide the Modal Panel

    kapil29

      Hi,

       

      I have dynamically generated HtmlModalPanel when clicking on <a4j:commandButton /> component. The modal panel displays the several form elements on it (i.e. textarea for emails , textboxes and two buttons <show> and <email>.). Now the situation is I need to display the email button only when the contents in the textarea are not empty.  Initially when Modal Panel appear I need to hide the email button.

       

      I have implemented this by using HtmlAjaxSupport for hiding / showing button using backing bean boolean property, but when onchange event is occured on textarea and panel is rerendered, the Modal Panel is closed when action is finishes.

       

       

              HtmlAjaxCommandButton emailCommandButton = new HtmlAjaxCommandButton();
             
                  HtmlOutputText lblEmail = new HtmlOutputText();
                  lblEmail.setValue("Email: ");

       

                  HtmlInputTextarea txtEmail = new HtmlInputTextarea();
                  txtEmail.setCols(20);
                  txtEmail.setRows(5);
                  txtEmail.setReadonly(false);
                  txtEmail.setValueExpression("value", application.getExpressionFactory().createValueExpression(context.getELContext(), "#{tagBean.emails}", String.class));
                  txtEmail.setImmediate(true);

       

                  Class[] EmailsClass = new Class[]{ValueChangeEvent.class};
                  MethodExpression emailsME = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
                                        createMethodExpression(context.getELContext(),
                                        "#{tagBean.emailsValueChanges}", null, EmailsClass);

       

                  MethodExpressionValueChangeListener emailsVCL = new MethodExpressionValueChangeListener(emailsME);
                  txtEmail.addValueChangeListener(emailsVCL);

       

                  HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
                        ajaxSupport.setActionExpression(FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
                                                          createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
                                                          "#{projectController.getEmailButtonStatus}", String.class, new Class[] {}));

       

                  ajaxSupport.setEvent("onchange");
                  ajaxSupport.setReRender("tagPanel");
                  txtEmail.getFacets().put("a4jsupport",ajaxSupport);

       

                  panelGrid.getChildren().add(lblEmail);
                  panelGrid.getChildren().add(txtEmail);

       

       

                  emailCommandButton.setId("EmailButtonId"+project.getId());
                  emailCommandButton.setValue("Email");
                                                      emailCommandButton.setValueExpression("rendered",application.getExpressionFactory().createValueExpression(context.getELContext(),           "#{tagBean.emailButtonStatus}", Boolean.class));
                     
                 String emailAction = "#{projectController.emailTagAction}";
                 emailCommandButton.setImmediate(true);

       

                 emailCommandButton.setActionExpression(
                 createActionExpression(emailAction, String.class));

       

                 emailCommandButton.setOnclick("javascript:Richfaces.hideModalPanel('tagPanel')");

       

                buttonPanelGroup.getChildren().add(emailCommandButton);

       

       

      Can any one let me know what is the exact cause for this isseue and how to reslove it.

        • 1. Re: HtmlModalPanel on rerendering hide the Modal Panel
          sivaprasad9394

          1)use rendered attribute,create some dummy propery in backing bean and set some value in the backing bean.

          2)onblur of the textarea check the length and if it is greater than 1 the then set the dummy property value ='some value' in bean and mean time reRender the email button id also.now email button id will be visible.

          • 2. Re: HtmlModalPanel on rerendering hide the Modal Panel
            kapil29

            Hi ,

             

            Thanks for your reply,

             

            I have aleady implemented "rendered" attribute with boolean property in my backing bean for textarea components. When the Modal Panel is appear the value for rendered is false initially, and onchange event of ajax support for textaraea component, I am again setting this property value is true in my ajax action method as mention below. But when the panel is reRendered, the Opened modal panel is hide.......

             

            Controller Action Method (projectController.getEmailButtonStatus)

             

                 public void getEmailButtonStatus() {
                    System.out.println("in getEmailButtonStatus........");
                    tagBean.setEmailButtonStatus(true);
                         
                }

             

            Bean Class

             

            public class TagBean {
                private String emails;

             

                private boolean emailButtonStatus;

             

               public TagBean() {
                    this.emails = "";
                    this.emailButtonStatus = false;
                }

             

                public String getEmails() {
                    return emails;
                }

             

                public void setEmails(String emails) {
                    this.emails = emails;
                }

             

                public boolean getEmailButtonStatus() {

                    return emailButtonStatus;
                }

             

                public void setEmailButtonStatus(boolean emailButtonStatus) {
                    this.emailButtonStatus = emailButtonStatus;
                }

             

                // Listeners

                public void emailsValueChanges(ValueChangeEvent event) {

                    emails = (String) event.getNewValue();
                }
            }

             

            Could you please let me know, what is wrong in this logic...?