aspose file tools*
The moose likes Struts and the fly likes text area +populating with default value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "text area +populating with default value" Watch "text area +populating with default value" New topic
Author

text area +populating with default value

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
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.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


  • Merrill
    Consultant, Sima Solutions
    A knibbs
    Ranch Hand

    Joined: Aug 23, 2006
    Posts: 158
    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

    Joined: Aug 23, 2006
    Posts: 158
    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 ?
    Brent Sterling
    Ranch Hand

    Joined: Feb 08, 2006
    Posts: 948
    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

    Joined: Aug 23, 2006
    Posts: 158
    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.
     
     
    subject: text area +populating with default value