Message Boards

« Back to 2.- Usage ( From Xml file to CRUD Portlet)

Losing field settings in portlet-model-hints

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Hello,

I was finding that the values I entered for field length were not being honored when the tables were created. For example, if I had

 1                    <field>
 2                        <name>courseName</name>
 3                        <title>Course Name</title>
 4                        <type>
 5                            <varchar>
 6                                <length>30</length>   
 7                                <filter>true</filter>
 8                                <order>true</order>
 9                            </varchar>
10                        </type>
11                        <showFieldInView>true</showFieldInView>
12                        <required>true</required>
13                    </field>


The database column courseName was created with the Liferay default varchar(75) length, not varchar(30).

Debugging I found that portlet-model-hints.xml was created with the correct max-length when XMLPortletFactory ran, but gets overwritten and all hints lost when 'ant build-service' runs.

With further debugging I discovered this only happens when the Application classDef name doesn't match the fileDef name. Unless I misunderstand, it seems that having fileDef and classDef names that don't match (different case, for example) should be legal.

I believe there is a bug in Portlet_portlet-model-hints_xml.vm. The model name in portlet-model-hints should be the classname, so I think
1<model name="${packageBase}.${commonData.getClient().toLowerCase()}.${commonData.getProjectName().toLowerCase()}.model.${table.getFileDef().getName()}">

should be
1<model name="${packageBase}.${commonData.getClient().toLowerCase()}.${commonData.getProjectName().toLowerCase()}.model.${table.getClassDef().getName()}">


That is, change ${table.getFileDef().getName()} to ${table.getClassDef().getName()}
When I made this change to the velocity template it seemed to fix the problem. The hints were retained and the tables had the field lengths I expected.

RE: Losing field settings in portlet-model-hints
Answer
8/15/12 4:19 PM as a reply to Deb Troxel.
Hola Deb,

You are correct, changing fileDef to classDef will do the job. BuildService didnt found the model name it was looking for, so he created its own from service.xml and erased the ones generated by XMLPF.

I already changed it in SVN and will be in next version. While changing it I also found that fields (createDate and modifiedDate) were not being created on 6.1.x generations, so I also corrected this.

So if you are using XMLPF for 6.1.x add also this two lines just after <column name="userId" type="long" />

1        <column name="createDate" type="Date" />
2        <column name="modifiedDate" type="Date" />


Thank you very much Deb,

RE: Losing field settings in portlet-model-hints
Answer
8/16/12 8:48 PM as a reply to Jack A. Rider.
Jack A. Rider:

So if you are using XMLPF for 6.1.x add also this two lines just after <column name="userId" type="long" /> ...

Hi Jack,

Done; but I just want to point out that neither the 2.1 or svn versions include "userId" (referenced above). I just mention that in case you wanted to add that to the check in too.

Best regards,
Deb