Starting to learn ofbiz, I am following the tutorial here:
https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guide#OFBizTutorial-ABeginnersDevelopmentGuide-SecureYourApplicationbyAuthentication
Now I am in the step to make the list form of persons editable. In this step I need to create a service which will be used for auto-fields-service. Below I give the code which I have done.
In the controller.xml of my componenent I have created a requestMaps as follows:
<request-map uri="updatePracticePerson">
<security https="true" auth="true"/>
<event type="service" invoke="updatePracticePerson"/>
<response name="success" type="view" value="personForm"/>
<response name="error" type="view" value="personForm"/>
</request-map>
Moving now to the PracticeScreens.xml i have the following for personForm:
<screen name="personForm">
<section>
<actions>
<set field="headerItem" value="personForm"/>
<set field="titleProperty" value="PageTitlePracticePersonForm"/>
<entity-condition entity-name="Person" list="persons"/>
</actions>
<widgets>
<decorator-screen name="CommonPracticeDecorator" location="${parameters.mainDecoratorLocation}">
<decorator-section name="body">
<label text="Person List" style="h2"/>
<include-form name="ListPersons" location="component://practice/widget/PracticeForms.xml"></include-form>
</decorator-section>
</decorator-screen>
</widgets>
</section>
The above includes the ListPersons from PracticeForms.xml, which I have as :
<form name="ListPersons" type="list" list-name="persons" list-entry-name="person" target="updatePracticePerson" paginate-target="personForm">
<auto-fields-service service-name="updatePracticePerson" default-field-type="edit" map-name="person"/>
<field name="partyId"><hidden/></field>
<field name="submitButton" title="Update" widget-style="smallSubmit"><submit button-type="button"/></field>
<field name="deletePracticePerson" title="Delete Person" widget-style="buttontext">
<hyperlink target="deletePracticePerson?partyId=${person.partyId}" description="${uiLabelMap.CommonDelete}" also-hidden="false"/>
</field>
<field name="submitButton" title="${uiLabelMap.CommonUpdate}"><submit button-type="button"/></field>
</form>
If you see above the ListPersons calls the service updatePracticePerson.
inside servicedef/services.xml i have the following:
<service name="updatePracticePerson" default-entity-name="Person" engine="simple"
location="component://practice/script/org/hotwax/practice/PracticeServices.xml" invoke="updatePracticePerson" auth="true">
<description>Create a Person</description>
<auto-attributes include="pk" mode="IN" optional="false"/>
<attribute name="salutation" mode="IN" type="String" optional="true"/>
<attribute name="firstName" mode="IN" type="String" optional="false"/>
<attribute name="middleName" mode="IN" type="String" optional="true"/>
<attribute name="lastName" mode="IN" type="String" optional="false"/>
<attribute name="suffix" mode="IN" type="String" optional="true"/>
</service>
In the root of my project in the file ofbiz-component.xml i have :
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
this to make sure that my service is loaded.
Although all of the above seem correct to me I get the following error :
org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen [component://common/widget/CommonScreens.xml#GlobalDecorator]: java.lang.RuntimeException: Error rendering included form named [ListPersons] at location [component://practice/widget/PracticeForms.xml]: java.lang.IllegalArgumentException: Error finding Service with name updatePracticePerson for auto-fields-service in a form widget (Error rendering included form named [ListPersons] at location [component://practice/widget/PracticeForms.xml]: java.lang.IllegalArgumentException: Error finding Service with name updatePracticePerson for auto-fields-service in a form widget)
Which obviously implies that everything is not ok and there is something wrong with my service. Could you please assist on this?
Thanks in advance,
gianis
Restart OFBiz and check the logs. During startup it will show you loading your component and then the services defined in your component. You should be able to see the problem in the logs
at the end i found the answer myself.
in the file on the root of my component ofbiz-component.xml i had:
<resource-loader name="personForm" type="component"/>
when I should have:
<resource-loader name="main" type="component"/>
Related
I have developed Odata service for a system entity which generates a metadata but however I cant figure out how to add Annotations element to it. Sample Metadata generated is as follows :-
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
m:DataServiceVersion="1.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="myNamespace" sap:schema-version="1">
<EntityType Name="System">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="name" Type="Edm.String" sap:label="System Name" sap:creatable="false"
sap:updatable="false" sap:sortable="false" sap:required-in-filter="true"/>
<Property Name="description" Type="Edm.String" />
<Property Name="status" Type="Edm.String" />
<Property Name="type" Type="Edm.String" />
</EntityType>
<EntityContainer Name="ODataEntityContainer" m:IsDefaultEntityContainer="true">
<EntitySet Name="Systems" EntityType="myNamespace.System" />
<FunctionImport Name="NumberOfSystems" ReturnType="Collection(myNamespace.System)"
m:HttpMethod="GET" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
I need to add following elements to above metatada
<Annotations Target="myNamespace.System"
xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotation Term="com.sap.vocabularies.UI.v1.LineItem">
<Collection>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="name" />
</Record>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="description"/>
</Record>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="status" />
</Record>
</Collection>
</Annotation>
</Annotations>
I came across the org.apache.olingo.commons.api.edm.provider.annotation package but cant find any suitable API. Please let me know how should I proceed.
Thanks in advance.
The annotations you would like to use have been introduced with OData V3 which is why they are not directly supported with the Olingo V2 library.
You can use the EdmProvider AnnotationElement and AnnotationAttribute classes to mimic this behaviour though. For example You can create a AnnotationElement with the name "Annotations" this element will then have the "AnnotationAttribute" Target=SomeString. Since an "AnnotationElement" can have child elements you can put your Collection element there. Namespaces are also handled with "AnnotationAttributes".
You can only attach the annotation to Edm elements which are derived from the EdmAnnotatable interface. So this is a difference to V3.
This is currently the only way to get this behaviour with Olingo V2.
I have a request-map in controller as follows:
<request-map uri="processFirstForm">
<event type="java" path="org.ofbiz.learning.learning.LearningEvents"
invoke="processFirstForm" />
<response name="success" type="view" value="OneFormScreen" />
</request-map>
In controller, I defined a handler for java event as follows:
<handler name="java" type="request" class="org.ofbiz.webapp.event.JavaEventHandler"/>
I have a screen form as follows:
<form name="FirstForm" type="single" target="processFirstForm">
<field name="firstName">
<text />
</field>
<field name="lastName">
<text />
</field>
<field name="submit">
<submit />
</field>
</form>
I also have file LearningEvents.class in folder /bin/org/ofbiz/learning/learning
But i still receive a exception when i submit FirstForm form as follows:
ERROR rendering error page [/error/error.jsp], but here is the error
text: org.ofbiz.webapp.event.EventHandlerException: Error invoking
event, the class org.ofbiz.learning.learning.LearningEvents was not
found
Can anyone help me? thank a lot!
Do you have other java services or events in this component that are working fine? I trying to understand whether the problem is in this event or the whole component setup is not complete. Start from comparing your build.xml and ofbiz-component.xml with an existing one.
I am working with liferay and want to store images in my MySQL database.
My service.xml goes like this:
<entity name="DLApp" local-service="true" remote-service="true">
<column name="blobId" type="long" primary="true" />
<column name="desc" type="String" />
<column name="image" type="Blob" />
</entity>
When i build services I get BUILD SUCCESSFUL message but an error in package com.test.blob.upload in the blobuploadModelImpl class.
How should I write function to store image in database and retrieve it?
I had same issue with Blob, so I changed it to String type, it was enought to store images up to 10 MB as string, I have used MySql as database and those column was mapped as LONGTEXT.
Also field should be 'hinted' in model hints as CLOB, See example below.
<entity name="UserExt" local-service="true" remote-service="true">
<column name="photo" type="String" />
</entity>
<model-hints>
<model name="com.project.model.UserExt">
<field name="photo" type="String">
<hint-collection name="CLOB" />
</field>
</model>
</model-hints>
Alternativelly you can store your images to Liferay's image gallery.
Suppose my entity name is SB_Claims so I generally get an error in SB_ClaimsModelImpl.java class
sb_ClaimsModelImpl._ContentBlobModel = null;
sb_ClaimsModelImpl variable is not declared or defined. We just declared this variable after sevice build operation. If you build service again then this code will remove by service builder. Always this code after service build and then do not build the service just deploy your portlet.
This will resolve the issue. In below I just modify that class.
#Override
public void resetOriginalValues()
{
SB_ClaimsModelImpl sb_ClaimsModelImpl=this;
sb_ClaimsModelImpl._ContentBlobModel = null;
}
Hope this will helpful for someone.
In SmartGwtEE project I have hierarchy of DataSources described in .ds.xml files, here is some of them:
BaseElement_DS.ds.xml
<DataSource ID="BaseElement_DS" serverConstructor="com.isomorphic.jpa.JPADataSource"
beanClassName="lnudb.server.model.BaseElement">
<fields>
<field name="id" type="sequence" hidden="true" primaryKey="true" />
<field name="name" type="text" title="Name" required="true" />
<field name="dsId" type="text" title="Datasource" hidden="true"/>
</fields>
</DataSource>
Human_DS.ds.xml
<DataSource ID="Human_DS" serverConstructor="com.isomorphic.jpa.JPADataSource"
beanClassName="org.zasadnyy.lnudb.server.model.Human" inheritsFrom="BaseElement_DS"
useParentFieldOrder="true">
<fields>
<field name="surname" type="text" />
<field name="birthday" type="date" title="Birthday" required="false" />
</fields>
</DataSource>
Problem: when I try to get parent datasource id in code
String parentDsId = DataSource.get("Human_DS").getInheritsFrom();
ClassCastExeption is raised from inside of getInheritsFrom() method:
java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$ cannot be cast to java.lang.String
I will be grateful for any help.
This way you won't get the exception any longer:
String parentDsId = DataSource.get("Human_DS").getInheritsFrom() + "";
However, I'm not sure whether this is "ok" for your purposes. If this is not good for you, try to create a Javascript object and assign the before mentioned value to it. I hope this helps.
I don't manage to persist a many-to-many link with DataNucleus using JDO. I have two classes Book and Shop. This is the orm mapping file:
<?xml version="1.0"?>
<!DOCTYPE orm PUBLIC
"-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN"
"http://java.sun.com/dtd/orm_2_0.dtd">
<orm>
<package name="com.mypackage.pojo">
<class name="Book" identity-type="datastore">
<datastore-identity>
<column name="BOOK_ID" />
</datastore-identity>
<field name="name">
<column length="100" jdbc-type="VARCHAR" />
</field>
<field name="shops" persistence-modifier="persistent"
table="BOOKS_SHOPS">
<collection element-type="com.mypackage.pojo.Shop" />
<join>
<column name="BOOK_ID" />
</join>
<element>
<column name="SHOP_ID" />
</element>
</field>
</class>
<class name="Shop" identity-type="datastore">
<datastore-identity>
<column name="SHOP_ID" />
</datastore-identity>
<field name="name">
<column length="50" jdbc-type="VARCHAR" />
</field>
<field name="books" persistence-modifier="persistent"
table="BOOKS_SHOPS">
<collection element-type="com.mypackage.pojo.Book" />
<join>
<column name="SHOP_ID" />
</join>
<element>
<column name="BOOK_ID" />
</element>
</field>
</class>
</package>
</orm>
I try to link a book to a shop and the other way around, like this:
shop.addBook(book);
book.addShop(shop);
Making these two objects persistent again doesn't do anything. Both before and after the little code snippet above, their ObjectState is detached-clean.
What could I be doing wrong?
I have a working solution, but have to admit I do not fully understand everything. Things work when the last field element is not defined as
<field name="books" persistence-modifier="persistent" table="BOOKS_SHOPS">
but as
<field name="books" persistence-modifier="persistent" mapped-by="shops">
This solved my problem.
See also the DataNucleus manual on JDO M-N Relationships. However, leaving the join and the element elements out, as is done in this example, didn't work for me. Another relevant link on the DataNucleus site is JDO Guides : M-N Relation. The code for this last example can be found on SourceForge. Unfortunately, this example also didn't work for me.
This is not really a good answer, but all that I have to offer for now...