Skip to main content

Set form mode for D2FS dialog

Forms in D2FS dialogs can be rendered in either editable(create) or readonly(read) mode.

When rendering a dialog form on D2 Smartview UI, this is determined by checking for the form_mode attribute of dialog xml.

When creating a D2FS dialog, the workspace assistant prompts user to select the form_mode. The selected value from workspace assistant is set in the dialog definition xml file <Plugins Directory>\src\main\resources\xml\dialog\<Dialog Name>.xml.

<dialog auto_smartview_edit_mode="false" buttons_right="false" focus="" height="500" id="SomeDialog" initial_invalid="false" resizable="true" signoff_creation="false" signoff_edit="false" signoff_import="false" signoff_intention_dictionary="" signoff_intention_required="false" width="400" form_mode="create">
<content>
<text advancedView_required="true" condition_required="true" control="true" id="name_field"/>
</content>
<buttons>
<button action="validDialog()" id="buttonOk" isPrimary="true"/>
<button action="cancelDialog()" id="buttonCancel"/>
</buttons>
<signoff_fallback_message>
<message locale="en" value=""/>
</signoff_fallback_message>
</dialog>

But this can be overwritten later either by editing the dialog definition xml file or by setting form_mode attribute for result XmlNode in buildDialog method of <Plugins Directory>\src\main\java\<Maven Group Id>\smartview\<Plugin Name>\dialogs\<Dialog Name>.java

public class SomeDialog extends AbstractDialog implements ID2Dialog {
...
@Override
public XmlNode buildDialog(D2fsContext context, List<Attribute> attributes) throws Exception {
...
XmlNode result = super.buildDialog(context, dialogFile, labelsBundle, context.getFirstObject(), defaultValues);

if(result == null) {
result = super.buildDialog(context, attributes);
}

// Custom logic to determine formMode at run time
String formMode = 1 == 0 ? "read" : "create";

result.setAttribute("form_mode", formMode);

return result;
}
...
}

In case of chained dialogs, if the chained dialog is returned as result from validDialog method of <Plugins Directory>\src\main\java\<Maven Group Id>\smartview\<Plugin Name>\dialogs\<Dialog Name>.java,

form_mode attribute could be set for result XmlNode before returning it.
public class SomeDialog extends AbstractDialog implements ID2Dialog {
...
@Override
public XmlNode validDialog(D2fsContext context) throws Exception {
...
XmlNode result = super.validDialog(context);

// Custom logic to determine formMode at run time
String formMode = 1 == 0 ? "read" : "create";

result.setAttribute("form_mode", formMode);

return result;
}
...
}

The form_mode attribute for chained dialog could also be set from validDialog method of <Plugins Directory>\src\main\java\com\opentext\d2\smartview\webfs\dialog\D2DialogServicePlugin.java before returning the dialog.

public class D2DialogServicePlugin extends D2DialogService implements ID2fsPlugin {
...
public Dialog validDialog(Context context, String id, String dialogName, List<Attribute> parameters) throws Exception {

// Custom logic

Dialog dialog = super.validDialog(context, id, dialogName, parameters);

XmlNode xmlDialog = XmlUtil.loadFromString(dialog.getXmlContent()).getRootXmlNode();

// Custom logic to determine formMode at run time
String formMode = 1 == 0 ? "read" : "create";

xmlDialog.setAttribute("form_mode", formMode);

dialog.setXmlContent(xmlDialog.toString());

return dialog;
}
...
}