我试图了解richfaces中的弹出菜单。我正在尝试执行以下操作:我有一个文本框和一个按钮。我在文本框中写了一些文字,如果写的文字的值是" popup",我想调用弹出菜单。这是代码:
<h:form>
<h:inputText value="#{popupCall.text}"></h:inputText>
<a4j:commandButton action="#{popupCall.showpopup()}" onclick="if (#{popupCall.showpopup()}) #{rich:component('popup')}.show();">
</a4j:commandButton>
</h:form>
<rich:popupPanel id="popup" modal="false" autosized="true" resizeable="false">
<f:facet name="header">
<h:outputText value="Popup panel" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide();
return false;">
X
</h:outputLink>
</f:facet>
</rich:popupPanel>
和bean:
@ManagedBean (name="popupCall")
@VievScoped
public class PopupCall {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public PopupCall() {
}
public void checkText(){
if(text.equals("popup")){
//CALL POPUP MENU
}
}
public boolean showpopup(){
if(text!=null && text.equals("popup"))
return true;
else
return false;
}
}
如果我不放&#34; if(#{popupCall.showpopup()})&#34;在onclick方法内部,它总是在按下按钮时调用,但现在即使showpopup()方法返回true,也不会显示弹出窗口。另外,在showpopup()方法中,如果我只是写回返true,则onclick中的if语句可以工作,但现在却没有。 谁能帮我这个?感谢
答案 0 :(得分:2)
对于您的情况,您希望使用oncomplete
而不是onclick
,因为您希望在执行某些业务逻辑后显示<rich:popupPanel>
。当我改变了
onclick="if (#{popupCall.showpopup()}) #{rich:component('popup')}.show();"
到
oncomplete="if (#{popupCall.showpopup()}) #{rich:component('popup')}.show();"
弹出窗口出现了。
也要小心action="#{popupCall.showpopup()}"
请注意,action
需要String
(或null
)才能进行导航
showpopup()
正在返回boolean
,因此您可能需要修复此问题。
我发现这些链接有助于检查它们(对于第一个链接,我喜欢投票率最高的那个)。
Primefaces onclick and onsuccess differences
EL expression inside p:commandButton onclick does not update/re-render on ajax request?