File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes HTML form to form bean mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "HTML form to form bean mapping" Watch "HTML form to form bean mapping" New topic
Author

HTML form to form bean mapping

Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Hello,

I am trying to overcome a funny situation.

I have an ActionForm bean where there is a field:


In the HTML form I correspondingly have a textbox:

Upon submitting the form, I get a null value in the bean's field.

However, (this however is really very important) when I name the field in the bean as : "firstName" and correspondingly change in the HTML form to "firstName", all works like a charm.

Please help me understand what's happening.

Regards


Experience and talent are independent of age
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What do your getters/setters for the two names look like?
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
I had changed the getters and setters accordingly while changing names.

When it was "sUserFirstName" the methods were:


Now it is "firstName" and the methods are:


I dont know if I should laugh at this problem or cry!

Regards
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Himanshu Kansal wrote:I dont know if I should laugh at this problem or cry!

You should "investigate",
Here are the steps I would followed If I came across the similar situation

  • Check if the HTML is valid, close all the tags, properly, especailly see if there is problem for "sUserFirstName" html tag
  • I would used html:text tag, instead of plain input type="text"
  • Look if you are validating "sUserFirstName" field, which consequently set the "sUserFirstName" to null
  • Finally, any exception/error in log file


  • And the best one is to go with "firstName" instead of "sUserFirstName"


  • [LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
    Himanshu Kansal
    Ranch Hand

    Joined: Jul 05, 2009
    Posts: 257
    Check if the HTML is valid, close all the tags, properly, especailly see if there is problem for "sUserFirstName" html tag

    would not make a difference in changing names.

    I would used html:text tag, instead of plain input type="text"

    I prefer going with the original. No good reason to replace the standard just because an alternative is available.

    Look if you are validating "sUserFirstName" field, which consequently set the "sUserFirstName" to null

    Not as yet. Will move to validating, that to client side, only after I get over with this.

    Finally, any exception/error in log file

    Nah, none.

    These steps are just intuitive basics and everyone does them. I am making some beautiful mistake which would make me look stupid later.

    And the best one is to go with "firstName" instead of "sUserFirstName"

    I fear that

    Can't figure out the difference in "sUserFirstName" and "firstName".

    Regards
    Sagar Rohankar
    Ranch Hand

    Joined: Feb 19, 2008
    Posts: 2902
        
        1

    Himanshu Kansal wrote:
    And the best one is to go with "firstName" instead of "sUserFirstName"

    I fear that

    Why

    Then, I would use this hack, if that's OK to you ?


    Himanshu Kansal
    Ranch Hand

    Joined: Jul 05, 2009
    Posts: 257
    Just giving a reason because you asked for it. I have no justifications:

    "My employer wants variable names to present like that(MS notation). Any variable, anywhere"

    Anyways, I am quitting next month. :p

    Regards
    Sagar Rohankar
    Ranch Hand

    Joined: Feb 19, 2008
    Posts: 2902
        
        1

    Himanshu Kansal wrote:"My employer wants variable names to present like that(MS notation). Any variable, anywhere"

    That's ridicules , man !! Don't they know there is something called as "Java Coding Standards"

    Himanshu Kansal wrote:Anyways, I am quitting next month. :p

    Good Luck for future

    And as per the problem, try using different name like "sFirstName" or something like that. HTH
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: HTML form to form bean mapping