Wednesday, December 8, 2010

How to invoke a JavaScript method from the managed bean

Jspx part
---------------
<f:view>
    <af:document id="d1">
     <![CDATA[
   <script>
      function greeter() {
         alert("Hello..");
         }
   }             
</script> ]]>
      <af:form id="f1">
        <af:commandButton text="commandButton 1" id="cb2"
                              partialSubmit="true"
                              action="#{ScriptCallerBean.cb2_action}"/>
      </af:form>
    </af:document>
</f:view>


managed bean coding
------------------------
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public void caller(){
ExtendedRenderKitService extRenderKitSrvc = Service.getRenderKitService(FacesContext.getCurrentInstance(),ExtendedRenderKitService.class);
extRenderKitSrvc.addScript(FacesContext.getCurrentInstance(),"window.greeter()");
}

1 comment:

  1. BetMGM agrees to buy MGM Springfield Casino in $14.2 billion
    MGM 의정부 출장안마 Springfield casino-owner BetMGM, the parent company of MGM Springfield and 목포 출장안마 MGM Resorts 여수 출장샵 International, agreed to buy MGM 부천 출장안마 Springfield Casino in a $14.2 충청남도 출장마사지

    ReplyDelete