Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

text area +populating with default value

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I have the following text tag but it isn't working quite like I would like. I am trying to allow user to change the shipping address, but I want to populate it with the default values in the event that they don't need to change it - there is more than one field, but I am working with one too see the effects.
I have tried the following and various ideas around it but haven't had any success. Can someone suggest something else ? With the below code the value is displayed exactly as it is instead of pulling that value - can someone give me an idea of how to give it that default value ?


<html:text property="shipTo" size="30" maxlength="30" value="currOrder.getShipTo" />

thanks in advance.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's how you do it:

  • Create a property on your ActionForm bean for every input on the form with corresponding getters and setters
  • In the Action class that forwards to this JSP, populate the ActionForm with the values you want displayed
  • That's it! the <html:text> tag will automatically pick up the value from the ActionForm bean and display it. do not specify a value attribute for this tag.

  •  
    A knibbs
    Ranch Hand
    Posts: 158
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    D'oh

    I can't believe it's that simple*



    *Still reserving the right to come back when I realize that I have indeed screwed up the "simple" thing.
     
    A knibbs
    Ranch Hand
    Posts: 158
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I got the default values to work and it was quite simple once i got over the stupid spelling mistakes that I was making. I do however have a further question on the matter. I want to be able to toggle between being able to edit and not edit the values in fields. Essentially on my jsp page there will be button to change the listed information. I am looking for the best manner in which to accomplish this. I assume that it will be something along the lines of submitting back to the same page only changing a variable such as setEditable to true - does something like this work ?
     
    Ranch Hand
    Posts: 948
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yea, something like that would work. Since the initial page is just read-only data, you would not really have to submit the page. You could just pass some type of id and the isEditable flag on a url. Another option might be to hide/show fields on your page or enable/disable fields using some form of DHTML.

    - Brent
     
    A knibbs
    Ranch Hand
    Posts: 158
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I was playing around with having a variable that I can toggle, but can't seem to get the right syntax, so I was hoping that someone could fill in my knowledge with respect to weather or not it is possible to do something like the following:

    <html:text name="User" property="currOrder.shipTo" readonly="<bean:write name="OrderForm" property="delete"/>" ></html:text>

    the part I am wondering about is using a bean write inside of the html:text. I am guessing that it can't be used as it seems that that would require interpretation twice on the same portion of code, but if there is a similar manner that would allow me to alter the readonly tag could someone please let me know about it.

    thanks in advance for your time.
     
    WARNING! Do not activate jet boots indoors or you will see a tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic