1

I am trying to understand popup menu in richfaces. I am trying to do the following: I have a textbox and a button. I write some text into the textbox, and if the value of the text written is "popup", i want to call the popup menu. Here is the code:

 <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>

and the 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;
}

}

If i don't put "if(#{popupCall.showpopup()})" inside the onclick method it always calls when button is pressed but now even though the showpopup()method returns true no popup is shown. Also, inside the showpopup() method, if i just write return true, the if statement inside onclick works but now it does not. Can anyone help me with this? Thanks

4

1 回答 1

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()返回的是 a boolean,因此您可能需要修复它。

我发现这些链接很有帮助,请查看它们(对于第一个链接,我喜欢投票最高的链接)。

Primefaces onclick 和 onsuccess 的区别

p:commandButton onclick 中的 EL 表达式不会根据 ajax 请求更新/重新渲染?

于 2013-07-19T18:45:34.180 回答