Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following example shows use of a macro that does not use parameters:

Macro:

 

Code Block
<modifications document=”nxml”>
<remove select="id(''{0}'')">
</modifications>
 
 
Calling this Macro:

The following example shows use of a macro with parameters:

Macro:

...

Code Block
<modifications document=”nxml”>
             <remove select="id(''{0}'')">
 </modifications>
 

Calling this macro:

onCommand=”macro://mymacro.execute (‘Window1’)

...

The following shows the basic format for defining macros:

 

Code Block
<macro xmlns:macro="http://nexaweb.com/macro">
   name = name-attribute-type
 (any valid Nexaweb elements or strings that become Nexaweb page elements when substituted for parameters)
 </macro>
 

name-attribute-type specifies a name that uniquely identifies this macro.

...

In this example, a page contains a macro named, mymacro. The body of this macro contains just one XUpdate command (set-attribute) that changes the text of a label ("mylabel"). When a user presses the button "Execute Macro", the macro executes and changes the label's name from Old Text to New Text.

 

Code Block
<nxml>
     <macro:macro name="mymacro" xmlns:macro="http://nexaweb.com/macro">
         <xu:modifications xmlns:xu="http://nexaweb.com/xupdate">
             <xu:set-attribute select="id(''mylabel'')">
                 <xu:attribute name="text" value="New Text" />
             </xu:set-attribute>
         </xu:modifications>
     </macro:macro>
    <panel>
         <flowLayout align="center"/>
         <label text="Old Text" id="mylabel" bgcolor="green"/>
         <button text="Execute Macro" onCommand="macro://mymacro.execute()"/>
     </panel>
 </nxml>
 

Defining Macro XUpdate Commands With Parameters

 The following examples show the same macro without and with parameters:

...

Code Block
<macro:macro name="mydialog" xmlns:macro="http://nexaweb.com/macro">
      <xu:modifications document="nxml" xmlns:xu="http://nexaweb.com/xupdate">
         <xu:append select="/nxml/rootPane">
             <dialog title="My Dialog" closeable="false" focused="true" centered="true"> 
                 <label text="My dialog is your dialog, from California, to the New York islands"/>
             </dialog>
         </xu:append>
     </xu:modifications>
 </macro:macro>
<macro:macro name="generic-dialog" xmlns:macro="http://nexaweb.com/macro">
      <xu:modifications document="nxml" xmlns:xu="http://nexaweb.com/xupdate">
         <xu:append select="/nxml/rootPane">
             <dialog title="{0}" closeable="{1}" focused="{2}" centered="{3}"> 
                 <label text="{4}"/>
             </dialog>
         </xu:append>
     </xu:modifications>
 </macro:macro>
 

The following shows a macro call to the macro with parameters:

...

Code Block
<macro:macroCall name="generic-dialog"
      xmlns:macro="http://nexaweb.com/macro" >
      <macro:parameter>ThisIt</macro:parameter>
      <macro:parameter>true</macro:parameter>
      <macro:parameter>true</macro:parameter>
      <macro:parameter>false</macro:parameter>
      <macro:parameter>Answer</macro:parameter>
 </macro:macroCall>

 

The following shows an event handler call to the macro with parameters:

...

Code Block
<button onCommand="macro://generic-dialog.execute( 'ThisIt', 'true', 'true', 'false', 'Answer' )" />

 

Specifying Parameters In Macros

...

Specifying Parameters In Event Handlers

...

Code Block
<button onCommand="macro://generic-dialog( {id('myDialogTitleField')/@text}, 'true', 'true', 'false', {MyDataDocument:id('myTextField')/@text} )" />
 

Programatic Macro Definition and Call

The following example defines a macro programatically:

...

Code Block
MacroContainer macroContainer = ClientSession.getMacroContainer();
 Macro macro = macroContainer.createMacro
      ("<xu:modifications xmlns:xu=\"http://nexaweb.com/xupdate\" document=\"nxml\">" +
       " <xu:append select=\"/nxml/rootPane[1]\">" +
       " <dialog>" +
       " <label text=\"Call me Ishmael. Some years ago- never mind how long precisely...\" />" +
       " </dialog>" +
       " </xu:append>" +
       "</xu:modifications>" );
 macroContainer.putMacro("nexaweb-examples-herman-melville-dialog", macro);
 

The following example shows a programatic macro call:

...

Code Block
MacroContainer macroContainer = clientSession.getMacroContainer();
 Macro melvilleMacro = macroContainer.getMacro( "nexaweb-examples-herman-melville-dialog" );
 melvilleMacro.execute();
Macro genericXUpdateMacro = macroContainer.getMacro( "nexaweb-examples-generic-xupdate" );
 genericXUpdateMacro.execute( new Object [] { "remove-element", "id('anElementId')", "" } );

 genericXUpdateMacro.execute( new Object [] { "append", 
"/nxml/rootPane[1]", "<dialog><label 
text=\"Mylabel\"/></dialog>" } );

 

Debugging and Troubleshooting Macros
To debug macros, enable macro debug logging in the application's client configuration file, nexaweb-client.xml, as follows:

...

Code Block
<log-configuration>
     <log name="Macro" log-level="debug"/>
 </log-configuration>

 

The following shows sample output from the macro log (note that all client side logging goes to the browser's java console):

Note: The sample output below shows the specified arguments, the macro, and pre- and post- formatting.

...

Code Block
[Debug - 10:42:22 (Macro): Enabled debug logging.]
 [Debug - 10:42:35 (Macro): Formatting macro with 0 args: []]
 [Debug - 10:42:35 (Macro): Macro pre-formatting:
 <nxml><xu:modifications xmlns:xu="http://nexaweb.com/xupdate" document="nxml">
 <xu:append select="/nxml/rootPane[1]">
 <dialog>
 <label text="Call me Ishmael. Some years ago- never mind how long precisely..."/>
 </dialog>
 </xu:append>
 </xu:modifications></nxml>]
 [Debug - 10:42:35 (Macro): Macro post-formatting:
 <nxml>
 <xu:modifications xmlns:xu="http://nexaweb.com/xupdate" document="nxml">
 <xu:append select="/nxml/rootPane[1]">
 <dialog>
 <label text="Call me Ishmael. Some years ago- never mind how long precisely..."/>
 </dialog>
 </xu:append>
 </xu:modifications>
 </nxml>]

 [Debug - 10:42:46 (Macro): Formatting macro with 3 args: ["append", 
"/nxml/rootPane[1]", "<dialog><label text="Mylabel" 
/></dialog>"]]
 [Debug - 10:42:46 (Macro): Macro pre-formatting:
 <nxml>
 <xu:modifications document="nxml" xmlns:xu="http://nexaweb.com/xupdate" >
 <xu:{0} select="{1}" >
 {2}
 </xu:{0}>
 </xu:modifications>
 </nxml>]
 [Debug - 10:42:46 (Macro): Macro post-formatting:
 <nxml>
 <xu:modifications document="nxml" xmlns:xu="http://nexaweb.com/xupdate" >
 <xu:append select="/nxml/rootPane[1]" >
 <dialog><label text="Mylabel" /></dialog>
 </xu:append>
 </xu:modifications>
 </nxml>]
 

Backward Compatibility
If you were using macros prior to Nexaweb's 4.2 release and those macros contained any of the MessageFormat special characters, you may wish to disable the MessageFormat functionality to ensure that your macros continue to function as before. This can be done by changing the following value to true in your nexaweb-client.xml file:

...

Code Block
    <!-- This parameter is supplied so that the macro code can know NOT -->
	<!-- to use MessageFormat for the macro strings. in 4.2 we added parameters -->
	<!-- which use MessageFormat, thus single tick escaping is required in 4.2 -->
	<!-- plus. We want existing macros to work if the customer so desires. -->
	<ensure-pre-4-dot-2-macro-compatibility>false</ensure-pre-4-dot-2-macro-compatibility> 
 

onCommand=”macro://mymacro.execute (‘Window2’)"