3 Replies Latest reply on Apr 23, 2010 4:53 PM by Aldo Bonzi

    pass return value from javascript to seam

    Marcel Vielsack Newbie


      I want to store the return value of a javascript in a seam component, but i just don't know how to do this.

      Things like this don't work:

      <h:commandButton value="submit" action="#{mySeamComponent.store(javascript:getValue())}"/>

      Has anybody an idea?


      Cheers Marcel

        • 1. Re: pass return value from javascript to seam
          Tauseef Ahmed Newbie

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


          • 2. Re: pass return value from javascript to seam
            Marcel Vielsack Newbie


            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?


            • 3. Re: pass return value from javascript to seam
              Aldo Bonzi Novice

              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"
                             function assignValue(){
                                  var d = new Date();
                        <h:form id="form1">
                             <h:inputHidden id="hidden1" value="#{mySeamComponent.localTime}" />
                             <h:commandButton action="#{mySeamComponent.showLocalTime}" value="Submit" onclick="javascript:assignValue()"/>


              public class MySeamComponent {
                   private String localTime;
                   public void showLocalTime(){
                   public String getLocalTime() {
                        return localTime;
                   public void setLocalTime(String localTime) {
                        this.localTime = localTime;