我有一個後端restservice通話值,返回值,與我有執行JS功能(爲簡單起見,我把「警戒」在這裏,在前端。這必須是在JSF實現的,我有一個困難時期。執行JS功能與@ManagedBean
而且,這是捕獲,性能方面的原因,我想後端其餘-致電第一要上點擊執行。
這裏是(以及許多其他事情),我曾嘗試過:
<p:commandLink action="#{viewingSessionBean.prepareViewingSession(document)}" oncomplete="alert('#{viewingSessionBean.name(document)}')">
<p:graphicImage value="documentViewerPopup.png"/>
</p:commandLink>
這裏的豆(縮短,使指向更清晰):
@ManagedBean
@ViewScoped
public class ViewingSessionBean implements Serializable {
private String name;
public String prepareViewingSession(Document document) {
name = restClient.call()
hashMap.put(document.getBlobId(), name);
return null; // don't navigate away...
}
public String name(Document document) {
return hashMap.get(document.getBlobId()); // return null if nothing is cached for the document yet there
}
}
我想這樣做(僞代碼......沒有H:commandScript ...,太舊JSF,沒辦法升級)
<h:commandScript action="alert('#{viewingSessionBean.prepareViewingSession(document)}') />
真棒的想法/模式!我認爲,在「firstLink」中的oncomplete事件中,你想觸發$('#form \\:secondLink')。click(),是否正確? – Frischling
真實生活的另一個改進是使用#{component.findComponent('secondLink')。clientId}進行選擇,這樣可以更輕鬆地在實際情況下閱讀代碼,並且在其中堆疊maaaany div等進入彼此。這導致
– Frischling
@Frischling是的,第一個鏈接應該調用第二個鏈接點擊,更新我的答案。你也是對的jQuery選擇功能,我省略了它,以儘可能簡單的答案。謝謝你們的高舉,雖然;) – Bonifacio