0 Replies Latest reply on Feb 21, 2014 8:12 AM by Leandro Fracaro

    How to call a method in Bean onClick in the save button on rich:editor using RichFaces 4?

    Leandro Fracaro Newbie

      I am using the RichFaces 4 in my application, but I`d like call a method from my bean when the user press the save button (for example: to save in a file text.txt)

      Is there a way to call a java method when the user click on the tollbar save button (disket)?

      Here is the code i`m using

      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      <http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      html xmlns="http://www.w3.org/1999/xhtml"
        xmlns
      :h="http://java.sun.com/jsf/html"
        xmlns
      :f="http://java.sun.com/jsf/core"
           xmlns
      :ui="http://java.sun.com/jsf/facelets"
           xmlns
      :a4j="http://richfaces.org/a4j"
           xmlns
      :rich="http://richfaces.org/rich">
       
      <h:head>
         
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
         
      <title>Insert title here</title>
       
      </h:head>
        
      <h:body>


        
      <h:form>
        
      <rich:editor id="editor" toolbar="full" value="#{editorBean.value}" style="margin-bottom: 1em" height="400" >

                    
      <a4j:ajax event="change" render="panel"  status="panelUpdateStatus" />

                    
      <a4j:ajax event="dirty" render="panel" status="panelUpdateStatus">
                  
      <a4j:attachQueue requestDelay="1000" />
                    
      </a4j:ajax>



                
      </rich:editor>

                
      <rich:panel id="panel">
                       
      <f:facet name="header">
                            
      Output from Editor
                    
      <a4j:status name="panelUpdateStatus">
                       
      <f:facet name="start">
                                 
      (Updating)
                             
      </f:facet>
                          
      </a4j:status>
                       
      </f:facet>
                   
      <h:outputText escape="false" value="#{editorBean.value}" />
                </rich:panel>


      </h:form>

       

      EditorBean

      import java.io.Serializable;


      import javax.enterprise.context.SessionScoped;
      import javax.inject.Named;

      @Named
       
      @SessionScoped
       
      public class EditorBean implements Serializable{

      /**
      *
      */

      private static final long serialVersionUID = 5383915229820571701L;


      private String value;

      /**
      * @return the value
      */

      public String getValue() {
        
      return value;
      }

      /**
      * @param value the value to set
      */

      public void setValue(String value) {
        
      this.value = value;
      }

      public void save(){
        
      System.out.println(" Saving ");
        
      //Code to save
      }
      }