2015-12-02 84 views
-1

我在這裏從一個JavaScript函數,如回我計數變量:如何採取從方法的返回值的方法

現在,我怎麼在我的JSF代碼讓我的計數值爲了用htm()函數打印它?

final class GroupsSelector extends BaseRenderablePanel<GroupsSelector> { 
     private GroupsSelector group(LabourInputReportCriteria.Level level) { 
      HtmlSelectBooleanCheckbox box = new HtmlSelectBooleanCheckbox(); 
      boolean isSelected = selections.isGroupSelected(level); 
      box.setSelected(isSelected); 
      // box.setDisabled(isDaySelectedOnFirst(level)); 
      String id="groupBy" + level.getClass().getSimpleName(); 
      box.setId(id); 

      box.setOnclick("resetGroupsSelector('"+id+"')"); 
      box.addValueChangeListener(u.addExpressionValueChangeListener("#{reportSearchCriteriaModel.groupBy}")); 
      HtmlOutputText labelComponent = new HtmlOutputText(); 

      labelComponent.setValue(getGroupSelectionValue(level)); 
      tr().td(); 
      html(box); 

      //html("&nbsp;"); 

      html(labelComponent); 
      //html("<script> function resetGroupsSelector() { var x = document.getElementById('search_report_form:groupByWeekLevel'); alert(x); } </script>"); 

      endTd().endTr(); 
      return this; 
     } 

請幫幫我。

感謝, Shruthi小號

回答

0

你的問題不是很清楚。但是,如果您想獲得熱門計數器,即有多少次訪問過jsf頁面。最好的選擇是按如下方式使用@辛格爾頓會話bean,JSF @ManageBean和@SessionScoped豆類:

@Singleton 

public class IndexCounterBean {

private int hits = 1; 

// Increment and return the number of hits 
public int getHits() { 
    return hits++; 
} 

}

然後創建一個JSF @SessionScoped @ManagedBean讓您訪問您的櫃檯如下:

@ManagedBean @SessionScoped public class IndexCount implements Serializable{

@EJB 
    private IndexCounterBean counterBean; 

    private int hitCount; 

    public IndexCount() { 
     this.hitCount = 0; 
    } 

    public int getHitCount() { 
     hitCount = counterBean.getHits(); 
     return hitCount; 
    } 

    public void setHitCount(int newHits) { 
     this.hitCount = newHits; 
    } 
} 

然後,從JSF(.xhtml)頁,打印計數器如下:

<h:outputText value="#{indexCount.hitCount} Visits"/> 

計數器將遞增每次頁面被請求。