Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    CanvasItem and ValuesManager

    Is there an issue with CanvasItem and ValuesManager? It doesn't seem to be saving the value in values manager for my custom canvas item. It gets to the validator code fine but never gets to the getValue(), setValue() methods. Reading elsewhere in the forum, I added setShouldSaveValue(true), etc. what else am I missing.

    Also added there seems to be an issue with the tab order with the outer form, this canvasitem is part of an outer form with other fields, but the tab order is always first for this canvasitem even if I set the tab order on the outer form fields. I also added this.setCanFocus(true) as per recommendations in other forum posts.

    Here is the snippet of code for CanvasItem
    Code:
    public class SplitPhoneItem extends CanvasItem {
    	private DynamicForm phoneForm;
    	boolean required;
    	private TextItem phoneField1;
    	private TextItem phoneField2;
    	private TextItem phoneField3;
    
    	public SplitPhoneItem(final String name, final String title) {
    		this(name);
    		super.setTitle(title);
    	}
    
    	public SplitPhoneItem(final String name) {
    		super.setRequired(false);
    		super.setShowErrorIcon(true);
    		super.setName(name);
    		setShouldSaveValue(true);
    
    		this.setCanvas(asWidget());
    		this.setCanFocus(true);
    
    		final Validator validator = new CustomValidator() {
    			@Override
    			protected boolean condition(final Object value) {
    				phoneForm.clearErrors(true);
    				final boolean validate = phoneForm.validate();
    				if (validate == false) {
    					final Map errors = phoneForm.getErrors();
    					if (Utility.isNotNull(errors) && (errors.isEmpty() == false)) {
    						// TODO: error message handling
    					}
    				} else {
    					storeValue(value);
    				}
    				return validate;
    			}
    		};
    		validator.setErrorMessage("Invalid phone");
    		this.setValidators(validator);
    	}
    
    	private Canvas asWidget() {
    		final HLayout layout = new HLayout();
    		layout.setHeight(20);
    
    		phoneForm = new DynamicForm();
    		phoneForm.setNumCols(6);
    		phoneForm.setShowErrorIcons(true);
    		phoneForm.setHiliteRequiredFields(false);
    
    		phoneField1 = new TextItem();
    		phoneField1.setValidators(customLengthValidator(3));
    		phoneField1.setWidth(60);
    		phoneField1.setShowTitle(false);
    		phoneField1.setRequired(this.required);
    		phoneField1.setShowErrorIcon(false);
    		phoneField1.setMask("###");
    
    		phoneField2 = new TextItem();
    		phoneField1.setValidators(customLengthValidator(3));
    		phoneField2.setWidth(60);
    		phoneField2.setShowTitle(false);
    		phoneField2.setRequired(this.required);
    		phoneField2.setShowErrorIcon(false);
    		phoneField2.setMask("###");
    
    		phoneField3 = new TextItem();
    		phoneField1.setValidators(customLengthValidator(4));
    		phoneField3.setWidth(80);
    		phoneField3.setShowTitle(false);
    		phoneField3.setRequired(this.required);
    		phoneField3.setShowErrorIcon(false);
    		phoneField3.setMask("####");
    
    		phoneForm.setFields(phoneField1, phoneField2, phoneField3);
    
    		layout.addChild(phoneForm);
    		return layout;
    	}
    
    	@Override
    	public String getValue() {
    		//		return phoneForm.getValueAsString(getPhoneItemName(1)) + phoneForm.getValue(getPhoneItemName(2)) + phoneForm.getValue(getPhoneItemName(3));
    		return (String) super.getValue();
    	}
    
    	public void showValue() {
    		//todo ?
    	}
    
    	@Override
    	public void setValue(final String value) {
    		phoneForm.getField(getPhoneItemName(1)).setValue(value.substring(0, 2));
    		phoneForm.getField(getPhoneItemName(2)).setValue(value.substring(3, 5));
    		phoneForm.getField(getPhoneItemName(3)).setValue(value.substring(6, 9));
    		super.setValue(value);
    	}
    
    	@Override
    	public void setTitle(final String title) {
    		super.setTitle(title);
    	}
    
    	@Override
    	public void setRequired(final Boolean required) {
    		this.required = required;
    		phoneField1.setRequired(required);
    		phoneField2.setRequired(required);
    		phoneField3.setRequired(required);
    	}
    
    	@Override
    	public Boolean validate() {
    		return phoneForm.validate(true);
    	}
    
    	@Override
    	public void clearValue() {
    		phoneForm.clearErrors(true);
    		phoneForm.clearValues();
    	}
    }
    I am using GWT 2.4 and one of the recent 3.0 LGPL nighly .
    Last edited by sujaydutta; 30 May 2012, 05:29.

    #2
    bumping this up....

    Comment


      #3
      Sorry for the delay responding to this
      From the description these issues sound like things that have already been addressed in the 3.1d branch.

      This is extremely close to a final release - we're up to "Release Candidate" builds at this point.
      Could you please try the latest nightly build from that branch and let us know if these issues are still occurring for you.

      If so, in addition to the actual CanvasItem class code, we'd like to see code that actually generates the problem. It'd be ideal if you could put together a simple EntryPoint which makes use of your custom item and which demonstrates the problems you're seeing, with clear steps to reproduce so we can run and reproduce it on our end (and eliminate any possible oddities elsewhere in your application which may be impacting behavior)

      Thanks
      Isomorphic Software

      Comment

      Working...
      X