我試圖讓h:inputText在單擊h:commandButton時用不同的開關切換出來。爲此,我試圖將f:ajax命令與h:commandButton綁定在一起,讓偵聽器在bean上設置一個值(決定要顯示哪一個值),然後重新渲染該區域。JSF f:ajax監聽器沒有調用
我已經嘗試在h:commandButton上的f:ajax,actionListener上使用監聽器,在f:ajax上執行h:commandButton上的操作。沒有工作。我試圖調用的主題完全沒有被調用 - 沒有println(請看後面的內容)。
panelGroup正在重新呈現,這就是爲什麼我需要onevent屬性,重新附加一些基於標題的JavaScript提示文本(我有一個涉及此問題的早期問題)。
的方法,我試圖調用:
public void morePressed(AjaxBehaviorEvent e) {
easySearch = !easySearch;
System.out.println("Made it!");
}
不工作的JSF段(注意最後H:的commandButton正試圖重新呈現panelGroup中):
<h:form>
<h:panelGroup id="switchSearchTexts">
<h:inputText accesskey="s" alt="Search" id="searchBoxPeople" title="Search Plebeians" valueChangeListener="#{peopleBean.simplePersonQuery}" size="25" rendered="#{peopleBean.easySearch}">
<f:ajax render="peopleDataTable" event="keyup" />
</h:inputText>
<h:inputText accesskey="s" alt="Search First Name" id="searchBoxFN" title="Search First Name" size="25" rendered="#{!peopleBean.easySearch}">
<f:ajax render="peopleDataTable" event="keyup" />
</h:inputText>
</h:panelGroup>
<div id="expandBox">
<h:inputText id="searchBoxLN" alt="Search Last Name" styleClass="hideToggle" title="Search Last Name" size="25" />
<h:inputText id="searchBoxAddress" alt="Search Address" styleClass="hideToggle" title="Search Address" size="25" />
</div>
<h:commandButton type="button" styleClass="moreButtonAsText" id="moreButtonAsText" value="▸More">
<f:ajax listener="#{peopleBean.morePressed}" render="switchSearchTexts" event="click" onevent="callFunctionAjaxRequest" />
</h:commandButton>
這是我附加到pageload上更多按鈕的JavaScript(jQuery)。我給它並不是因爲我認爲它可以幫助,但我不知道這能以任何方式阿賈克斯聽衆的干擾:
$(function() {
textboxHint();
$('input[id$="moreButtonAsText"]').toggle(function(e) {
$(this).prop('value', '\u25c2Less');
$(".hideToggle").show(300);
}
, function() {
$(this).prop('value', '\u25b8More');
$(".hideToggle").hide(100);
$('input[id$="searchBoxAddress"]').prop('value', function() {
return $(this).prop('title');
});
$('input[id$="searchBoxAddress"]').blur();
});
});
我不知道。正如我所說的,我已經在h:commandButton上嘗試了actionListener,其中有各種各樣的appraoches,以及ajax上偵聽器的各種方法。任何人都可以明白爲什麼聽者不工作?
更新:
我最終什麼事做,有一個答案之前,正在將一切顯示和隱藏基於JavaScript,帶的東西,如果他們沒有JavaScript的最初隱藏我需要隱藏,等
但是我現在需要其他地方的f:ajax。
解決方法是在h:commandButton上取出event =「click」。我仍然現在知道這是爲什麼導致它打破,但嘿,無論工程。
我確實有callFunctionAjaxRequest,以及固定的ajax調用(並刪除所有執行,因爲我不需要它們)。 但是......奇怪的是,將事件=「點擊」出來導致它工作。我想知道爲什麼離開它不工作? – twmb 2012-03-24 19:48:54
event =「click」是多餘的,但不應該造成任何傷害...怪異的,你確定它沒有引用錯誤的ID沒有造成危害嗎? – Daniel 2012-03-24 19:57:32
我正是這樣的: h:commandButton>' 使用println in morePressed;它從未印過。以'event ='點擊''出來到達println。我附加了一個jQuery切換到JavaScript文件中的按鈕,但我不認爲這會覆蓋行爲,並導致點擊不起泡或什麼;我沒有任何傳播停止。 –
twmb
2012-03-24 20:04:24