FAQ
I have a page which detects some browser properties (browser window
width, etc.) and I would like to submit these capabilities automatically
using a javascript like

document.forms['mySecretAndHiddenForm'].submit();

However this does not seem to work. In other words: Automatically
invoking submit from javascript does not seem to yeild the same results
as making the user click a form button manually - probably because the
action of the form is never set.

Is there a standard way to submit hidden form fields using javascript?
Now I guess I could manually set the action of the form to something like
"#{evaluationBean.evaluate}"
using javascript and then call submit afterwards, but it does not feel
right to hard-code this into my javascript - I sence there has got to be
a better, cleaner way.

Any suggestions would be highly appreciated.

Randahl


Here follows my forms JSF code:
<h:form id="mySecretAndHiddenForm">
<h:inputText id="windowInnerWidth"
value="#{evaluationBean.windowInnerWidth}"/>
<h:inputText id="windowInnerHeight"
value="#{evaluationBean.windowInnerHeight}"/>
[...]
<h:commandButton
id="sendProperties"
type="SUBMIT"
action="#{evaluationBean.evaluate}"
/>
</h:form>

Search Discussions

  • Galen Dunkleberger at Jun 16, 2005 at 11:45 pm
    This document.forms['mySecretAndHiddenForm'].submit(); probably isn't
    working for you because it's not the id of the form once jsf has
    renderd it. If you look at the source of the generated html page the
    id of you form has all the names of the parent containers seperated by
    :. Anyway i've found the j4j tag library's idProxy tag works great for
    getting the correct id of an element from javascript.
    On 6/16/05, Randahl Fink Isaksen wrote:
    I have a page which detects some browser properties (browser window
    width, etc.) and I would like to submit these capabilities automatically
    using a javascript like

    document.forms['mySecretAndHiddenForm'].submit();

    However this does not seem to work. In other words: Automatically
    invoking submit from javascript does not seem to yeild the same results
    as making the user click a form button manually - probably because the
    action of the form is never set.

    Is there a standard way to submit hidden form fields using javascript?
    Now I guess I could manually set the action of the form to something like
    "#{evaluationBean.evaluate}"
    using javascript and then call submit afterwards, but it does not feel
    right to hard-code this into my javascript - I sence there has got to be
    a better, cleaner way.

    Any suggestions would be highly appreciated.

    Randahl


    Here follows my forms JSF code:
    <h:form id="mySecretAndHiddenForm">
    <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/>
    <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/>
    [...]
    <h:commandButton
    id="sendProperties"
    type="SUBMIT"
    action="#{evaluationBean.evaluate}"
    />
    </h:form>

  • Enrique Medina at Jun 17, 2005 at 5:28 am
    Or you can use forceId ;-)

    2005/6/17, Galen Dunkleberger <galendunkleberger@gmail.com>:
    This document.forms['mySecretAndHiddenForm'].submit(); probably isn't
    working for you because it's not the id of the form once jsf has
    renderd it. If you look at the source of the generated html page the
    id of you form has all the names of the parent containers seperated by
    :. Anyway i've found the j4j tag library's idProxy tag works great for
    getting the correct id of an element from javascript.
    On 6/16/05, Randahl Fink Isaksen wrote:
    I have a page which detects some browser properties (browser window
    width, etc.) and I would like to submit these capabilities automatically
    using a javascript like

    document.forms['mySecretAndHiddenForm'].submit();

    However this does not seem to work. In other words: Automatically
    invoking submit from javascript does not seem to yeild the same results
    as making the user click a form button manually - probably because the
    action of the form is never set.

    Is there a standard way to submit hidden form fields using javascript?
    Now I guess I could manually set the action of the form to something like
    "#{evaluationBean.evaluate}"
    using javascript and then call submit afterwards, but it does not feel
    right to hard-code this into my javascript - I sence there has got to be
    a better, cleaner way.

    Any suggestions would be highly appreciated.

    Randahl


    Here follows my forms JSF code:
    <h:form id="mySecretAndHiddenForm">
    <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/>
    <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/>
    [...]
    <h:commandButton
    id="sendProperties"
    type="SUBMIT"
    action="#{evaluationBean.evaluate}"
    />
    </h:form>

  • Randahl Fink Isaksen at Jun 17, 2005 at 6:22 am
    I found a very simple javascript solution:
    form.elements['myForm:myButton'].click()

    This simulates a user click on the button. I have simply hidden the button using CSS, so the user
    does not see that a GUI form is used. Still I would like NOT to involve a button at all. Does anyone
    know what it takes to make a regular javascript submit work? Something like
    form.submit();

    In response to Galen Dunklebergers post:
    I have verified that my "form" var is does indeed contain the form object, but invoking
    ".submit()" simply reloads the same page as if MyFaces does not realize what just happened. I
    was guessing that this is because the simulated click makes the browser set the "action=xyz"
    parameter of the request, but I have not been able to simulate this by something like
    action='xyz'.

    I will do some more testing, but if someone has already been down this alley, I would be happy to
    hear from you.

    Randahl

    Enrique Medina wrote: Or you can use forceId ;-) 2005/6/17, Galen Dunkleberger
    <galendunkleberger@gmail.com>: This
    document.forms['mySecretAndHiddenForm'].submit(); probably isn't working for you
    because it's not the id of the form once jsf has renderd it. If you look at the source of the
    generated html page the id of you form has all the names of the parent containers seperated by :.
    Anyway i've found the j4j tag library's idProxy tag works great for getting the correct id of an
    element from javascript. On 6/16/05, Randahl Fink Isaksen wrote: I
    have a page which detects some browser properties (browser window width, etc.) and I would
    like to submit these capabilities automatically using a javascript like
    document.forms['mySecretAndHiddenForm'].submit(); However this does not seem to work.
    In other words: Automatically invoking submit from javascript does not seem to yeild the same
    results as making the user click a form button manually - probably because the action of the
    form is never set. Is there a standard way to submit hidden form fields using javascript? Now I
    guess I could manually set the action of the form to something like
    "#{evaluationBean.evaluate}" using javascript and then call submit afterwards, but it
    does not feel right to hard-code this into my javascript - I sence there has got to be a better,
    cleaner way. Any suggestions would be highly appreciated. Randahl Here follows my forms JSF
    code: <h:form id="mySecretAndHiddenForm"> <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/> <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/> [...] <h:commandButton
    id="sendProperties" type="SUBMIT" action="#{evaluationBean.evaluate}" /> </h:form>
  • Slawek at Jun 18, 2005 at 1:37 pm
    u cant simple fire submit.
    jsf stuff works cause when u click on commandbuttn or sth than few things
    are set by JS (ex. form action). so submiting without seting that "magic
    things" doesnt make any sense.

    clicking on button performs setting jsf stuff so u must find that button
    and click it:

    document.getElementById('formId:buttonId').click();


    cheers
    Slawek
    I found a very simple javascript solution:
    form.elements['myForm:myButton'].click()

    This simulates a user click on the button. I have simply hidden the
    button using
    CSS, so the user does not see that a GUI form is used. Still I would
    like NOT to
    involve a button at all. Does anyone know what it takes to make a regular
    javascript submit work? Something like
    form.submit();

    In response to Galen Dunklebergers post:
    I have verified that my "form" var is does indeed contain the form
    object, but
    invoking ".submit()" simply reloads the same page as if MyFaces does not
    realize
    what just happened. I was guessing that this is because the simulated
    click
    makes the browser set the "action=xyz" parameter of the request, but I
    have not
    been able to simulate this by something like
    action='xyz'.

    I will do some more testing, but if someone has already been down this
    alley, I
    would be happy to hear from you.


    Randahl




    Enrique Medina wrote:

    Or you can use forceId ;-)

    2005/6/17, Galen Dunkleberger <galendunkleberger@gmail.com>:


    This document.forms['mySecretAndHiddenForm'].submit(); probably isn't
    working for you because it's not the id of the form once jsf has
    renderd it. If you look at the source of the generated html page the
    id of you form has all the names of the parent containers seperated by
    :. Anyway i've found the j4j tag library's idProxy tag works great for
    getting the correct id of an element from javascript.

    On 6/16/05, Randahl Fink Isaksen wrote:


    I have a page which detects some browser properties (browser window
    width, etc.) and I would like to submit these capabilities automatically
    using a javascript like

    document.forms['mySecretAndHiddenForm'].submit();

    However this does not seem to work. In other words: Automatically
    invoking submit from javascript does not seem to yeild the same results
    as making the user click a form button manually - probably because the
    action of the form is never set.

    Is there a standard way to submit hidden form fields using javascript?
    Now I guess I could manually set the action of the form to something like
    "#{evaluationBean.evaluate}"
    using javascript and then call submit afterwards, but it does not feel
    right to hard-code this into my javascript - I sence there has got to be
    a better, cleaner way.

    Any suggestions would be highly appreciated.

    Randahl


    Here follows my forms JSF code:
    <h:form id="mySecretAndHiddenForm">
    <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/>
    <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/>
    [...]
    <h:commandButton
    id="sendProperties"
    type="SUBMIT"
    action="#{evaluationBean.evaluate}"
    />
    </h:form>





  • Randahl Fink Isaksen at Jun 19, 2005 at 2:34 pm
    Then I think the MyFaces developers should change the design, so the
    button invokes a JS function called submit() which I can invoke directly
    without using the button. Right now, I think it is a really awkvard
    solution to place a button on a page and then deliberately hiding the
    button using CSS - that is what I have been forced to do, to make sure
    the user does not click it before my script submits the form
    automatically. Using a button on a GUI-less page seems really odd, I think.

    Randahl


    Slawek wrote:
    u cant simple fire submit.
    jsf stuff works cause when u click on commandbuttn or sth than few
    things are set by JS (ex. form action). so submiting without seting
    that "magic things" doesnt make any sense.

    clicking on button performs setting jsf stuff so u must find that
    button and click it:

    document.getElementById('formId:buttonId').click();


    cheers
    Slawek
    I found a very simple javascript solution:
    form.elements['myForm:myButton'].click()

    This simulates a user click on the button. I have simply hidden the
    button using
    CSS, so the user does not see that a GUI form is used. Still I would
    like NOT to
    involve a button at all. Does anyone know what it takes to make a
    regular
    javascript submit work? Something like
    form.submit();

    In response to Galen Dunklebergers post:
    I have verified that my "form" var is does indeed contain the form
    object, but
    invoking ".submit()" simply reloads the same page as if MyFaces does
    not realize
    what just happened. I was guessing that this is because the simulated
    click
    makes the browser set the "action=xyz" parameter of the request, but
    I have not
    been able to simulate this by something like
    action='xyz'.

    I will do some more testing, but if someone has already been down
    this alley, I
    would be happy to hear from you.


    Randahl




    Enrique Medina wrote:

    Or you can use forceId ;-)

    2005/6/17, Galen Dunkleberger <galendunkleberger@gmail.com>:


    This document.forms['mySecretAndHiddenForm'].submit(); probably isn't
    working for you because it's not the id of the form once jsf has
    renderd it. If you look at the source of the generated html page the
    id of you form has all the names of the parent containers seperated by
    :. Anyway i've found the j4j tag library's idProxy tag works great for
    getting the correct id of an element from javascript.

    On 6/16/05, Randahl Fink Isaksen wrote:


    I have a page which detects some browser properties (browser window
    width, etc.) and I would like to submit these capabilities automatically
    using a javascript like

    document.forms['mySecretAndHiddenForm'].submit();

    However this does not seem to work. In other words: Automatically
    invoking submit from javascript does not seem to yeild the same results
    as making the user click a form button manually - probably because the
    action of the form is never set.

    Is there a standard way to submit hidden form fields using javascript?
    Now I guess I could manually set the action of the form to something
    like
    "#{evaluationBean.evaluate}"
    using javascript and then call submit afterwards, but it does not feel
    right to hard-code this into my javascript - I sence there has got to be
    a better, cleaner way.

    Any suggestions would be highly appreciated.

    Randahl


    Here follows my forms JSF code:
    <h:form id="mySecretAndHiddenForm">
    <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/>
    <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/>
    [...]
    <h:commandButton
    id="sendProperties"
    type="SUBMIT"
    action="#{evaluationBean.evaluate}"
    />
    </h:form>






  • Adrien FOURES at Jun 17, 2005 at 8:09 am
    Hello Randahl,

    If i have understand your question, try this:

    <body onload="test()">
    [...]
    <script language="Javascript">
    function test(){
    document.getElementById('mySecretAndHiddenForm:sendProperties').click();
    }
    </scipt>
    </body>

    or

    <body>
    [...]
    <script language="Javascript">
    test();
    function test(){
    document.getElementById('mySecretAndHiddenForm:sendProperties').click();
    }
    </script>
    </body>


    Adrien



    Randahl Fink Isaksen wrote:
    I have a page which detects some browser properties (browser window
    width, etc.) and I would like to submit these capabilities
    automatically using a javascript like

    document.forms['mySecretAndHiddenForm'].submit();

    However this does not seem to work. In other words: Automatically
    invoking submit from javascript does not seem to yeild the same
    results as making the user click a form button manually - probably
    because the action of the form is never set.

    Is there a standard way to submit hidden form fields using javascript?
    Now I guess I could manually set the action of the form to something like
    "#{evaluationBean.evaluate}"
    using javascript and then call submit afterwards, but it does not feel
    right to hard-code this into my javascript - I sence there has got to
    be a better, cleaner way.

    Any suggestions would be highly appreciated.

    Randahl


    Here follows my forms JSF code:
    <h:form id="mySecretAndHiddenForm">
    <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/>
    <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/>
    [...]
    <h:commandButton
    id="sendProperties"
    type="SUBMIT"
    action="#{evaluationBean.evaluate}"
    />
    </h:form>


  • Randahl Fink Isaksen at Jun 18, 2005 at 11:09 am
    Thanks Adrien - I guess we wrote e-mails at the same time... as stated
    in the previous e-mail I have just tried such a solution. Still I wish
    there was a more standard way...

    R.


    Adrien FOURES wrote:
    Hello Randahl,

    If i have understand your question, try this:

    <body onload="test()">
    [...]
    <script language="Javascript">
    function test(){

    document.getElementById('mySecretAndHiddenForm:sendProperties').click();
    }
    </scipt>
    </body>

    or

    <body>
    [...]
    <script language="Javascript">
    test();
    function test(){

    document.getElementById('mySecretAndHiddenForm:sendProperties').click();
    }
    </script>
    </body>


    Adrien



    Randahl Fink Isaksen wrote:
    I have a page which detects some browser properties (browser window
    width, etc.) and I would like to submit these capabilities
    automatically using a javascript like

    document.forms['mySecretAndHiddenForm'].submit();

    However this does not seem to work. In other words: Automatically
    invoking submit from javascript does not seem to yeild the same
    results as making the user click a form button manually - probably
    because the action of the form is never set.

    Is there a standard way to submit hidden form fields using
    javascript? Now I guess I could manually set the action of the form
    to something like
    "#{evaluationBean.evaluate}"
    using javascript and then call submit afterwards, but it does not
    feel right to hard-code this into my javascript - I sence there has
    got to be a better, cleaner way.

    Any suggestions would be highly appreciated.

    Randahl


    Here follows my forms JSF code:
    <h:form id="mySecretAndHiddenForm">
    <h:inputText id="windowInnerWidth"
    value="#{evaluationBean.windowInnerWidth}"/>
    <h:inputText id="windowInnerHeight"
    value="#{evaluationBean.windowInnerHeight}"/>
    [...]
    <h:commandButton
    id="sendProperties"
    type="SUBMIT"
    action="#{evaluationBean.evaluate}"
    />
    </h:form>


Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriesmyfaces
postedJun 16, '05 at 10:47p
activeJun 19, '05 at 2:34p
posts8
users5
websitemyfaces.apache.org

People

Translate

site design / logo © 2019 Grokbase