In recompiling our Java modules against LabKey 12.2 (trunk), we are hitting compile errors from our use of the deprecated constructor:
@Deprecated /** Use version that takes an action class instead */
private ActionButton(String actionName, String caption)
{
assert StringUtils.containsNone(actionName,"/:?") : "this is for _actions_, use setUrl() or setScript()";
_actionName = StringExpressionFactory.create(actionName);
_caption = StringExpressionFactory.create(caption);
}
Could you help explain which version of the constructor to use that "takes an action class"?
And give the code - below - from Elispot Module where we are experiencing these compile errors, could you give an example of such a migration?
Thanks.
Scott Langley
slangley@scharp.org
private static final String VIEW_BEGIN = "begin.view";
...
String actionName = "insertToStudy.view";
...
String actionName = "insertToLabs.view";
...
String actionName = "insertToStudyLabs.view";
...
String actionName = "insertToBatch.view?labstudyseqId="+queryValue;
...
String actionName = "insertToPlate.view?batchseqId="+queryValue;
...
protected ButtonBar getButtonBar(String insertAction,String actionName)
{
ButtonBar bb = new ButtonBar();
ActionButton insertButton = new ActionButton(ActionButton.BUTTON_DO_INSERT);
insertButton.setActionName(insertAction);
insertButton.setCaption("Insert a Row");
bb.add(insertButton);
ActionButton viewButton = new ActionButton(actionName,"View Data");
bb.add(viewButton);
ActionButton goBack = new ActionButton(VIEW_BEGIN, "Go Back");
ActionURL backURL = new ActionURL(EliSpotModule.NAME,VIEW_BEGIN, getContainer());
goBack.setURL(backURL.getLocalURIString());
bb.add(goBack);
return bb;
}
private DataRegion getDataRegion(Container c,List<ColumnInfo> cInfo,String actionName)
{
DataRegion rgn = new DataRegion();
rgn.setColumns(cInfo);
ButtonBar gridButtonBar = new ButtonBar();
ActionButton insert = new ActionButton(actionName, "Insert a Record");
insert.setActionType(ActionButton.Action.LINK);
insert.setDisplayModes(DataRegion.MODE_GRID);
gridButtonBar.add(insert);
ActionURL backURL = new ActionURL(EliSpotModule.NAME,VIEW_BEGIN, c);
ActionButton goBack = new ActionButton(VIEW_BEGIN, "Go Back");
goBack.setURL(backURL.getLocalURIString());
gridButtonBar.add(goBack);
rgn.setButtonBar(gridButtonBar,DataRegion.MODE_GRID);
rgn.setShowBorders(true);
rgn.setShadeAlternatingRows(true);
return rgn;
} |
|
Karl Lum responded: |
2012-06-28 12:17 |
Hi Scott,
For your examples I would probably use the variant of constructor that takes an ActionURL class : ActionButton(ActionURL, String). That way you can pass in an ActionURL that contains your action class plus any optional parameters. The ActionURL is usually constructed from a controller action class and Container. If your controller actions are not visible from your implementing class, let me know and I can show you ways to expose them.
So for example, you could possibly refactor the getButtonBar class like this:
ActionURL insertUrl = new ActionURL(InsertToStudyAction.class, getContainer());
ActionURL actionUrl = new ActionURL(InsertToBatchAction.class, getContainer()).addParameter("labstudyseqId", "+queryValue");
...
protected ButtonBar getButtonBar(ActionURL insertURL, ActionURL action)
{
ButtonBar bb = new ButtonBar();
ActionButton insertButton = new ActionButton(ActionButton.BUTTON_DO_INSERT);
insertButton.setURL(insertURL);
insertButton.setCaption("Insert a Row");
bb.add(insertButton);
ActionButton viewButton = new ActionButton(action,"View Data");
bb.add(viewButton);
ActionButton goBack = new ActionButton(new ActionURL(BeginAction.class, getContainer()), "Go Back");
ActionURL backURL = new ActionURL(EliSpotModule.NAME,VIEW_BEGIN, getContainer());
goBack.setURL(backURL.getLocalURIString());
bb.add(goBack);
return bb;
}
- Karl |
|
slangley responded: |
2012-06-29 15:44 |
Thanks Karl. That was very helpful.
The only complication I ran into was for a few insert actions that were of the .post type instead of the .view type. For those, I had to add a:
insertButton.setActionType(Action.POST);
as you might expect. |
|
|
|