Announcement Announcement Module
Collapse
No announcement yet.
Why use Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why use

    I'm a little confused as to why the spring bind tag is necessary. I am currently able to fill in my command object and retrieve the command object values without its use by simply naming the form fields appropriately and associating the controller with the proper command.

    So, what does this tag provide for me and why would I want to use it?

    Thanks for any info!

  • #2
    Without spring:bind: If a validator fails and the controller executes showForm(...) to allow the user to correct the errors, the input controls will revert to their default values.


    When the spring:bind tag is used to set the control value like this

    Code:
    <spring&#58;bind path="command.property">
      <input type="text" name="$&#123;status.expression&#125;" value="$&#123;status.value&#125;" />
    </spring&#58;bind>
    the user will be presented with the erroneous value that caused validation to fail--which is more user-friendly than requiring the user to retyping the entire value.

    Top Secret - Classified
    I am almost finished with a set of JSP 2.0 tag files that will allow you to condense the above code down to something like this:

    Code:
    <html&#58;input path="command.property"/>
    By default the html:input tag uses type="text", but you can override the type by simply specifying a type attribute like this:

    Code:
    <html&#58;input type="hidden" path="command.property"/>
    You can also add any other random attribute like this (the resulting input tag will have them too):

    Code:
    <html&#58;input path="command.property" class="myClass" size="50" foo="bar" />
    And you can even override the value like this:

    Code:
    <html&#58;input type="password" path="command.password" value="" />
    They will soon be in the sandbox.

    Comment


    • #3
      Daniel, thanks for your reply, however, I'm still a little perplexed. Let me explain. I have a JSP with a couple text fields and selects on it. Each text field, for example, is named according to the name that it corresponds to in the command object, like so:

      Command object:

      Code:
      private String keyword;
      
      public String getKeyword&#40;&#41;&#123;...&#125;
      
      public setKeyword&#40;String keyword&#41;&#123;...&#125;
      JSP:

      Code:
      <input type="text" name="keyword" value="$&#123;command.keyword&#125;">
      Now, in my controller, I force it to always go to showForm by overriding the isFormChangeRequest(...) method and returning true (after a certain condition it finally allows the form submission to occur). When I return true from this method it always calls showForm(...) (as I can see from when I debug it). When the form first loads the text field is blank, I type something in, click submit, which calls showForm, and when the JSP reloads, the value that was typed in for keyword is there in the JSP and I'm not making any use of the <spring:bind> tag nor am I storing anything in the session.

      Is there something I'm missing here?

      Thanks again!

      Comment


      • #4
        Try binding to a Date or Integer property. Enter "abc" in the field and submit the form. Now what do you get back?

        Comment


        • #5
          Ahhhh...got ya. Now I get it. Thanks!

          Comment


          • #6
            I believe Spring made an explicit choice not to provide struts-like form tags. This is a good thing as it allows html editors to work with standard html tags. As of JSP 2.0 the typing work is reduced because you can drop the <c:out/> tags and directly type ${status.expression} to get bound values.

            Comment

            Working...
            X