Announcement Announcement Module
Collapse
No announcement yet.
Bind, PropertyEditor and Map Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bind, PropertyEditor and Map

    After too many days sitting and trying in vain I'm now turning to the 'Wizards of Spring' with a hopeful mind.....

    This is the situation:
    I want to bind a DB-relation object in a form. Designed JavaBean style, nothing unusual.

    Code:
    public class Delegation implements Serializable, TernaryAssociation {
    
        private Event 				event;
        private Function			delegate;
        private Date 				until;
        private DelegationLevel		level;
    
    
    	public Delegation(Event event, Function delegate, Date until, 
    				DelegationLevel level) {
    		this.event = event;
    		this.delegate = delegate;
    		this.until = until;
    		this.level = level;
    	}
    	
                    [standard setters/getter]
    }
    A couple of these are bound to form object

    Code:
    public class DelegationForm {
    
    	private Function function; //The function of the current user
    	private Map delegations; //All the delegation node objects per function in the system
    	
    	public DelegationForm(Function function){
    		this.function = function;
    	}
    	
    	public DelegationForm(){}
    	
    	public Function getFunction() { return (this.function); }
    	public void setFunction(Function function) { this.function = function; }
    	
    	public Map getDelegations() { return (this.delegations); }
    	public void setDelegations(Map delegations) { this.delegations = delegations; }			
    }
    Relevant JSP-code:

    Code:
    <c&#58;forEach var="functionnaire" items="$&#123;functionnaires&#125;">
    <c&#58;set var="fid" value="$&#123;functionnaire.function.id&#125;"/>
    <TR>
    	<spring&#58;bind path="command.delegations&#91;$&#123;fid&#125;&#93;">
    		<TD<b><c&#58;out value="$&#123;functionnaire.function.description&#125; $&#123;functionnaire.user.fname&#125; $&#123;functionnaire.user.lname&#125; "/></b></TD>
    		<c&#58;forEach var="level" items="$&#123;levellist&#125;">	
    			<TD><input  type="radio" name="<c&#58;out value="$&#123;status.expression&#125;"/>" 
    						value="<c&#58;out value="$&#123;status.value&#125;"/>" 							
    			></TD>
    		</c&#58;forEach>
    	</spring&#58;bind>
    </TR>
    </c&#58;forEach>
    where 'functionnaires' is a list of objects containing a User and a Function, provided by controller function referenceData. 'command.delegations' is the form objects Map, which is preloaded with existing data from database.

    What I cannot seem to accomplish is to get PropertyEditor

    Code:
    public class DelegationEditor extends PropertyEditorSupport &#123;
    	
    	private LogicFacade logic;
    	
    	public static Category log = Category.getInstance&#40;DelegationEditor.class.getName&#40;&#41;&#41;;
    	
    	public LogicFacade getLogic&#40;&#41; &#123; return &#40;this.logic&#41;; &#125;
    	public void setLogic&#40;LogicFacade logic&#41; &#123; this.logic = logic; &#125;
      
    	public void setAsText&#40;String text&#41; &#123;
    		log.debug&#40;"setAsText got&#58; " +  text&#41;;
    		Delegation status = null;
    		if&#40;text.trim&#40;&#41;.equals&#40;""&#41; || text == null&#41;&#123;
    			this.setValue&#40;null&#41;;
    		&#125;
    		else&#123;
    			try&#123;
    				this.setValue&#40;new Delegation&#40;null, null, null, null&#41;&#41;;
    			&#125;catch&#40;Exception e&#41;&#123;
    				
    			&#125;
    		&#125;
    	&#125;
    	
    	public String getAsText&#40;Delegation status&#41; throws Exception &#123;
    
    		log.debug&#40;"getAsText got&#58; " +  status&#41;;
    		if&#40;status == null&#41;&#123;
    			return "Hejsan";
    		&#125;//if
    		else&#123;
    			return status.getEvent&#40;&#41;.getId&#40;&#41; + "@" + status.getDelegate&#40;&#41;.getId&#40;&#41;;
    		&#125;//else		
    	&#125;
    &#125;
    to print out 'Hejsan' or the wanted string 'xxx@xxx'. Instead it somehow uses Delegation's internal toString()-function, resulting in

    Code:
    <TD><input  type="radio" name="delegations&#91;5&#93;" 						value="ks.rah.avik2.domain.Delegation@1644c9&#91;event&#58; =1,delegate&#58; =5,level&#58; =Inga rättigheter&#93;" ></TD>
    despite the fact that

    Code:
    protected void initBinder&#40;HttpServletRequest request, ServletRequestDataBinder binder&#41; &#123;
    		super.initBinder&#40;request,binder&#41;;
    		binder.registerCustomEditor&#40;Delegation.class, "delegations.*", delegEditor&#41;;
    	&#125;
    is invoked in the DelegationFormController class.

    In short: I don't see any PropertyEditor impact on my presented HTML-page.

    What am I doing wrong in binding here? Is invoking the contents of a Map in a Command object with 'mapname[keystring]' not doable? Any tips and tricks?

    Thanks in advance,
Working...
X