Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 6.26 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JSF El expression retaining old value (JSF life cycle)
  2. @ManagedBean(name = "kpilist")
  3. @ViewScoped
  4. public class KPIListController implements Serializable {
  5.  
  6.     private static final long serialVersionUID = 1L;
  7.     boolean state = true;
  8.     String selectedKPIType;
  9.     String selectKPITime = "D";
  10.     boolean renderDatatable;
  11.     String json;
  12.  
  13.  
  14.  
  15.     public String getJson() {
  16.         return json;      
  17.     }
  18.  
  19.  
  20.     public boolean isRenderDatatable() {
  21.         return renderDatatable;
  22.     }
  23.  
  24.     public void setRenderDatatable(boolean renderDatatable) {
  25.         this.renderDatatable = renderDatatable;
  26.     }
  27.  
  28.     public boolean isState() {
  29.         return state;
  30.     }
  31.  
  32.     public List<String> showViewList() {
  33.         Logger.getLogger(KPIListController.class.getName()).warning("Show view List:");
  34.         KPIDAO kpiDAO = new KPIDAO();
  35.         try {
  36.             Logger.getLogger(KPIListController.class.getName()).info("Into show view List ---select One");
  37.             return kpiDAO.showViewList(selectKPITime);
  38.         } catch (SQLException ex) {
  39.             ex.printStackTrace();
  40.             Logger.getLogger(KPIListController.class.getName()).log(Level.SEVERE, null, ex);
  41.             return null;
  42.         }
  43.     }
  44.  
  45.     public void setState(boolean state) {
  46.         this.state = state;
  47.     }
  48.  
  49.     public String getSelectedKPIType() {
  50.         return selectedKPIType;
  51.     }
  52.  
  53.     public void setSelectedKPIType(String selectedKPIType) {
  54.         this.selectedKPIType = selectedKPIType;
  55.     }
  56.  
  57.     public String getSelectKPITime() {
  58.         return selectKPITime;
  59.     }
  60.  
  61.     public void setSelectKPITime(String selectKPITime) {
  62.         this.selectKPITime = selectKPITime;
  63.     }
  64.  
  65.     public List<KPI> getKPI() {
  66.         Logger.getLogger(KPIListController.class.getName()).warning("Get KPI Values:");
  67.         KPIDAO kpiDAO = new KPIDAO();        
  68.          List<KPI> kpiList = new ArrayList<KPI>();
  69.  
  70.         try {
  71.             kpiList = kpiDAO.getKPI(selectedKPIType);  
  72.             Logger.getLogger(KPIListController.class.getName()).warning("KPI List:"+kpiList.size());            
  73.  
  74.         } catch (SQLException ex) {
  75.             ex.printStackTrace();
  76.             return null;
  77.         }
  78.          Gson gson = new Gson();
  79.         json= gson.toJson(kpiList);
  80.         return kpiList;
  81.     }
  82.  
  83.     public void resetFormValues() {      
  84.         Logger.getLogger(KPIListController.class.getName()).warning("Reset form:");
  85.         selectedKPIType = "--";
  86.     }
  87. }
  88.        
  89. <html xmlns="http://www.w3.org/1999/xhtml"
  90.       xmlns:h="http://java.sun.com/jsf/html"
  91.       xmlns:rich="http://richfaces.org/rich"
  92.       xmlns:f="http://java.sun.com/jsf/core"
  93.       xmlns:a4j="http://richfaces.org/a4j"
  94.       xmlns:ui="http://java.sun.com/jsf/facelets"
  95.       xmlns:c="http://java.sun.com/jsp/jstl/core">
  96.     <h:head>
  97.  
  98.     </h:head>
  99.     <h:body>
  100.         <ui:composition template="/contentTemplate.xhtml">
  101.             <ui:define name="windowTitle">KPI Index</ui:define>
  102.             <ui:define name="content" >
  103.  
  104.                 <h:outputScript name="js/graphics/jquery.js"/>  
  105.                 <h:outputStylesheet name="/css/jquery-ui-1.8.22.custom.css"/>
  106.                 <h:outputScript name="js/graphics/jquery-ui-1.8.22.custom.min.js"/>
  107.                 <h:outputScript name="js/OpenLayers/OpenLayers.js"/>
  108.  
  109.                 <h:outputScript name="js/graphics/raphael-min.js"/>
  110.                 <h:outputScript name="js/graphics/canvg.js"/>
  111.                 <h:outputScript name="js/graphics/paths.js"/>
  112.                 <h:outputScript name="js/graphics/draw.js"/>
  113.  
  114.                 <h:form id="ins_sel_form">
  115.                     <h:outputText value="KPI TIME FRAME"/>
  116.                     <h:selectOneRadio value="#{kpilist.selectKPITime}"  >
  117.                         <f:selectItem itemLabel="DAILY" itemValue="D"   />
  118.                         <f:selectItem itemLabel="WEEKLY" itemValue="W"  />
  119.                         <f:selectItem itemLabel="LAST WEEK" itemValue="LW"  />    
  120.                         <a4j:ajax event="change" render="ins_sel_form:selectOnemenu dataPnl"  listener="#{kpilist.resetFormValues()}" />
  121.                     </h:selectOneRadio>
  122.  
  123.                     <h:outputText value="Major KPI Type"/>
  124.                     <h:selectOneMenu id="selectOnemenu" value="#{kpilist.selectedKPIType}"  >
  125.                         <f:selectItem itemValue="--" itemLabel="--"></f:selectItem>
  126.                         <f:selectItems itemValue="#{item.toString()}" var="item" itemLabel="#{item.toString()}" value="#{kpilist.showViewList()}"/>
  127.                         <a4j:ajax event="change" render="dataPnl"  oncomplete="jsonDemo('#{kpilist.json}')" />
  128.                     </h:selectOneMenu>
  129.  
  130.                     <h:outputText value="Show / Hide Map"/>
  131.  
  132.                 </h:form>
  133.                 <rich:panel  id ="dataPnl">
  134.  
  135.                         <rich:dataTable id="kpiValueTable" value="#{kpilist.KPI}" var="kpi" style="width:100%" rows="20" rendered="#{kpilist.selectedKPIType!=null and kpilist.selectedKPIType !='--' }" >                            
  136.  
  137.                             <rich:column>
  138.                                 <f:facet name="header" >
  139.                                     <h:outputText value ="Value"></h:outputText>
  140.                                 </f:facet>
  141.                                 <h:outputText value="#{kpi.KPIValue}"></h:outputText>
  142.                             </rich:column>
  143.  
  144.                         </rich:dataTable>
  145.                     JSON String :  <h:outputText  id="json" value ="#{kpilist.json}"/>  
  146.                         <center><rich:dataScroller for="kpiValueTable" rendered="#{kpilist.selectedKPIType!=null and kpilist.selectedKPIType!='--'}"/></center>
  147.                     </rich:panel>
  148.  
  149.                 <rich:panel id="map" style="display: none;">
  150.                 </rich:panel>
  151.  
  152.  
  153.             </ui:define>
  154.         </ui:composition>
  155.     </h:body>
  156. </html>
  157.        
  158. function jsonDemo(jsonString){
  159.  
  160.     console.log("Chart data already retrieved: " + jsonString);
  161.     var data = $.parseJSON(jsonString);    
  162.     $.each(data,function(i,val){
  163.          console.log("The value of i: "+i+" The val: "+val.NCELLCLUSTER);
  164.     });
  165.  
  166. }
  167.        
  168. function jsonDemo() {
  169.     $.getJSON("servletURL", function(jsonData) {
  170.         // ...
  171.     });
  172. }
  173.        
  174. <a4j:ajax ... render="json" />
  175. ...
  176. <h:panelGroup id="json">
  177.     <h:outputScript rendered="#{not empty bean.json}">jsonDemo(#{bean.json});</h:outputScript>
  178. </h:panelGroup>