Author: jonesde
Date: Mon Feb 18 04:18:38 2008 New Revision: 628699 URL: http://svn.apache.org/viewvc?rev=628699&view=rev Log: A cleanup of the form widget so that ModelForm is initially created without a delegator and dispatcher but only model data, and then thator and dispatcher but only model data and then the del/disp come from the render context Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/FormFactory.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/xml/XmlFormRenderer.java Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java Mon Feb 18 04:18:38 2008 @@ -114,7 +114,7 @@ ModelFormField modelFormField = dropDownField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); String currentValue = modelFormField.getEntry(context); - List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator()); + List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator(context)); // if the current value should go first, display it if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { String explicitDescription = dropDownField.getCurrentDescription(context); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/FormFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/FormFactory.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/FormFactory.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/FormFactory.java Mon Feb 18 04:18:38 2008 @@ -33,6 +33,8 @@ import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.model.ModelReader; +import org.ofbiz.service.DispatchContext; import org.ofbiz.service.LocalDispatcher; import org.w3c.dom.Document; @@ -50,7 +52,7 @@ public static final UtilCache formLocationCache = new UtilCache("widget.form.locationResource", 0, 0, false); public static final UtilCache formWebappCache = new UtilCache("widget.form.webappResource", 0, 0, false); - public static ModelForm getFormFromLocation(String resourceName, String formName, GenericDelegator delegator, LocalDispatcher dispatcher) + public static ModelForm getFormFromLocation(String resourceName, String formName, ModelReader entityModelReader, DispatchContext dispatchContext) throws IOException, SAXException, ParserConfigurationException { Map modelFormMap = (Map) formLocationCache.get(resourceName); if (modelFormMap == null) { @@ -65,7 +67,7 @@ URL formFileUrl = null; formFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader); Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true); - modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher, resourceName); + modelFormMap = readFormDocument(formFileDoc, entityModelReader, dispatchContext, resourceName); formLocationCache.put(resourceName, modelFormMap); } } @@ -95,7 +97,7 @@ URL formFileUrl = servletContext.getResource(resourceName); Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true); - modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher, cacheKey); + modelFormMap = readFormDocument(formFileDoc, delegator.getModelReader(), dispatcher.getDispatchContext(), cacheKey); formWebappCache.put(cacheKey, modelFormMap); } } @@ -108,7 +110,7 @@ return modelForm; } - public static Map readFormDocument(Document formFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String formLocation) { + public static Map readFormDocument(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation) { Map modelFormMap = new HashMap(); if (formFileDoc != null) { // read document and construct ModelForm for each form element @@ -117,7 +119,7 @@ Iterator formElementIter = formElements.iterator(); while (formElementIter.hasNext()) { Element formElement = (Element) formElementIter.next(); - ModelForm modelForm = new ModelForm(formElement, delegator, dispatcher); + ModelForm modelForm = new ModelForm(formElement, entityModelReader, dispatchContext); modelForm.setFormLocation(formLocation); modelFormMap.put(modelForm.getName(), modelForm); } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Mon Feb 18 04:18:38 2008 @@ -50,7 +50,9 @@ import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.model.ModelReader; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelParam; @@ -67,8 +69,8 @@ public static final String module = ModelForm.class.getName(); public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList"; - protected GenericDelegator delegator; - protected LocalDispatcher dispatcher; + protected ModelReader entityModelReader; + protected DispatchContext dispatchContext; protected String formLocation; protected String type; @@ -183,10 +185,10 @@ public ModelForm() {} /** XML Constructor */ - public ModelForm(Element formElement, GenericDelegator delegator, LocalDispatcher dispatcher) { + public ModelForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) { super(formElement); - this.delegator = delegator; - this.dispatcher = dispatcher; + this.entityModelReader = entityModelReader; + this.dispatchContext = dispatchContext; initForm(formElement); } @@ -205,7 +207,7 @@ // check if we have a resource name (part of the string before the ?) if (parentResource.length() > 0) { try { - parent = FormFactory.getFormFromLocation(parentResource, parentForm, delegator, dispatcher); + parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, dispatchContext); } catch (Exception e) { Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource + "'", module); } @@ -219,7 +221,7 @@ while (formElementIter.hasNext()) { Element formElementEntry = (Element) formElementIter.next(); if (formElementEntry.getAttribute("name").equals(parentForm)) { - parent = new ModelForm(formElementEntry, delegator, dispatcher); + parent = new ModelForm(formElementEntry, entityModelReader, dispatchContext); break; } } @@ -439,7 +441,7 @@ while (autoFieldsServiceElementIter.hasNext()) { Element autoFieldsServiceElement = (Element) autoFieldsServiceElementIter.next(); AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement); - this.addAutoFieldsFromService(autoFieldsService, dispatcher); + this.addAutoFieldsFromService(autoFieldsService); } // auto-fields-entity @@ -448,7 +450,7 @@ while (autoFieldsEntityElementIter.hasNext()) { Element autoFieldsEntityElement = (Element) autoFieldsEntityElementIter.next(); AutoFieldsEntity autoFieldsEntity = new AutoFieldsEntity(autoFieldsEntityElement); - this.addAutoFieldsFromEntity(autoFieldsEntity, delegator); + this.addAutoFieldsFromEntity(autoFieldsEntity); } // read in add field defs, add/override one by one using the fieldList and fieldMap @@ -583,13 +585,13 @@ altTargets.add(altTarget); } - public void addAutoFieldsFromService(AutoFieldsService autoFieldsService, LocalDispatcher dispatcher) { + public void addAutoFieldsFromService(AutoFieldsService autoFieldsService) { autoFieldsServices.add(autoFieldsService); // read service def and auto-create fields ModelService modelService = null; try { - modelService = dispatcher.getDispatchContext().getModelService(autoFieldsService.serviceName); + modelService = this.dispatchContext.getModelService(autoFieldsService.serviceName); } catch (GenericServiceException e) { String errmsg = "Error finding Service with name " + autoFieldsService.serviceName + " for auto-fields-service in a form widget"; Debug.logError(e, errmsg, module); @@ -606,20 +608,25 @@ } if (modelParam.formDisplay) { if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { - ModelEntity modelEntity = delegator.getModelEntity(modelParam.entityName); - if (modelEntity != null) { - ModelField modelField = modelEntity.getField(modelParam.fieldName); - if (modelField != null) { - // okay, populate using the entity field info... - ModelFormField modelFormField = this.addFieldFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType, autoFieldsService.defaultPosition); - if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { - modelFormField.setMapName(autoFieldsService.mapName); - } - modelFormField.setRequiredField(!modelParam.optional); - // continue to skip creating based on service param - continue; - } - } + ModelEntity modelEntity; + try { + modelEntity = this.entityModelReader.getModelEntity(modelParam.entityName); + if (modelEntity != null) { + ModelField modelField = modelEntity.getField(modelParam.fieldName); + if (modelField != null) { + // okay, populate using the entity field info... + ModelFormField modelFormField = this.addFieldFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType, autoFieldsService.defaultPosition); + if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { + modelFormField.setMapName(autoFieldsService.mapName); + } + modelFormField.setRequiredField(!modelParam.optional); + // continue to skip creating based on service param + continue; + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } } ModelFormField modelFormField = this.addFieldFromServiceParam(modelService, modelParam, autoFieldsService.defaultFieldType, autoFieldsService.defaultPosition); @@ -643,10 +650,15 @@ return this.addUpdateField(newFormField); } - public void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity, GenericDelegator delegator) { + public void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity) { autoFieldsEntities.add(autoFieldsEntity); // read entity def and auto-create fields - ModelEntity modelEntity = delegator.getModelEntity(autoFieldsEntity.entityName); + ModelEntity modelEntity = null; + try { + modelEntity = this.entityModelReader.getModelEntity(autoFieldsEntity.entityName); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } if (modelEntity == null) { throw new IllegalArgumentException("Error finding Entity with name " + autoFieldsEntity.entityName + " for auto-fields-entity in a form widget"); } @@ -1676,14 +1688,6 @@ } } return fieldListByPosition; - } - - public LocalDispatcher getDispacher() { - return this.dispatcher; - } - - public GenericDelegator getDelegator() { - return this.delegator; } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Mon Feb 18 04:18:38 2008 @@ -54,7 +54,9 @@ import org.ofbiz.entity.finder.EntityFinderUtil; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.model.ModelReader; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelParam; @@ -279,9 +281,9 @@ if (UtilValidate.isEmpty(this.getServiceName()) || UtilValidate.isEmpty(this.getAttributeName())) { return false; } - LocalDispatcher dispatcher = this.getModelForm().getDispacher(); + DispatchContext dispatchContext = this.getModelForm().dispatchContext; try { - ModelService modelService = dispatcher.getDispatchContext().getModelService(this.getServiceName()); + ModelService modelService = dispatchContext.getModelService(this.getServiceName()); if (modelService != null) { ModelParam modelParam = modelService.getParam(this.getAttributeName()); if (modelParam != null) { @@ -372,16 +374,20 @@ if (UtilValidate.isEmpty(this.getEntityName()) || UtilValidate.isEmpty(this.getFieldName())) { return false; } - GenericDelegator delegator = this.getModelForm().getDelegator(); - ModelEntity modelEntity = delegator.getModelEntity(this.getEntityName()); - if (modelEntity != null) { - ModelField modelField = modelEntity.getField(this.getFieldName()); - if (modelField != null) { - // okay, populate using the entity field info... - this.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType); - return true; - } - } + ModelReader entityModelReader = this.getModelForm().entityModelReader; + try { + ModelEntity modelEntity = entityModelReader.getModelEntity(this.getEntityName()); + if (modelEntity != null) { + ModelField modelField = modelEntity.getField(this.getFieldName()); + if (modelField != null) { + // okay, populate using the entity field info... + this.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType); + return true; + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } return false; } @@ -1876,7 +1882,7 @@ if (UtilValidate.isEmpty(fieldKey)) { fieldKey = this.modelFormField.fieldName; } - GenericDelegator delegator = this.modelFormField.modelForm.getDelegator(); + GenericDelegator delegator = this.modelFormField.modelForm.getDelegator(context); String fieldValue = modelFormField.getEntry(context); try { if (this.cache) { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Mon Feb 18 04:18:38 2008 @@ -606,7 +606,7 @@ buffer.append(" size=\"").append(dropDownField.getSize()).append("\">"); String currentValue = modelFormField.getEntry(context); - List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator()); + List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator(context)); // if the current value should go first, stick it in if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { @@ -716,7 +716,7 @@ String currentValue = modelFormField.getEntry(context); Boolean allChecked = checkField.isAllChecked(context); - List allOptionValues = checkField.getAllOptionValues(context, modelForm.getDelegator()); + List allOptionValues = checkField.getAllOptionValues(context, modelForm.getDelegator(context)); String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); @@ -768,7 +768,7 @@ public void renderRadioField(StringBuffer buffer, Map context, RadioField radioField) { ModelFormField modelFormField = radioField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); - List allOptionValues = radioField.getAllOptionValues(context, modelForm.getDelegator()); + List allOptionValues = radioField.getAllOptionValues(context, modelForm.getDelegator(context)); String currentValue = modelFormField.getEntry(context); String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java Mon Feb 18 04:18:38 2008 @@ -66,7 +66,7 @@ try { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - this.modelForm = FormFactory.getFormFromLocation(resourceName, formName, delegator, dispatcher); + this.modelForm = FormFactory.getFormFromLocation(resourceName, formName, delegator.getModelReader(), dispatcher.getDispatchContext()); } catch(IllegalArgumentException iae) { Debug.logWarning("Could not find form with name [" + formName + "] in class resource [" + resourceName + "], will try to load it using relative path syntax.", module); this.modelForm = FormFactory.getFormFromWebappContext(resourceName, formName, request); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Mon Feb 18 04:18:38 2008 @@ -762,7 +762,7 @@ String name = this.getName(context); String location = this.getLocation(context); try { - modelForm = FormFactory.getFormFromLocation(location, name, this.modelScreen.getDelegator(context), this.modelScreen.getDispatcher(context)); + modelForm = FormFactory.getFormFromLocation(location, name, this.modelScreen.getDelegator(context).getModelReader(), this.modelScreen.getDispatcher(context).getDispatchContext()); } catch (Exception e) { String errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextFormRenderer.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextFormRenderer.java Mon Feb 18 04:18:38 2008 @@ -107,7 +107,7 @@ ModelFormField modelFormField = dropDownField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); String currentValue = modelFormField.getEntry(context); - List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator()); + List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator(context)); // if the current value should go first, display it if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { String explicitDescription = dropDownField.getCurrentDescription(context); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/xml/XmlFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/xml/XmlFormRenderer.java?rev=628699&r1=628698&r2=628699&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/xml/XmlFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/xml/XmlFormRenderer.java Mon Feb 18 04:18:38 2008 @@ -112,7 +112,7 @@ ModelFormField modelFormField = dropDownField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); String currentValue = modelFormField.getEntry(context); - List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator()); + List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator(context)); // if the current value should go first, display it if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { String explicitDescription = dropDownField.getCurrentDescription(context); |
Free forum by Nabble | Edit this page |