Results 1 to 4 of 4

Thread: Can we do this?

  1. #1

    Default Can we do this?

    Hi,

    I have a bean "Student" which contains a getter method getClass() which returns an instance of a "Class". In the JSP i need to bind the attributes in returned Class to HTML text fields... How can I do a <spring:bind> to the Class instance returned by getClass() method in JSP.

    let's say the text field is:

    <input type="text" name="classType">

    I need to bind the above field with the returned "Class" instance

    <spring:bind path="student.getClass().classType"> ???
    <input type="text" name="classType">
    </spring:bind>

    The above does not works...what is the right syntax?

    An example will be appreciated.

    Thx!
    A

  2. #2
    Join Date
    Jul 2005
    Posts
    246

    Default

    I'm surprised that even compiles. getClass() is defined in java.lang.Object as final:-

    Code:
    public final native Class getClass();
    And there is no such thing as a classType in the java.lang.Class object.

    Rule number one, do not name your classes with the same name as anything in java.lang, and if possible do not name them the same as anything in the Java API.

    So, say that you've changed your class to be StudentClass and the getter method in Student is getStudentClass(), your bind code would be:-

    Code:
    <spring:bind path="student.studentClass.classType">
        <input type="text" name="classType">
    </spring:bind>
    Bob

  3. #3

    Default

    Thanks man.... that was an example which I composed as my scenario would require a more complex description.. thx for poiting out the mistake ;-)

    will check out the same..

    A

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Why are you binding on the class?

    Anyways, should you still decide you need to do this you would want:

    Code:
    <spring:bind path="student.class.classType"> ???
      <input type="text" name="classType">
    </spring:bind>
    And you will need to register a property editor for ClassType.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •