package org.onetwo.common.web.view.jsp.form;

import org.onetwo.common.log.MyLoggerFactory;
import org.onetwo.common.spring.SpringUtils;
import org.slf4j.Logger;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyAccessor;

public class SimpleFormDataProvider implements FormDataProvider {

	private static final Logger logger = MyLoggerFactory.getLogger(SimpleFormDataProvider.class);
	
//	private final Object dataObject;
	private PropertyAccessor accessor = null;
	
	public SimpleFormDataProvider(Object dataObject) {
		super();
//		this.dataObject = dataObject;
		if(dataObject!=null){
			BeanWrapper bw = SpringUtils.newBeanWrapper(dataObject);
			this.accessor = bw;
		}
	}

	@Override
	public boolean isFieldShow(String fieldName) {
		return true;
	}

	@Override
	public Object getFieldValue(FormFieldTagBean field) {
		Object val = "";
		if(field.isModelAttribute()){
			if(this.accessor!=null){
				try {
					if(this.accessor.isReadableProperty(field.getValue()))
						val = this.accessor.getPropertyValue(field.getValue());
				} catch (BeansException e) {
					logger.error("getPropertyValue error : " + e.getMessage());
				}
			}
		}
		return val;
	}
	
	

}

@@ -130,16 +130,102 @@
 gUtils;%0A
+import org.onetwo.common.utils.LangUtils;%0Aimport org.onetwo.common.utils.StringUtils;%0A
 import o
@@ -989,16 +989,129 @@
 ield) %7B%0A
+%09%09String fieldValue = field.getValue();%0A%09%09if(StringUtils.isBlank(fieldValue))%0A%09%09%09return LangUtils.EMPTY_STRING;%0A%0A
 %09%09Object
@@ -1237,27 +1237,21 @@
 ty(field
-.get
 Value
-()
 ))%0A%09%09%09%09%09
@@ -1297,20 +1297,48 @@
 ield
-.get
 Value
-())
+);%0A%09%09%09%09%09else%0A%09%09%09%09%09%09val = fieldValue
 ;%0A%09%09
@@ -1444,16 +1444,46 @@
 %09%7D%0A%09%09%09%7D%0A
+%09%09%7Delse%7B%0A%09%09%09val = fieldValue;%0A
 %09%09%7D%0A%09%09re

fix form field tag