DynaFormControl set disabled
Posted: 01 May 2018, 22:00
I'd like disable rows editing on dynaform with my VisitTaskExecutor:
I build dynamic form from like this source:
But when I disable a select in the visitor, other selects are disabled, too. Is this normal? How can I reduce disable only one input field?
Code: Select all
public class FieldRightsInputExecutor implements VisitTaskExecutor {
private Map<String,FieldModel> fieldModelMap;
public FieldRightsInputExecutor(Map<String,FieldModel> fieldModelMap) {
this.fieldModelMap = fieldModelMap;
}
@Override
public VisitResult execute(UIComponent component) {
VisitResult result = VisitResult.ACCEPT;
if (component instanceof UIInput) {
UIInput input = (UIInput) component;
String propertyName = (String) input.getAttributes().get("propertyName");
if (propertyName != null) {
FieldModel fieldModel = fieldModelMap.get(propertyName);
if (fieldModel != null) {
FieldEntitySpecificRightsInfo rights = fieldModel.getFieldEntitySpecificRightsInfo();
if (rights != null && rights.disabled() != null && !rights.disabled().isEmpty()) {
if (input instanceof SelectOneMenu) {
((SelectOneMenu)input).setDisabled(evalELToBoolean(rights.disabled()));
}
}
}
}
}
return result;
}
private Boolean evalELToBoolean(String expression) {
Boolean result = null;
if (expression != null && !expression.isEmpty()) {
FacesContext context = FacesContext.getCurrentInstance();
try {
result = context.getApplication().evaluateExpressionGet(context, expression, Boolean.class);
} catch (ELException ex) {
}
}
return result;
}
@Override
public boolean shouldExecute(UIComponent input) {
return true;
}
}
Code: Select all
<pe:dynaFormControl type="select" for="#{data.propertyName}_select">
<p:selectOneMenu id="#{data.propertyName}_select"
value="#{data.value}" autoWidth="false"
disabled="#{data.rights.disabled}" required="#{data.required}">
<f:attribute name="propertyName" value="#{data.propertyName}" />
<f:selectItem itemLabel="--- #{msg['select-one']} ---"
noSelectionOption="true" />
<f:selectItems var="s" value="#{managerBean[data.propertyName]}"
itemLabel="#{s[data.lookupLabelfield]}"
itemValue="#{s[data.lookupKeyfield]}" />
</p:selectOneMenu>
<p:commandButton icon="ui-icon-refresh" id="_selectrefresh"
update="_select" rendered="#{!data.rights.disabled}"
title="#{msg['refresh-button']}" />
<p:commandButton
rendered="#{!data.rights.disabled && data.rights.admin}"
id="#{data.propertyName}_selectnew" title="#{msg['new-button']}"
action="#{managerBean.showDialog(data.detailDialogFile)}"
process="@this" icon="ui-icon-star">
<p:ajax event="dialogReturn" listener="#{managerBean.handleReturn}"
update="_select" />
</p:commandButton>
</pe:dynaFormControl>