how to pass a String[] array in the declarative UI

50 views
Skip to first unread message

Marius Grama

unread,
Oct 31, 2012, 9:51:36 AM10/31/12
to google-we...@googlegroups.com
I have an own Button class which has a method
void setDisplayPermissions(String[] displayPermissions)
where it is specified for the button which are the required permissions needed for showing the button.

In the example bellow i can set that the button should be shown only when the user has the FINISH_ORDER function right.
<a:Button ui:field="finishButton" displayPermissions="{Rights.getFinishOrder}"/>

(Rights is an application specific class where there are getters defined for all the function rights names from the application)

Now I'd like to show this button when the user has FINISH_ORDER or CANCEL_ORDER function right.
Can anybody suggest me how to do this (elegantly) through the declarative UI within a .ui.xml file?

Thanks in advance.

Benjamin Possolo

unread,
Oct 31, 2012, 5:06:34 PM10/31/12
to google-we...@googlegroups.com
You are trying to add logic to your UiBinder XML file which is not what it is intended to do. View-specific logic goes in the java code.

Just do it in the constructor or if you are caching your views (which is good for performance) in a dedicated method that can be called before the view is rendered by your Activity.

For the sake of an example, lets assume your UiBinder class is called MyView.

public class MyView extends Composite {

//definition of UiBinder interface and instance

@UiField
FinishButton finish;

public MyView(){
initWidget(binder.initAndBindUi(this));
}

public MyView(Rights permissions){
this();
updateUi(permissions);
}
 
public void updateUi(Rights permissions){
if( permissions == FINISH_ORDER || permissions == CANCEL_ORDER ) 
finish.setVisible(true);
}

@UiHandler("finish")
void onClickFinish(ClickEvent e){
//handle the click
}
}
Reply all
Reply to author
Forward
0 new messages