Adding new field to RepositoryEditDescriptionController

15 views
Skip to first unread message

Ivano Gnoni

unread,
Jul 29, 2015, 4:04:24 PM7/29/15
to OpenOLAT
Hi, I'm working on a customization on OpenOLAT platform.
My goal is to add a new field in the EditDescription Page managed by controller RepositoryEditDescriptionController.

I added a new html object in the view (private TextBoxListElement tagListElement), I'm able to catch the values of that control in the formOk method and I'm to able to save in DB. 
After the submit OpenOLAT execute the formOk and than reload the page but I loose the content I inserted in the tagListElement. 

I watched the code and I realized that the state of the page is managed by variable RepositoryEntry. So, probably, I must to edit the RepositoryEntry class to manage the field I added on the controller. 

Is there some method to binding (after a submit) by code the html object defined in the controller and their values?

Best Regards, Ivano  

Stéphane Rossé

unread,
Jul 30, 2015, 3:43:28 AM7/30/15
to OpenOLAT, ivano...@gmail.com
Hi

You need:
- Add the field to the database (see the setupDatabase.sql and the different alter scripts in /src/main/resources/database
- Add the field in the hibernate mapping ( the class org.olat.repository.RepositoryEntry )
- Make the changes in RepositoryEditDescriptionController as you wish: validateFormLogic to validate the content of your field, formOK to pass the value to the repository entry and after pass the value to the method setDescriptionAndName of the RepositoryManager ( the construct is a little bit complex because we need pessimistic locking to update the row on the database )
- Than you must show your new field somewhere...

Best regards
Stéphane
---------------------------------------------------------------
professional services for the open source eLearning system OLAT
hosting - operating - support - java development - consulting
---------------------------------------------------------------
http://www.frentix.com | http://www.olat.com | http://openolat.org

frentix  GmbH
Stéphane Rossé
Hardturmstrasse 76
CH-8005 Zürich, Switzerland

tel://+41-43-544-9000
skype://s_rosse
--------------------------------------------------------------- 

Ivano Gnoni

unread,
Jul 30, 2015, 6:18:42 AM7/30/15
to OpenOLAT, ivano...@gmail.com
Hi Stephane, thanks for your answer.

I don't need to save my custom fields in DB. I declared new field in the RepositoryEntry as Transient and all is working fine.
If I use the a TextElement for my custom field in controller and a String field in the RepositoryEntry, after save I can read new values in the reloaded form. My problem persist with object of type TextBoxListElement. If I add a new tag in the TextBoxListElement, then click on button 'Save', the reloaded form haven't the new tag I inserted before click 'Save'

For this object I declare in the RepositoryEntry this attribute:

@Transient
private Map<String, String>  tags;

public Map<String, String> getTags() {
return tags;
}

public void setTags(Map<String, String> tags) {
this.tags = tags;
}

in the init method of controller I put this code:

List<Tag> fetchedTags = taggingManager.loadTagsForResource(repositoryEntry, null, null);
Map<String, String> repositoryEntryTags = new HashMap<String, String>();
if (fetchedTags!=null)  {
for (Tag fetchedTag : fetchedTags) {
repositoryEntryTags.put(fetchedTag.getTag(), fetchedTag.getTag());
}
}

repositoryEntry.setTags(repositoryEntryTags);
tagListElement = uifactory.addTextBoxListElement("artefact.tags", "tag.label", "tag.input.hint", repositoryEntry.getTags(), descCont, getTranslator());
tagListElement.setElementCssClass("o_sel_ep_tagsinput");

Best regards
Ivano

Stéphane Rossé

unread,
Jul 30, 2015, 2:22:00 PM7/30/15
to OpenOLAT, ivano...@gmail.com
Hi

I would not save the tags in the RepositoryEntry but in the RepositoryEntryEditController. The controller is create every time someone need it, it's not a singleton, you can set the map in the init, no problem.

Best regards
Stéphane
Reply all
Reply to author
Forward
0 new messages