1

I have a javascript function responsible to call 2 managed bean methods using <p:remoteCommand/> the problem is that in one method i have to generate a value and use it in the second method, but when I call to the second method the value is null and this is because the ManagedBean is recreated each request, here is my code:

javascriptFile.js

<script>
function executeProcess(){
      method1();
      method2();
}
</script>

myView.xhtml

<h:form>
<p:remoteCommand name="method1"
                        actionListener="#{controller.method1()}"
                        update="xComponent" />
<p:remoteCommand name="method2"
                        actionListener="#{controller.method2()}"
                        update="xComponent" />

</h:form>

Controller.java

@ManagedBean
@ViewScoped
public class SearchCarneStudent implements Serializable {
     private String myValue;

     public void method1(){
           myValue="Hello";
     }

     public void method2(){
         System.out.println(myValue);  //<- This line is returning null because the bean is recreated each request
     }    

}

I hope you can help me

Thanks

Kukeltje
  • 12,223
  • 4
  • 24
  • 47

0 Answers0