Announcement Announcement Module
Collapse
No announcement yet.
CustPropertyEditor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • CustPropertyEditor

    hi guys:

    In my web page, i want to bind the form to the domain object, so i use the CustPropertyEditor. Now the problem is it can bind the form to the object, but not bind the object to the form.

    this is my custPropertyEdit:

    Code:
    public class TypistDailyLogEntryPropertyEditor extends PropertyEditorSupport{
    
    	
    
    	public String getAsText() {
    		// TODO Auto-generated method stub
    		
    		StringBuffer sb = new StringBuffer();
    		
    		TypistDailyLogEntry timesheet=(TypistDailyLogEntry)this.getValue();		
    		
    		System.out.println(".....................zzz"+timesheet);
    		if(timesheet.getRequestId()==null||timesheet.getRequestId().trim().length()==0) return null;
    		
    		
    		return sb.append(timesheet.getRequestId()).toString();
    /*
    		sb.append(timesheet.getAuscriptCode()+",");
    		sb.append(timesheet.getJurisdiction().getId().toString()+",");
    		sb.append(Constants.HHmm.format(timesheet.getStartTime())+",");
    		sb.append(Constants.HHmm.format(timesheet.getEndTime())+",");
    		sb.append(timesheet.getActivity().getId().toString()+",");
    		sb.append(timesheet.getTurnNumber().toString()+",");
    		sb.append(timesheet.getWordCount().toString());
    		return sb.toString();		
    */
    	}
    
    	@Override
    	public void setAsText(String arg0) throws IllegalArgumentException {
    		// TODO do some vaildations in here ............
    		System.out.println("................xxxx"+arg0);
    		String[] formData=arg0.split(",");
    		TypistDailyLogEntry timesheet=new TypistDailyLogEntry();
    
    		try{
    			timesheet.setRequestId(formData[0]);
    			timesheet.setAuscriptCode(formData[1]);
    			timesheet.setJurisdiction(new Jurisdiction(new Integer(formData[2])));
    			timesheet.setStartTime(Constants.HHmm.parse(formData[3]));
    			timesheet.setEndTime(Constants.HHmm.parse(formData[4]));
    			timesheet.setActivity(new Activity(new Integer(formData[5])));
    			timesheet.setTurnNumber(new Integer(formData[6]));
    			timesheet.setWordCount(new Integer(formData[7]));
    		}
    		catch(Exception e){System.out.println(".........................................cann't happen"); }
    		setValue(timesheet);
    	}
    
    	
    	
    }
    by this i mean: the setAsText( ) method is work fine, but the getAsText( ) is not working. When i try to bind the object to the form, in the web page it call the getAsText( ) methods the number of form field times. i don't know why.

    here is my web page:

    Code:
    <tr>					
    					<td>
    						<form:input path="modifytimesheet" size="10"/>
    					</td>					
    					<td>
    						<form:input path="modifytimesheet" size="10"/>
    					</td>

  • #2
    Would it be easier to understand your web page if you bind individual form elements to the individual properties of your timesheet object (timesheet.requestId, timesheet.wordCount, etc.), instead of trying to do the whole thing in one go? Then you might not even need a custom editor.

    If you need more detailed suggestions maybe you should post on the spring web forum.

    Comment


    • #3
      yes, i know the tradition way is to bind the form field to String or Integer.

      but still want to know how to override the getAsText( ) method. and why setAsText( ) method working ?

      In my case, In setAsText(String arg) the arg is a xxxx,xxxx,xxxx,xxxxx,xxxx,xxx
      but when i try to use String getAsText() to return xxxx,xxxx,xxxx,xxxx,xxxx,xxx, it was not working.

      So does any one can help me?

      thanks
      Tony

      Comment

      Working...
      X