[MGNLUI-2974] SwitchableField can't have a BasicUploadField Created: 23/Dec/13  Updated: 18/Feb/16  Resolved: 06/Jun/14

Status: Closed
Project: Magnolia UI
Component/s: None
Affects Version/s: 5.2
Fix Version/s: 5.3

Type: Bug Priority: Neutral
Reporter: Milan Divilek Assignee: Eric Hechinger
Resolution: Fixed Votes: 0
Labels: support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
dependency
is depended upon by MGNLDAM-464 Replace DamFileWrapper by an equivale... Closed
relation
is related to MGNLUI-3783 SwitchableField can't have a DamUploa... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

ClassCastException occurs when BasicUploadField (http://documentation.magnolia-cms.com/display/DOCS/Basic+upload) is added into SwitchableField (http://documentation.magnolia-cms.com/display/DOCS/Switchable).

Caused by: java.lang.ClassCastException: info.magnolia.ui.vaadin.integration.NullItem cannot be cast to info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter
	at info.magnolia.ui.form.field.factory.BasicUploadFieldFactory.getOrCreateSubItemWithBinaryData(BasicUploadFieldFactory.java:104)
	at info.magnolia.ui.form.field.factory.BasicUploadFieldFactory.createFieldComponent(BasicUploadFieldFactory.java:83)
	at info.magnolia.ui.form.field.factory.AbstractFieldFactory.createField(AbstractFieldFactory.java:103)
	at info.magnolia.ui.form.field.AbstractCustomMultiField.createLocalField(AbstractCustomMultiField.java:109)
	at info.magnolia.ui.form.field.SwitchableField.initFields(SwitchableField.java:110)
	at info.magnolia.ui.form.field.SwitchableField.initFields(SwitchableField.java:66)
	at info.magnolia.ui.form.field.AbstractCustomMultiField.initFields(AbstractCustomMultiField.java:96)
	at info.magnolia.ui.form.field.SwitchableField.initContent(SwitchableField.java:93)
	at com.vaadin.ui.CustomField.getContent(CustomField.java:92)
	at com.vaadin.ui.CustomField.attach(CustomField.java:82)

Error is caused by this line in info.magnolia.ui.form.field.AbstractCustomMultiField#createLocalField method

FieldFactory fieldfactory = fieldFactoryFactory.createFieldFactory(fieldDefinition, new NullItem());

and then by this line in info.magnolia.ui.form.field.factory.BasicUploadFieldFactory#getOrCreateSubItemWithBinaryData method

Node node = ((JcrNodeAdapter) item).getJcrItem();


 Comments   
Comment by Jaroslav Simak [ 17/Jan/14 ]

The issue can be solved by adding this method, but i am not sure if its a right way to go:

    @Override
    protected Field<?> createLocalField(ConfiguredFieldDefinition fieldDefinition, Item item, boolean setCaptionToNull) {

        FieldFactory fieldfactory = fieldFactoryFactory.createFieldFactory(fieldDefinition, item);
        fieldfactory.setComponentProvider(componentProvider);
        fieldfactory.setI18nContentSupport(i18nContentSupport);
        // FIXME change i18n setting : MGNLUI-1548
        fieldDefinition.setI18nBasename(definition.getI18nBasename());
        Field<?> field = fieldfactory.createField();
        if (field instanceof AbstractComponent) {
            ((AbstractComponent) field).setImmediate(true);
        }
        if (setCaptionToNull) {
            field.setCaption(null);
        }
        return field;
    }

to the SwitchableField (it is copy-paste from the AbstractCustomMultiField with one difference - JCR Item (instead of NullItem) is passed to the field factory.

Comment by Federico Grilli [ 28/Jan/14 ]

I had to stop progress for this issue as there is no easy and quick way to solve it in 5.2.2 being a rather complex task involving field transformers http://documentation.magnolia-cms.com/display/DOCS/Transforming+field+values. Currently BasicUploadField, due to its complexity, is the only field without a dedicated transformer (it uses the default one). As I was told by Eric Hechinger, who knows most about the topic, it is a current limitation that SwitchableField(s) cannot have a BasicUploadField. However, he's planning to have this resolved for 5.3.
The workaround mentioned by Jaroslav unfortunately seems not to work (no binary or reference to it is saved as far as I could see).

Generated at Mon Feb 12 09:01:59 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.