基本自訂 > User Interface Customization > Adding Actions and Hooking Them Up in the UI > Defining Menus > Displaying Actions > Displaying Actions Column in a Table
  
Displaying Actions Column in a Table
* 
You can no longer add the actions column to tables. The actions column is in the data store, but not available in the UI. The actions menu is only available by right-clicking each row
1. Define the actions in an actions.xml file (see Defining a new action)
2. Add the actions to an action model (see Defining a new action). There are multiple levels where the action model can be set for a particular table. They are listed below in ascending order of complexity:
a. Define a “menufor” a business object type.
In the action model definition (in the XML file), set the attribute “menufor” for the object type that you are defining the actions for.
<model name="part actions" menufor="wt.part.WTPart">
<action name="view" type="object"/>
.....
</model>
To get a menu to fly out from the main menu, add a submenu to the action model.
<model name="part actions" menufor="wt.part.WTPart">
<action name="action_1" type="object"/>
<submodel name="submenu_new"/>
</model>

<model name="submenu_new">
<action name="newViewVersion" type="part"/>
</model>
b. Set action model in a Builder.
There can only be one action model per type with the menufor attribute. If you would like to override the default action model for your table you can specify a different model in your table builder. See MVC Components for information on creating a table builder class.
public ComponentConfig buildComponentConfig (ComponentParams params) {
ComponentConfigFactory factory = getComponentConfigFactory ();
JcaTableConfig table = (JcaTableConfig) factory.newTableConfig ();

ColumnConfig actionsMenu = setComponentConfigFactory().
newColumnConfig(DescriptorConstants.ColumnIdentifiers.NM_ACTIONS, true);

(JcaColumnConfig)actionsMenu).setDescriptorProperty
(DescriptorConstants.ActionProperties.ACTION_MODEL,
"model_name_here");
table.addComponent(actionsMenu);
....
return table;
}
c. Create a custom Data Utility.
If you can’t rely on a “menufor” action model for your table because you need to calculate which action model to use dynamically, then you’ll need to create a data utility for the actions column. You will need to extend NmActionDataUtility and override the getDataValue() method. Set the property DescriptorConstants.ActionProperties.ACTION_MODEL on the component descriptor to the name of the action model you want to use:
public class CustomNmActionDataUtility extends NmActionDataUtility {

@Override
public Object getDataValue(String component_id, Object datum,
ModelContext mc) throws WTException {
String modelName = "foo";
if(...) {
modelName = "bar";
} else {
modelName = "baz";
}

mc.getDescriptor().setProperty( DescriptorConstants.
ActionProperties.ACTION_MODEL, modelName);
return super.getDataValue(component_id, datum, mc);

}
}
You can specify different action models for different types of datums (row objects) or use other logic based on information in the model context to determine the action model to use.
* 
If you don’t want to display any actions in the actions column you can set the action model to EMPTY_ACTION_MODEL. When you do that, the text “No Actions to Display” will appear in the actions column.
After creating your data utility, add a column to the table in the builder. Use a custom column id (i.e “customNmActions”) instead of DescriptorConstants.ColumnIdentifiers.NM_ACTIONS:
public ComponentConfig buildComponentConfig (ComponentParams params) {
ComponentConfigFactory factory = getComponentConfigFactory ();
JcaTableConfig table = (JcaTableConfig) factory.newTableConfig ();

ColumnConfig actionsMenu = setComponentConfigFactory().
newColumnConfig(“customNmActions”, true);


....

table.addComponent(actionsMenu);
....
return table;
}
Finally, you’ll need to register your data utility for the custom column id in an *.xconf entry, e.g:
<!-- Sample XCONF Entry -->
<Service name="com.ptc.core.components.descriptor.DataUtility">
<Option serviceClass="com.ptc.windchill.dataUtilities.
CustomNmActionDataUtility
" requestor="java.lang.Object"
selector="customNmActions" cardinality="singleton"/></Service>
Trouble Shooting
Problem Description
Solution
Action Column does not appear in Table
By default, the actions column is not displayed. Users are not allowed to see it. Right-clicking a row is the only way to see the row actions.
Icons for some actions are missing
To follow UI standards, the action service is designed to only show the icons in the actions menu if those icons also appear in some toolbar anywhere in the system. If you need to workaround this for some action that doesn’t belong in any toolbar, you could create a dummy model with your action such as:
<model name=”toolbarModelNotUsedAnywhere”>
<action name=”myAction” type=”myActionType”/>
</model>
Then the action service will show the icon defined for that action in the actions menu.
User right clicks and gets the following error message: No Actions to Display
Ensure “menufor” attribute is defined on the action model (in the XML file) for your type: menufor=”your.type.Here”
(Or you can define which model should be used in the builder when you add the column to the table config)
Add the NmActions column identifier to the table config in the MVC builder:
public ComponentConfig buildComponentConfig
(ComponentParams params) {
ComponentConfigFactory factory
= getComponentConfigFactory ();
JcaTableConfig table =
(JcaTableConfig) factory.newTableConfig ();

table.addComponent (factory.newColumnConfig
(DescriptorConstants.ColumnIdentifiers.NM_ACTIONS
, true));
....

return table;
}
Using fiddler/firebug, check what the oid parameter is on the servlet/ActionsMenu request that is made when you right click. If its not the oid you expected, or if there is no oid at all, the infrastructure was not able to make the correct NmOid from the backing objects used for the table. See the NmObjectUtility documentation for more details of how to control what oid will be used for actions in the table.
If you are defining the action model to be used for the table/column (described in the Actions Column in a Table section under Intended Outcome). Using fiddler/firebug check what the “actions” parameter is on the servlet/ActionsMenu request made when you click to get the menu. Is the “actions” param the model name you defined? If actions=EMPTY_ACTION_MODEL it means the action column is not defined in the current table view. The actions column is required for the right click menu to work. Try using the “View”->”Customize…” option to add the actions column to the current table view. Change the table builder to make the actions column one of the default columns.
Check the validators defined on the actions in the model. Did all the actions get validated as hidden? If that was the case, then adding jcaDebug=true as a URL param should show the list of actions that were hidden as disabled actions in the menu.
User right clicks and gets the following error message: You do not have access to this object or it does not exist
This message is ok if the user really does not have access to the row object.
If the user should have access (for example they are able to get to the information page and see the actions menu there) Then using fiddler/firebug, check what the oid parameter is on the servlet/ActionsMenu request that is made when you right click. If its not the oid you expected, or if there is no oid at all, the infrastructure was not able to make the correct NmOid from the backing objects used for the table. See the NmObjectUtility documentation for more details of how to control what oid will be used for actions in the table.
Some actions don’t appear in the list in the UI
There may be a validator configured on it which may hide the action in certain conditions. See Action Framework for Windchill Client Architecture for information on configuring an action with a validator.
Add jcaDebug=true to the url to see even the hidden actions. With the jcaDebug option enabled, you’ll see more information in the menu, and there will be an action at the end of the list that takes you to the action model report for that menu.
Wrong set of actions is showing.
Add jcaDebug=true and check what vaildators are on the actions in the menu. Check that the validators are working as you’d expect.
1. If you expect the action model to be found by type (described in the Actions Column in a Table section under Intended Outcome) , is ‘menuFor’ defined on the action model for the object type?
To see what the action service is finding for the type of object in the row, turn on log4j logger : com.ptc.netmarkets.util.misc. StandardNmActionService
2. If the model to use is defined on the table/column (described in the Actions Column in a Table section under Intended Outcome):
To see what action model the default data utility is returning turn on log4j logger: com.ptc.core.components.factory.dataUtilities.NmActionDataUtility
The jcaDebug param will also produce a link to the action model report at the bottom of the menu. The action model report will have the model name, the set of actions in that model, where the model is defined, whether the model overrides any other models, etc. Make sure the model is defined as you’d expect.
If you made a custom data utility for the column, make sure the correct column is getting used. Set jcaDebug=true on the URL and inspect the column header DOM element to make sure the column id is as you’d expect. Each column will have header text that starts with the column id, for example the default actions column would have header text like: “nmActions validated by: …”.
Displaying Actions