Struts 1: Accessing form values with bean:write

15,386

writing properties from a form with bean:write is possible with using the form name. in your case you can use the following code:

form: <bean:write name="TestForm"/>##
id = <bean:write name="TestForm" property="id" />

This should work better i guess

Share:
15,386
risingTide
Author by

risingTide

I am a human bean.

Updated on June 05, 2022

Comments

  • risingTide
    risingTide almost 2 years

    Greetings,

    This is a simple question I believe, but nonetheless it is stumping me right now.

    I have a TestForm class with your usual getters/setters...for example I have an "id" field with "getId" and "setId" methods.

    My form is populated in an action class correctly (which I know from stepping through the Eclipse debugger) just before it is sent to the jsp page which has the code below:

    <html:form action="/AppropriateAction">  
    <bean:define id="testFormA" name="TestForm" type="com.whatever.form.TestForm" />
    
    form = <bean:write name="testFormA" />##  
    id = <bean:write name="testFormA" property="id" />##  
    
    </html:form>  
    

    My output looks like this:

    form = com.whatever.form.TestForm13a3x4##

    id = ##

    Now I know that the page can see the form correctly due to the first line of the output, but if this is the case then why does the id show that it is empty from this statement:

    id = <bean:write name="testFormA" property="id" />##  
    

    What am I doing wrong to access the id field of my form on this jsp page?

    Many thanks!

  • risingTide
    risingTide over 13 years
    Your answer is clear and I appreciate that. However, I have implemented the code exactly as you have it above and am still receiving this as output: form = com.whatever.form.TestForm13a3x4## id = ## What else could I try or what am I missing?
  • Salandur
    Salandur over 13 years
    is the form correctly linked to the action in the struts-config.xml? it is strange btw that the form output is printet as com.whatever.form.TestForm13a3x5, it should be ...TestForm@13a3x4. if you view the generated page, does it look correct?