My problem is setting up an initial value for a Radio field using Struts. In plain old HTML you could do something by adding a "checked" key word. With Struts there doesn't seem to be any "Checked" option. With a "Select" I believe I can just assign "Value" to have my initial value; as read previously from a database (in the example its from the bean "account.") I believd this works ok. <tr> <td width="49%">Security Question</td> <td width="43%"> <html:select property="securityQuestion" value="<%=account.getSecurityQuestionType() %>"> <html ptions collection="securityquestions" property="questionText" /> </html:select> </td> </tr> The problem is with Radio buttons. From everything I've read, I either that have to : a) Set the form field value to whatever is desired and it will show up correctly. But my problem with this is that I don't see how to set it initially based on a session/request bean. I tried looking at the form "reset" method, checking for "" as an initial value and then setting it to the desired session bean value. But, my reset method wasn't being called by default. I obviously can't use my Perform Action method. b) I've seen some servlet code that spits out real html. I'd like to solve this using Struts taglib. <tr> <td width="49%">Type of Account:</td> <td width="43%"> <logic:iterate id="t" name="accounttypeset" type="java.lang.String"> <html:radio property="accountType" value="<%=t %>"/> <%=t %> </logic:iterate> </td> </tr> Any thoughts out there? I'm still a bit green in the Java/Stuts/JSP world but I've done a fair bit of hunting. Thanks, Howard
Joined: Oct 09, 2001
Your form's reset method is called at the start of every request. Try putting some logging in there to prove it. However the reset is called BEFORE struts initialises all the form fields to the values from the request. So if you have the value in your request, then it will be entered in that field. It's not clear exactly how you determine what its initial value should be - you mention session/request beans. There are struts-standard methods for doing this that the struts designers decided upon, but how to apply them depends on what you want to achieve.
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.