Announcement Announcement Module
Collapse
No announcement yet.
Inserting value from select form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inserting value from select form

    How do I insert a value from select form that also fetches data from DB?

    Code:
    				<spring&#58;bind path="perumahan.rt">
    				<select name="rt">
    					<c&#58;forEach var="rt" items="$&#123;rtList&#125;">
    					<option value="<c&#58;out value="$&#123;rt.id&#125;"/>"><c&#58;out value="$&#123;rt.id&#125;"/></option>
    					</c&#58;forEach> 
    				</select> 
    				<c&#58;out value="$&#123;status.errorMessage&#125;"/>
    				</spring&#58;bind>
    This is my mapping:
    Code:
        <class name="net.streambuffer.kelurahan.model.Perumahan" table="perumahan">
        	<id name="id" column="id">
        		<generator class="native" />
        	</id> 
        	<many-to-one name="rt" column="id_rt" class="net.streambuffer.kelurahan.model.Rt"/>
        </class>
    
    	<class name="net.streambuffer.kelurahan.model.Rt" table="rt">
    		<id name="id" column="id">
    			<generator class="native" />
    		</id>
    	</class>
    And my bean:
    Code:
    public class Perumahan extends Entity&#123;
        private Rt rt;
    
        public Rt getRt&#40;&#41;&#123;
            return this.rt;
        &#125;
        
        public void setRt&#40;Rt rt&#41;&#123;
            this.rt=rt;
        &#125;
    &#125;
    What else do I need to check?

    Thanks in advance.

  • #2
    Re: Inserting value from select form

    Hi,

    I'm having the same problem. See http://forum.springframework.org/showthread.php?t=17384. If you're binding to the many-to-one object, you will need to tell spring how to translate the String that the <SELECT> tag will return to the controller to an object of type Rt.
    I'm trying to determine what the best practice is for doing this. From what I understand, you can create a custom PropertyEditor and register it in an overridden initBinder() method, or you can override onBind() and handle it there. Unfortunately, I'm not certain how to do either, or which is the preferred way.

    Graham.
    Last edited by robyn; May 14th, 2006, 09:05 PM.

    Comment


    • #3
      What do I write on onBind()? Since the I get a null value when submitting the form.

      Comment

      Working...
      X