How to tell the Inline form edit mode to save specific object

Hey guys - I´m working on a workaround regarding the XWIKI-69 issue. I created a script service that does a quite comfortable translation-handling for me using several objects all having a “lang” property where I store the language-key. So for example I have two objects, one with “en” and one with “de”. I select the right one based on the current local and display it´s content (the pages I create like this are based on a template, this as a side-note…)

The problem I face now is the edit-mode. If I click on edit, the inline form edit mode opens and I can edit the object I displayed before (based on current language) - this works so far. If I want to save it, it does not work properly. I saw that it only works for the first object contained in the document´s object-list of the specific class. So it tries to save only the first object - if I try to edit the second one for example, no content changes, no exception is thrown.

Am I able to tell the save-button (or the underlying URL…) somehow that I want to edit and save a specific object and not the first one of its class?

Another possibility would be that I write my own fully-custom edit mode, etc. if that´s possible at all…

Many thanks in advance,
Nils

Hi, I’ve tested this and the following worked fine for me:

  • I created a page and added 2 xobects to it of the class XWiki.Mail. One for language ‘en’ and another for language ‘fr’.
  • I then put the following content in the page:
{{velocity}}
#set ($objects = $doc.getObjects('XWiki.Mail'))
#foreach ($object in $objects)
  #set ($language = $object.getProperty('language').value)
  #if ($language == $request.language)
    $doc.display('subject', $object)
  #end
#end
{{/velocity}}
  • Then viewing this page with ?language=fr in the query returned the correct subject matching the passed language.
  • Editing the page (still with ?language=fr) also worked fine and updated the right xobject.

Hope it helps

Thank you. Sorry for replying late.
I have a quite similar code on my page:

{{velocity}}
#set($class = $doc.getObject('NGPageTemplates.YourTemplateNameClass').xWikiClass)
#set($obj = $doc.getObject('NGPageTemplates.YourTemplateNameClass', 'lang', $xcontext.getLocale()))

#foreach($prop in $class.properties)
  ; $prop.prettyName
  : $doc.display($prop.getName(), $obj)
#end
{{/velocity}}

I have in mind that this already worked fine in the past for me, too - but somehow it doesn´t anymore. I encountered a very strange behavior: If I have two objects, say one with “de” and one with “en”, (whether first object or not, makes no difference), then the edit and save only works for the english object. If I change the property “lang” from “en” to “fr”, none of them is able to be saved anymore. Do I maybe have some strange system settings or something? My standard language is english, supported are german and english. I also changed standard language to german, but same effect.

Ok I know what your problem is: you’re using the wrong API :slight_smile:

You use:

#set($obj = $doc.getObject('NGPageTemplates.YourTemplateNameClass', 'lang', $xcontext.getLocale()))

The javadoc for this API says:

Get the first object of a given classname that has a field name matching the given value When none found this method will return null

You should change that an iterate as I did in my example on all objects to find the matching one that corresponds to your locale.

It seems like this is also not the root-cause… I now created a completely new page, added two XWiki.Mail objects, inserted your code and the problem is the same. :frowning:

My code assumes you pass query parameters! Did you do that?

Yes…

What do you get?

I don’t see any reason why this code wouldn’t work actually so I’m a bit lost :slight_smile:

Me too… :smiley: have a look at how I do this currently, maybe you have an idea…

image
image
image
image
image
image
image

…additional information: If I use english as standard language, this effect occurs. But if I change the settings of the wiki and create a new page whose standard language is german, it works - means, it saves the data. In the english version only the english object can be saved. Even with this “hard-coded” language it does not work on the english page for the german object - this is strange! :confused:

image

image

image

Update: Which object is saveable properly depends on the language of the document the object is attached to and the language I currently use for viewing the content.

Example: I have a page (regardless if template sheet or not) and it´s standard language is english. If I use the code you see below to display a specific object (regardless which one, all objects selected by ‘de’, ‘en’, etc. will work), the object can be edited and saved without problems in inline form mode if I display the page in english, too.

[[DE>>||queryString='language=de']] [[EN>>||queryString='language=en']]

{{velocity}}
#set($class = $doc.getObject('XWiki.Mail').xWikiClass)
#set($obj = $doc.getObject('XWiki.Mail', 'language', 'de'))

#foreach($prop in $class.properties)
  ; $prop.prettyName
  : $doc.display($prop.getName(), $obj)
#end
{{/velocity}}

If I now switch to german (means I display xwiki in german, using ?language=de), the object is displayed, too, because the selection $doc.getObject('XWiki.Mail', 'language', 'de') is static. But the funny thing now is that i´m not able to save it anymore! Saving of edited stuff is only possible if displaying in english.

I tested the opposite case using a document created in german with the same code (also tried ‘de’ and ‘en’ selection, but both act same) - and the result is equal. This means in this case I´m only able to save the object´s new contents after editing if I display the document in german. English brings the same effect as before using German.

So it seems like I´m only allowed to edit objects if I´m on the original page and translations cause problems.

Has anyone a rough idea maybe? I´m kind of at the end already…

Many thanks in advance, guys. Have a nice weekend so far! :wink:

I created a fully new class and template and now it works for this. Means my problem is solved temporaily so far… thanks anyway guys :slight_smile:

Just adding a note about the fact that this unexpected behaviour is due to XWIKI-9617.