Class AiChatLoader

java.lang.Object
io.jmix.flowui.xml.layout.loader.AbstractComponentLoader<AiChat<?>>
io.jmix.aichat.xml.layout.loader.AiChatLoader
All Implemented Interfaces:
ComponentLoader<AiChat<?>>

public class AiChatLoader extends AbstractComponentLoader<AiChat<?>>
Loads AiChat from a view descriptor.
  • Field Details

  • Constructor Details

    • AiChatLoader

      public AiChatLoader()
  • Method Details

    • createComponent

      protected AiChat<?> createComponent()
      Specified by:
      createComponent in class AbstractComponentLoader<AiChat<?>>
    • initComponent

      public void initComponent()
      Description copied from interface: ComponentLoader
      Creates result component by XML-element
      Specified by:
      initComponent in interface ComponentLoader<AiChat<?>>
      Overrides:
      initComponent in class AbstractComponentLoader<AiChat<?>>
    • loadComponent

      public void loadComponent()
      Description copied from interface: ComponentLoader
      Loads component properties by XML definition.
    • loadSystemPrompt

      protected void loadSystemPrompt()
      Loads the system prompt from the nested systemPrompt element, or, when it is absent, from the systemPrompt attribute — the same pair aiCodeBlock offers for its code, and for the same reason: a prompt is routinely multi-line. Absent from both is not an error; the provider's own default then applies. A present but blank element is an error: loading it as "" would silently shadow the attribute.
    • loadI18n

      protected void loadI18n()
      Applies the labels declared in the nested i18n element on top of the localization the component resolved from the message bundle when it was created — the chat's own announcements, and, from the nested messageInput and messageList elements, the labels of the two components it composes.

      The element edits the tree the chat already carries rather than building a fresh one, so a label it does not declare keeps its bundle value instead of falling back to the client's hardcoded English.

    • loadDataContainer

      protected void loadDataContainer()
      Binds the declared collection container as the chat's message source.

      Resolved by hand rather than through DataLoaderSupport: AiChat binds through its own AiChatItems abstraction and deliberately does not implement SupportsItemsContainer, so nothing in the framework would pick this up.

    • initAutoSave

      protected void initAutoSave(boolean autoSave)
      Installs the default persistence delegates when autoSave is on: the common handling every view otherwise retypes. Both go through the view's DataContext, so the instance the component keeps is the tracked one that save() merges the database's answer back into.

      Two kinds of warning are logged here, and they are deliberately not the same:

      • Nothing is installed when the context cannot persist — absent, or read-only. Installing a delegate that silently saves nothing would be worse than leaving the attribute inert, because the component would report every message as stored.
      • The delegates are installed anyway when the descriptor declares no dataContainer. autoSave is XML-only, so a descriptor attribute is the only way to turn it on, but a chat bound programmatically in onInit() to an entity-backed ContainerAiChatItems has no dataContainer attribute either, and is a legitimate, fully-working configuration. Making that case inert too would break it, so this one only warns — it does not know at load time what the view will bind, and the warning is an unavoidable false positive for that programmatic case. Do not "fix" the inconsistency by making this case inert as well.
      Parameters:
      autoSave - whether the descriptor asked for automatic persistence
    • saveMessage

      protected Object saveMessage(DataContext dataContext, Object message)
      The default save delegate: merges the message into the context, saves, and returns the tracked instance the database's answer was merged back into.
      Parameters:
      dataContext - the context to save through
      message - the committed message
      Returns:
      the tracked instance
      Throws:
      IllegalStateException - when the context reports no save for the message
    • saveOrEvict

      protected EntitySet saveOrEvict(DataContext dataContext, Object entity)
      Saves the context, evicting the given entity if the save fails.

      DataContextImpl#save clears its modified and removed sets only after the store accepted them, so a rejected entity stays queued and is retried by every later save — re-failing forever on a constraint, or inserting out of order once the cause clears. Evicting drops it from both sets, which is what makes the failure recoverable.

      Parameters:
      dataContext - the context to save
      entity - the entity to evict if the save fails
      Returns:
      the entities the context reported as saved
    • getAiComponentLoaderSupport

      protected AiComponentLoaderSupport getAiComponentLoaderSupport()
    • getActionLoaderSupport

      protected ActionLoaderSupport getActionLoaderSupport()