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

yrazlik
  • 10,411
  • 33
  • 99
  • 165
  • possible duplicate of [Conditional invocation of rich:popup panel](http://stackoverflow.com/questions/8957560/conditional-invocation-of-richpopup-panel) – Andy Jul 18 '13 at 23:04
  • The answer is in the link. Let me know if you don't understand it. – Andy Jul 18 '13 at 23:05
  • @Andy thanks i am trying it, but i think there is a problem with the "if" inside onclick method. Edited the question – yrazlik Jul 19 '13 at 07:02

1 Answers1

2

For your case you want to use oncomplete instead of onclick since you want to show <rich:popupPanel> after executing some business logic. When I changed

onclick="if (#{popupCall.showpopup()}) #{rich:component('popup')}.show();"

to

oncomplete="if (#{popupCall.showpopup()}) #{rich:component('popup')}.show();"

The pop up showed up. Also be careful with

action="#{popupCall.showpopup()}"

Remember that action needs String (or null) for navigation but showpopup() is returning a boolean so you might want to fix that.

I found these links to be helpful check them out (for the first link, I liked the one with the highest vote).

Primefaces onclick and onsuccess differences

EL expression inside p:commandButton onclick does not update/re-render on ajax request?

Community
  • 1
  • 1
Andy
  • 5,900
  • 2
  • 20
  • 29
  • @iceface Let me know if this didn't work. I was using Netbeans and I had some trouble along the way. In particular, check the js error console for any error messages if the panel doesn't pop up. – Andy Jul 19 '13 at 21:27
  • yeah i had figured out how to do it i just saw your answer. I did the same thing thanks – yrazlik Jul 19 '13 at 23:53
  • Great. Glad you solved it. Thanks for accepting my answer. I appreciate it. – Andy Jul 20 '13 at 00:33
  • how can we add if (#{popupCall.showpopup()}) #{rich:component('popup')}.show(); else statement with this – Irfan Nasim Nov 27 '14 at 07:31