6 Replies Latest reply: May 12, 2008 1:37 AM by 637500 RSS

    How to do submit without any button

    637500
      Hi ,

      i am using Jdev 10.1.3.1 .
      i am using JSF ADF BC Technology. i am having a problem. how to do submit the values in inputHidden field without submit or any button.
      even i bind the method in valueChangeListner like below.it is not submit.Am i did any mistake? plz go thru this code and help me.
      Hidden there is no auto submit attribute.


      Code:
      <af:form>
      <af:inputHidden id="startDate"
      value="#{bindings.Eventdate.inputValue}"
      valueChangeListener="#{bindings.Execute.execute}"
      required="false"/>

      <af:commandLink text="search" actionListener="#bindings.Execute.execute}"/>

      OR

      <af:commandButton actionListener="#{bindings.Execute.execute}"
      text="Search"
      disabled="#{!bindings.Execute.enabled}"/>


      </af:form>

      i dont want to use command link or command button for action. how to submit the value in hidden field which is set by javascript function to the corresponding action.
      could you please help me out regarding this?? .


      Thanks & Regards,
      Arun
        • 1. Re: How to do submit without any button
          jflack
          Let me see if I have your use case correctly:
          The user views the page, and some event triggers some Javascript code. The Javascript code needs to set the values of a hidden field, then submit the form, executing the action named Execute in the bindings.

          First of all, get rid of the valueChangeListener. If you were to use a valueChangeListener, it would have to reference a method in a backing bean that takes a valueChangeEvent as its argument and returns void. Now try this - I haven't tried it myself, so I don't know that it will work, but I think it will. On your page:
          <af:form id="theForm" defaultCommand="executeButton">
            <af:inputHidden id="startDate" value="#{bindings.Eventdate.inputValue}" />
            <af:commandButton id="executeButton"
                                          actionListener="#{bindings.Execute.execute}"
                                          text="Search"
                                          disabled="#{!bindings.Execute.enabled}"
                                          inlineStyle="display: none;" />
          </af:form>
          And in your Javascript function:
          document.theForm.submit();
          The basic idea is that the defaultCommand property of the form says that any submit of the form defaults to the button with the id=executeButton, unless some other button or link is explicitly clicked. The button has an inlineStyle with display none, which hides it from the user. Then the Javascript submits the form which ought to execute the default command.
          • 2. Re: How to do submit without any button
            637500
            Hi jflag,

            Thanks for your reply. nice to see this..

            My UseCase:

            i am having search page. in that page javascript triggers and it is showing the calender. when i click the date. it will set the value to my hidden field. without any other action(by clicking command button or commandlink) it should post the values. if javascript didnt return any values it will show all the data without any search criteria. This is my requirement.

            i made alert statement in javascript code before submitting,

            as per you mentioned :

            alert(document.getElementById("form").startDate.value);
            document.form.submit();

            It is showing the date which is selected.

            i want to know whether we are submiting this form by using javascript or ADF command button?

            I tried the same.it is not submiting the paricular selected date.
            It just refreshing and displaying all the data.

            could u help me..

            Thanks & Regards,

            Arun
            • 3. Re: How to do submit without any button
              jflack
              If you need a calendar, why not just use a <af:selectInputDate> component? You can even set the autoSubmit property to "true" which will automatically submit the form as soon as the user selects a date. Or if you are using PartialTriggers, it will do a partial submit and update only the components that are registered there.
              • 4. Re: How to do submit without any button
                637500
                Hi jflag,

                Thanks for your reply. nice to see this..

                My UseCase:

                i am using javascript calendar to achive hijiri calender.i dont want datepicker. i just want to show the calendar in page in the form of hijiri or gregorean.

                i am having search page. in that page javascript triggers and it is showing the calender. when i click the date. it will set the value to my hidden field. without any other action(by clicking command button or commandlink) it should post the values. if javascript didnt return any values it will show all the data without any search criteria. This is my requirement.

                As Per your previous post i did the things,
                here is the details.

                i made alert statement in javascript code before submitting,

                as per you mentioned :

                alert(document.getElementById("form").startDate.value);
                document.form.submit();

                It is showing the date which is selected.

                i want to know whether we are submiting this form by using javascript or ADF command button?

                I tried the same.it is not submiting the paricular selected date.
                It just refreshing and displaying all the data.

                could u help me..

                Thanks & Regards,

                Arun
                • 5. Re: How to do submit without any button
                  jflack
                  You got me curious, so I went ahead and created a demo application to try this for myself. I'm using JDev 10.1.3.3. Actually, I was pretty close to the right answer. It turns out that a commandButton element in ADF Faces doesn't really generate a button in HTML (or XHTML), it generates an anchor around an image of a button. And that anchor has an "onclick" event that calls some Javascript that the renderer puts into the page. So to submit the form as if the user pressed the button, all you have to do is call the same Javascript function that the "onclick" event calls.

                  Use the same code in the page as I gave before - the same properties for the form and the commandButton. In your Javascript function, at the point where you want the script to submit the form, add this code:
                  submitForm('theForm',1,{source:'executeButton'});return false;
                  One warning - if a future version of ADF Faces changes how it renders the HTML and Javascript for a commandButton, this may not continue to work. I doubt that this will be a problem in the near future, however.
                  • 6. Re:[solved] How to do submit without any button
                    637500
                    Hi jflack,

                    Thanks alot.. By using your suggestion and code i got the solution.
                    Its working fine..Thanks a lot for your help.

                    Thanks & Regards,

                    Arun