3

I'm using JSF OpenFaces, and I have an Ajax call in a command button.

This Ajax call, calls a Java method, and it has onsuccuess and onfailure attributes.

<o:commandLink value="Save" id="SaveButton"
                    action="#{operationController.save}"
                    onsuccess="#Do something#" 
                    onerror="#Do something else#"/>

The java is quite simple:

public void save() {
             if(case1)
                  doAction1();
             else if(case2)
                  doAction2(); //throw new error?
}

What I want to do, without sending the event to the Java method (due to code\signature limitation), is to invoke 1 JS function in case1 and another JS function in case2.

I thought about throwing an error in case2 and then I know it will go to the onerror attribute, but I don't think it's a good practice.

I thought about putting an if inside the onsuccess but I don't know what can I check there.

What else can I do?

Thanks

Dvir
  • 301
  • 1
  • 2
  • 16
  • When the user clicks the button: What exactly do you want to happen on server side (Java code) and on client side (JavaScript code)? I don't yet get it. – Selaron Oct 24 '18 at 06:11
  • @Selaron - thx - there is a general button that the user clicks, after the clicking, the `save` method invoked, and inside this method, the java code checks something generally (let's say - checking boolean var), and I want to invoke a general js function if this var is true and another js if it's false. – Dvir Oct 24 '18 at 06:26
  • Other question: I had used OpenFaces years ago but it seames to be kind of dead. Can't connect to openfaces.org. Is the project alive somwhere else? Do you also use Primefaces or Omnifaces? – Selaron Oct 24 '18 at 06:43
  • BalusC has written down some ideas on this topic: https://stackoverflow.com/questions/5675017/calling-a-javascript-function-from-managed-bean – Selaron Oct 24 '18 at 06:49
  • @Selaron as one who used their paid version with the support, I can tell you that they died. no support, no documentation. nothing. officially. – Dvir Oct 24 '18 at 08:25

0 Answers0