-
1. Re: pass return value from javascript to seam
tausuahmed Apr 21, 2010 1:50 PM (in response to marcel.m.vielsack.cluetec.de)Hi Marcel,
You can go with reverse process.
First call a javascript method and perform operation whatever is there in getValue(), and pass the result of getValue to Seam Component using seam remoting method.Check Seam Remoting...
Regards,
Tauseef -
2. Re: pass return value from javascript to seam
marcel.m.vielsack.cluetec.de Apr 22, 2010 1:22 PM (in response to marcel.m.vielsack.cluetec.de)Hey
Thanks for the reply.
I try to do it the way you suggested.Now I'm facing a new problem...
I added the @WebRemote annotation to the Java method and added<s:remote include="mySeamComponent" />
to the xhtml file.
When I try to call the method from my javascript function, i get this error (reported by firebug)
"Error: mySeamComponent.myJavaMethod is not a function"I also copied the jboss-seam-remoting.jar into the EAR-Content\lib folder.
Does anybody know a solution?
Thanks.
-
3. Re: pass return value from javascript to seam
cosmo Apr 23, 2010 4:53 PM (in response to marcel.m.vielsack.cluetec.de)Another thing you can do is to use hidden fields where you can assign the javascript value.
Take a look at this:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <body> <script> function assignValue(){ var d = new Date(); document.getElementById("form1:hidden1").setAttribute("value",d); } </script> <h:form id="form1"> <h:inputHidden id="hidden1" value="#{mySeamComponent.localTime}" /> <h:commandButton action="#{mySeamComponent.showLocalTime}" value="Submit" onclick="javascript:assignValue()"/> </h:form> </body> </html>
MySeamComponent.java
@Name("mySeamComponent") public class MySeamComponent { private String localTime; public void showLocalTime(){ System.out.println(localTime); } public String getLocalTime() { return localTime; } public void setLocalTime(String localTime) { this.localTime = localTime; } }