4 Replies Latest reply on Oct 8, 2007 5:22 AM by eminil

    create modal panel dinamically

    kgoedert

      Hello,

      how can I create a modal panel on the java code and display it on the screen? Is there an example on the documentation?

      Thanks

      Kelly

        • 1. Re: create modal panel dinamically
          ilya_shaikovsky

          you may use standard binding to create it dynamically.

          As for calling - its just JS functions calls so you may cal them in any handler you need.

          • 2. Re: create modal panel dinamically
            kgoedert

            Could you please give me an example?

            • 3. Re: create modal panel dinamically
              ilya_shaikovsky

              please (a very simple example):

              page:

              <h:form>
               <a4j:commandButton value="showMp" oncomplete="javascript:Richfaces.showModalPanel('_panel',{left:'auto', top:'auto'})" action="#{mpBean.mpInit}" reRender="test"/>
               </h:form>
               <a4j:outputPanel id="test">
               <rich:modalPanel binding="#{mpBean.mp}"/>
               </a4j:outputPanel>
              


              Java code:
              import javax.faces.component.html.HtmlOutputText;
              import org.richfaces.component.html.HtmlModalPanel;
              
              public class MpBean {
               HtmlModalPanel mp = new HtmlModalPanel();
              
               public MpBean() {
               }
               public String mpInit() {
               mp.setId("_panel");
               HtmlOutputText text= new HtmlOutputText();
               text.setValue("Hello");
               mp.getFacets().put("header", text);
               HtmlOutputText text2 = new HtmlOutputText();
               text2.setValue("sample");
               mp.getChildren().add(text2);
               return null;
               }
               public HtmlModalPanel getMp() {
               return mp;
               }
               public void setMp(HtmlModalPanel mp) {
               this.mp = mp;
               }
              }
              


              So after button pressed - mp is created, refreshed on a page and called after request completed.

              • 4. Re: create modal panel dinamically
                eminil

                How do you actually show the modal panel from the backing bean?

                Suppose you have a method in the bean, and that method returns and error, and you wish to show that in a modal panel. So you want to open the modal panel from within the backing bean method.