我有一个后端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