ここでは、次のようにJavascriptの関数からcount変数を返しています。
<script type="text/javascript">
var count = 0;
function resetGroupsSelector(groupId){
//alert(groupId);
console.log("search_report_form:"+groupId)
//alert("search_report_form:"+groupId)
var id = "search_report_form:"+groupId;
//alert(count);
if(document.getElementById(id).checked)
{
count=count+1;
alert(count);
}
else
{
count=count-1;
alert(count);
}
return count;
}
</script>
では、htm()関数で出力するために、JSFコードからカウント値を取得するにはどうすればよいですか?
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(" ");
html(labelComponent);
//html("<script> function resetGroupsSelector() { var x = document.getElementById('search_report_form:groupByWeekLevel'); alert(x); } </script>");
endTd().endTr();
return this;
}
私を助けてください。
ありがとう、シュルティS
あなたの質問はあまり明確ではありません。ただし、ヒットカウンター、つまりjsfページにアクセスした回数を取得する場合。最善のオプションは、次のように@SingletonセッションBean、jsf @ManageBean、および@SessionScopedBeanを使用することです。
@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"/>
カウンターは、ページが要求されるたびにインクリメントされます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加