Announcement Announcement Module
Collapse
No announcement yet.
Submit AbstractWizardFormController via href url Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Submit AbstractWizardFormController via href url

    How do you submit a page to an AbstractWizardFormController from a href url?

    I have a jsp page with a list of appointment times as urls. I also have a javascript function which inserts values into hidden form fields i.e. the date, appointment time etc and submits the form when one of these urls is clicked.

    BookingWizardFormController code:
    Code:
    protected Map referenceData(HttpServletRequest request,
                                                        int page)
                                                        throws Exception {
        System.out.println("referenceData method");
    
        // If the page is the stylist and services page.
        if(page == 0) {
          return getFirstPageModel();
        } else if(page == 1) {
          return getSecondPageModel(request);
        } else if(page == 2) {
          return getThirdPageModel(request);
        }
       
        return null;
      }

    As things stand the referenceData method is called as the println statement appears in the console. The problem is that the page value has not been set when the page was submitted. Below is the code for the href and javascript.

    href code:
    Code:
    <a href="javascript&#58;submitForm&#40;
                    '<c&#58;out value="$&#123;stylist&#125;"/>',
                    '<c&#58;out value="$&#123;service&#125;"/>',
                    '<fmt&#58;formatDate value="$&#123;date&#125;"
                                     type="date"
                                     pattern="dd/MM/yyyy"/>',
                    '<c&#58;out value="$&#123;appointment.time&#125;"/>'&#41;" name="_target2">
                    <c&#58;out value="$&#123;appointment.time&#125;"/>
                  </a>

    javascript code:
    Code:
    function submitForm&#40;stylist, service, date, time&#41; &#123;
            document.dateAndTime.stylist.value = stylist;
            document.dateAndTime.service.value = service;
            document.dateAndTime.date.value = date;
            document.dateAndTime.time.value = time;
     
            document.dateAndTime.submit&#40;&#41;;
          &#125;

    These values should be sent to the wizard controller to be displayed in a confirmation screen. I am using the default getTargetPage method. Unfortunately the _target2 page variable isn't getting picked up in the referenceData method as I don't believe it is getting sent to the controller, therefore no proccess is occurring.

    Is there a way around this?

    Ideally I wouldn't use javascript and hidden fields but I could not find any other way to submit a form via urls.

    Any help is gratefully appreciated.

    MARK

    CIAO

  • #2
    I have a similar problem

    html:
    Code:
    ....
    <script type="text/javascript">
    // <!--
    function goToPage&#40;targetN&#41; &#123;
        pageN = targetN + 1;
        document.forms&#91;"itemForm"&#93;.setAttribute&#40;'action', 'editItem.html?_target' + targetN + '&_page=' + pageN&#41;;
        alert&#40;document.forms&#91;"itemForm"&#93;.getAttribute&#40;'action'&#41;&#41;;
        document.forms&#91;"itemForm"&#93;.submit&#40;&#41;;
    &#125;
    // -->
    </script>
    .....
    <form method="post" action="" name="itemForm">
    .....
    <ul id="menuList">
        <li>
            <a href="" title="Main" name="_target0" onclick="javascript&#58;goToPage&#40;0&#41;>Main</a>
        </li>
        <li>
             <a href="" title="Attributes" name="_target1" onclick="javascript&#58;goToPage&#40;1&#41;">Attributes</a>
        </li>
    </ul>
    ....
    <input type="submit" class="button" name="_target0" value="0" />
    <input type="submit" class="button" name="_target1" value="1" />
    </form>
    If I use the buttons at the end of code, everything works = I can change page
    if I use href it doesn't work

    my log after 4 clicks:
    1. using javascript for _target0
    2. using javascript for _target1
    3. using button for _target0
    4. using button for _target1
    Code:
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;448&#41; | Validating wizard page 1 for form bean 'item'
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;454&#41; | Target page 0 requested
    DEBUG - AbstractWizardFormController.showPage&#40;322&#41; | Showing wizard page 0 for form bean 'item'
    DEBUG - AbstractFormController.showNewForm&#40;290&#41; | Displaying new form
    DEBUG - AbstractWizardFormController.showPage&#40;322&#41; | Showing wizard page 0 for form bean 'item'
    ----------------------------------
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;448&#41; | Validating wizard page 2 for form bean 'item'
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;454&#41; | Target page 1 requested
    DEBUG - AbstractWizardFormController.showPage&#40;322&#41; | Showing wizard page 1 for form bean 'item'
    DEBUG - AbstractFormController.showNewForm&#40;290&#41; | Displaying new form
    DEBUG - AbstractWizardFormController.showPage&#40;322&#41; | Showing wizard page 0 for form bean 'item'
    --------------------------
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;448&#41; | Validating wizard page 0 for form bean 'item'
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;454&#41; | Target page 0 requested
    DEBUG - AbstractWizardFormController.showPage&#40;322&#41; | Showing wizard page 0 for form bean 'item
    --------------------------
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;448&#41; | Validating wizard page 0 for form bean 'item'
    DEBUG - AbstractWizardFormController.processFormSubmission&#40;454&#41; | Target page 1 requested
    DEBUG - AbstractWizardFormController.showPage&#40;322&#41; | Showing wizard page 1 for form bean 'item'
    My AbstractWizardFormController is basic
    Code:
    public class ItemWizardController extends AbstractWizardFormController &#123;
    
    	private ItemManager itemManager = null;
    
    	public void setItemManager&#40;ItemManager itemManager&#41; &#123;
    		this.itemManager = itemManager;
    	&#125;
    
    	public ItemWizardController&#40;&#41; &#123;
    		setCommandName&#40;"item"&#41;;
    		setPages&#40;new String&#91;&#93; &#123;"editItemMain", "editItemAttributes", "editItemFiles"&#125;&#41;;
    	&#125;
    
    	protected ModelAndView processFinish&#40;HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors&#41;
    			throws Exception &#123;
    
    		Item item = &#40;Item&#41; command;
    		item.setId&#40;Long.valueOf&#40;"10"&#41;&#41;;
    
    		return new ModelAndView&#40;"ok", "item", item&#41;;
    	&#125;
    
    	protected ModelAndView processCancel&#40;HttpServletRequest request,
    			HttpServletResponse response, Object command,
    			BindException bindException&#41; throws Exception &#123;
    		return new ModelAndView&#40;"editItem"&#41;;
    	&#125;
    
    
    	protected Object formBackingObject&#40;HttpServletRequest request&#41;
    			throws ServletException &#123;
    
    		return new Item&#40;&#41;;
    	&#125;
    &#125;
    Any idea?

    Thanks

    Comment


    • #3
      I solved my problem adding a hidden input :idea: and modifing the javascript

      jsp:
      Code:
      <form method="post" action="" name="itemForm">
      <input type="hidden" name="target" value="">
      ....
      <ul id="menuList">
          <li>
              <a href="#" title="Main"  onclick="javascript&#58;goToTarget&#40;0&#41;">Main</a>
           </li>
           <li>
               <a href="#" title="Attributes" onclick="javascript&#58;goToTarge&#40;1&#41;">Attributes</a>
           </li>
      </ul>
      ....
      </form>
      javascript:
      Code:
      function goToTarget&#40;targetN&#41; &#123;
      	MyForm = document.forms&#91;0&#93;;
      	MyForm.elements&#91;'target'&#93;.setAttribute&#40;'name','_target' + targetN&#41;;
      	MyForm.submit&#40;&#41;;
      &#125;
      I hope this could be useful for mark

      Comment


      • #4
        Hi there,

        Thanx for your input guys, I thought I had solved it by using buttons instead of urls and using css to make the button look like a url. That way I got rid of using Javascript which was cool as I am not a fan of Javascript, also it can be turned of which would break my site.

        Unfortunately I ran into a problem, I was returning the value of the url clicked on as a parameter i.e. the values of the buttons where 9:00 9:45 10:30 etc in increments of 45.

        Problem is I can't get the value of the button and pass it as a parameter unless I use Javascript onClick to set the hidden value.

        If anyone knows of any other way then great let me know but I reckon I am stuck with this.

        MARK

        CIAO

        Comment


        • #5
          <a href="javascript:documents.forms[0].submit()">Blah</a>

          You could add javascript to the above to set hidden fields also I guess.

          Also, if you continue to use buttons and are using CSS to make them look like links, then the name of the button should automatically be posted.

          e.g.

          <input type="submit" style="looksLikeALink" name="_doSomething" value="Click Me"/>

          This should still mean that you get _doSomething being passed as a request parameter.

          Comment


          • #6
            Not able to navigate using Href

            Hi All,

            I have a 4 pages Wizard and am using AbstractWizardFormController,On success,the 4th page is shown and I have a hyperlink in this page which would take me to the second page.

            I am able to display to the second page using button,but when I use the hyperlink the first page is only getting displayed.Actually when I go through the logs,the second page is being called but after that the first page is called.Hence the first page is fnally displayed to the user.
            I 've tried to have a hidden field and set the target name onClick method but does'nt seem to work.

            Any suggestions to solve this issue would be of great help to me.

            Comment

            Working...
            X