Maximo Open Forum

 View Only

 how to update custom control on "Next record"

  • Customizations
Jason Uppenborn's profile image
Jason Uppenborn posted 02-09-2022 17:31

I have created a simple "label" custom control based on Viet Tran's Maximo custom control (Part IV) – Create a chart control blog post. All my control has to do is put "Hello <valueOfDataattribute>!" in the HTML, like this:

As shown above, it works when you load a record from the List. However, if you load a record by using the Previous or Next buttons, it does not update.

Here is properties/registry-extensions/mycontrol-registry-extension.xml:

<?xml version="1.0" encoding="UTF-8"?>
<control-registry basedir="webclient/controls" package="psdi.webclient.controls"
        xsi:noNamespaceSchemaLocation="../control-registry.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <control-descriptor name="mycontrol">
        <property-list>
            <property name="id">
                <flag name="final" />
            </property>
            <property name="datasrc">
                <flag name="nonconditional" />
                <flag name="global" />
            </property>
            <property name="dataattribute">
                <flag name="final"/>
            </property>
        </property-list>
        <component-list>
            <components id="co" layout="horizontal">
                <mylabelcomponent id="co1"/>
            </components>
        </component-list>
        <containers>
            <container name="section" />
        </containers>
    </control-descriptor>
</control-registry>

 

Here is properties/registry-extensions/mylabel-registry-extension.xml:

<?xml version="1.0" encoding="UTF-8"?>
<component-registry basedir="webclient/components"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../component-registry.xsd">
    <component-descriptor name="mylabelcomponent" instance-class="${package}.controller.BoundComponentInstance">
        <property-list>
            <property name="jsp-filename">
                <default-value>mylabel</default-value>
            </property>
            <property name="id">
                <flag name="final" />
            </property>
        </property-list>
    </component-descriptor>
</component-registry>

 

Here is maximouiweb/webmodule/webclient/components/mylabel.jsp:

<%@include file="../common/componentheader.jsp" %>
<%
    String text = control.getPage().getDataBean().getMbo().getString(control.getProperty("dataattribute"));
%> 
<div>Hello <%=text%>!</div>
<%@include file="../common/componentfooter.jsp" %>

 

Note that I have tried this in mylabel.jsp but the result did not change.

<div>Hello <%=control.resolveParams("{"+control.getProperty("dataattribute")+"}")%>!</div> 


To use my control, I put this in the XML for my application (precautn / Precautions) by export / import:

<mycontrol id="mycontrol1" dataattribute="precautionid"/>

 

What have I missed?

Steven Shull's profile image
Steven Shull

I'll have to start with I've never created a custom component. I noticed the RichTextViewer utilizes this to get the value:

String value = ((BoundComponentInstance)component).getString();


That makes more sense to me. I would try that and if it doesn't work let me know and I can test doing something similar and let you know.

Jade Warren's profile image
Jade Warren
We've tackled this by doing the following:
  1. Create a statictext control in the application definition (XML) and give it a meaningful ID value such as "hello_text"
  2. Create or modify an automation script that fires on the INIT of the target MBO...
  3. Inside of that script, do something like this:
if (interactive):
    session = service.webclientsession();
    appinstance = session.getCurrentApp();
    appbean = session.getCurrentApp().getAppBean();
    vapp = session.getCurrentAppId().upper();
    hello = session.findControl("hello_text");

    if (vapp in ("TARGET_APP_LIST_HERE") and hello != None):
        hello_text = "Hello " + mbo.getString("precautionid") + "!";
        hello.setProperty("label", hello_text);

What's nice about this is that your changes won't get overwritten with patches that affect controlregistry.xml, etc...

Cheers,

Jade
Jason Uppenborn's profile image
Jason Uppenborn
You can read the full answer on the IBM Maximo forum. My takeaways from the answer provided there are:
  1. The control registry must define the datasrc and dataattribute properties and pass dataattribute="@{dataattribute}" to the component.
  2. The component registry must define the dataattribute and defaultrender properties and give defaultrender a defaultvalue of true.
  3. The component JSP needs to inject the value of the "dataattribute" using <%=boundComponent.getString()%>.