DynaFormControl set disabled

Community Driven Extensions Project
pzoli
Posts: 100
Joined: 27 Feb 2012, 20:52
Location: Hungary
Contact:

01 May 2018, 22:00

I'd like disable rows editing on dynaform with my VisitTaskExecutor:

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;
	}

}
I build dynamic form from like this source:

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 &amp;&amp; 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>
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?
JBoss Developer Studio 11.3.0.GA
Eclipse Oxygen
Wildfly 11
PrimeFaces 6.2.3, PrimaFaces Extensions 6.2.3
Mojarra 2.2.11-jbossorg-1, MyFaces 2.2.8, Deltaspike 1.7.1
MySQL, Oracle, MS-SQL, PostgreSQL, NoSQL

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

02 May 2018, 13:59

@Rapster is the DynaForm expert he says he will get back to you here when he is back from vacation. Stay Tuned!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

pzoli
Posts: 100
Joined: 27 Feb 2012, 20:52
Location: Hungary
Contact:

04 May 2018, 18:51

Melloware wrote:
02 May 2018, 13:59
@Rapster is the DynaForm expert he says he will get back to you here when he is back from vacation. Stay Tuned!
Okay. I made a dynaForm based service.
https://exprog.hu/Homework4Telekocsi

When @Rapster will get back, I'd talk with him about the source publication.

Thank you!
JBoss Developer Studio 11.3.0.GA
Eclipse Oxygen
Wildfly 11
PrimeFaces 6.2.3, PrimaFaces Extensions 6.2.3
Mojarra 2.2.11-jbossorg-1, MyFaces 2.2.8, Deltaspike 1.7.1
MySQL, Oracle, MS-SQL, PostgreSQL, NoSQL

Rapster
Posts: 17
Joined: 08 May 2018, 21:58

08 May 2018, 22:01

Hi there,

Is it possible to have a sample so I can test it?

pzoli
Posts: 100
Joined: 27 Feb 2012, 20:52
Location: Hungary
Contact:

09 May 2018, 11:16

Hi Rapster,

Here is my temp repo on github:

https://github.com/pzoli/Homework4Telekocsi

This is the exprog.hu HoneyWeb and BeeComposit reference implementation project for DynaForm force presentation. A disability carpooling project.
I make an Enity annotatons based database manager framework for easy and rapid administration program development for Primefaces and Extesions.
I can rapidly connect database structure creation with jsf GUI creation with dynamic forms, filterable and orderable tables from entity annotations.
Additional I can make JSF GUIs with Velocity templates from annotated entities, so JSF can be dynamic and static generated for old codebase users, and I can generate any non JSF (like angular) GUIs. I'd like mixed JavaEE and Microprofile services with Keycloak. With this code I can easily help developers to migrate from old codebase to new designed codebase.

HoneyWeb is the basic processor of annotated Entites.
BeeComposit is the basic user interface builder for login, user group and rights management.

I use this configuration and components:
- PostgreSQL database server
- Wildfly 11 application server
- PrimeFaces 6.2.3 and PrimeFaces-Extensions 6.2.3 JSF2 GUI
- Maven project builder
- JBoss Developer Studio 11.3.0.GA
or JBoss Tools 4.5.3.Final plugin with Eclipse Oxygen 3 Java IDE
- JavaMail
- Quarzt
- JasperReports
- Hibernate JPA
- Activiti BPML (future plane)
- Multi language support

HoneyWeb front/manager/BasicManager.java is the begining point where developer can start understand the mechanism of the framework.
I use this code part for start dynaForm visitor:

Code: Select all

	public void setFormRights(String formName, Map<String, FieldModel> fieldModelMap) {
		FacesContext fc = FacesContext.getCurrentInstance();
		FieldRightsInputExecutor visitTaskExecutor = new FieldRightsInputExecutor(fieldModelMap);
		ExecutableVisitCallback visitCallback = new ExecutableVisitCallback(visitTaskExecutor);
		DynaForm dynaForm = (DynaForm) fc.getViewRoot().findComponent(formName);
		if (dynaForm != null) {
			dynaForm.visitTree(VisitContext.createVisitContext(fc, null, VISIT_HINTS), visitCallback);
		}
	}
And here is dynaform visitor implementation (hu.seacon.front.controller.FieldRightsInputExecutor)

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;
	}

}
This is not yet finished, I'd like to use generic UIComponent for disable (maybe wiith Helper, I'll thinking on it).
I changed the right manager in JaratIgenyManager to representate the required function:

Code: Select all

	@Override
	public boolean checkEditableRights(JaratIgeny entity) throws ActionAccessDeniedException {
		//boolean result = entity != null && entity.getIgenyStatusz() != null && !entity.getIgenyStatusz().getIgenyKod().equalsIgnoreCase("V");
		boolean result = true;
		return result;
	}
The pe:dynaForm controls are defined in webapp/WEB-INF/tags/dynFormElements.xhtml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:composite="http://java.sun.com/jsf/composite">
	<h:panelGroup id="dynaGroup">
		<p:growl id="messages" />
		<pe:dynaForm id="dynaForm" value="${formModel}" var="data"
			columnClasses="label-container, field-container">

			<pe:dynaFormControl type="hidden" for="#{data.propertyName}_hidden">
				<p:inputText id="#{data.propertyName}_hidden" value="#{data.value}"
					type="hidden" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:inputText>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="email" for="#{data.propertyName}_email">
				<p:inputText id="#{data.propertyName}_email" value="#{data.value}"
					disabled="#{data.rights.disabled}" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:inputText>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="txt" for="#{data.propertyName}_txt">
				<p:inputText id="#{data.propertyName}_txt" value="#{data.value}"
					disabled="#{data.rights.disabled}" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:inputText>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="password"
				for="#{data.propertyName}_password">
				<p:password id="#{data.propertyName}_password" value="#{data.value}"
					disabled="#{data.rights.disabled}" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:password>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="booleancheckbox"
				for="#{data.propertyName}_ckbox">
				<p:selectBooleanCheckbox id="#{data.propertyName}_ckbox"
					value="#{data.value}" disabled="#{data.rights.disabled}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:selectBooleanCheckbox>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="date" for="#{data.propertyName}_date">
				<p:calendar id="#{data.propertyName}_date" value="#{data.value}"
					disabled="#{data.rights.disabled}" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:calendar>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="textarea" for="#{data.propertyName}_texta">
				<p:inputTextarea cols="70" rows="8" id="#{data.propertyName}_texta"
					disabled="#{data.rights.disabled}" value="#{data.value}"
					required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:inputTextarea>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="integer" for="#{data.propertyName}_integer">
				<p:inputNumber id="#{data.propertyName}_integer"
					value="#{data.value}" decimalPlaces="0"
					disabled="#{data.rights.disabled}" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:inputNumber>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="float" for="#{data.propertyName}_float">
				<p:inputNumber id="#{data.propertyName}_float" value="#{data.value}"
					decimalPlaces="2" disabled="#{data.rights.disabled}"
					required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
				</p:inputNumber>
			</pe:dynaFormControl>
			<pe:dynaFormControl type="autocomplete"
				for="#{data.propertyName}_autocomplete">
				<p:autoComplete scrollHeight="120"
					id="#{data.propertyName}_autocomplete" dropdown="true"
					disabled="#{data.rights.disabled}" value="#{data.value}"
					completeMethod="#{managerBean.autoComplete}"
					converter="#{data.converter}" var="s" forceSelection="false"
					itemValue="#{s[data.lookupLabelfield]}"
					itemLabel="#{s[data.lookupLabelfield]}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
					<p:ajax event="itemSelect" update="@this" />
				</p:autoComplete>
				<p:commandButton
					rendered="#{!data.rights.disabled &amp;&amp; data.rights.admin}"
					id="#{data.propertyName}_autocompletenew"
					title="#{msg['new-button']}"
					action="#{managerBean.showDialog(data.detailDialogFile)}"
					process="@this" icon="ui-icon-star">
					<p:ajax event="dialogReturn" listener="#{managerBean.handleReturn}"
						update="#{data.propertyName}_autocomplete" />
				</p:commandButton>
			</pe:dynaFormControl>
			<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 &amp;&amp; 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>

			<pe:dynaFormControl type="manymenu"
				for="${data.propertyName}_selectmanymenu">
				<p:selectManyMenu id="#{data.propertyName}_selectmanymenu" var="t"
					value="#{data.value}" converter="#{data.converter}"
					disabled="#{data.rights.disabled}" filter="true"
					filterMatchMode="custom" filterFunction="${data.filterFunction}"
					showCheckbox="true" required="#{data.required}">
					<f:attribute name="propertyName" value="#{data.propertyName}" />
					<f:selectItems var="s" value="#{managerBean[data.propertyName]}"
						itemLabel="#{s[data.lookupLabelfield]}" itemValue="#{s}" />
					<p:column>
						<h:outputText value="#{t[data.lookupLabelfield]}" />
					</p:column>
				</p:selectManyMenu>
				<p:commandButton icon="ui-icon-refresh"
					update="_selectmanymenu"
					title="#{msg['refresh-button']}"
					id="#{data.propertyName}_manymenurefresh"
					rendered="#{!data.rights.disabled}" />
				<p:commandButton title="#{msg['new-button']}"
					id="#{data.propertyName}_manymenunew"
					rendered="#{!data.rights.disabled &amp;&amp; data.rights.admin}"
					action="#{managerBean.showDialog(data.detailDialogFile)}"
					process="@this" icon="ui-icon-star">
					<p:ajax event="dialogReturn" listener="#{managerBean.handleReturn}"
						update="_selectmanymenu" />
				</p:commandButton>
			</pe:dynaFormControl>
			<ui:insert name="buttonsBar" />
		</pe:dynaForm>
	</h:panelGroup>
</ui:composition>
Here is a youtube video for the question: Youtube link
Please help to improve development of this project.
Thanks,
Best regards
Zoltan
JBoss Developer Studio 11.3.0.GA
Eclipse Oxygen
Wildfly 11
PrimeFaces 6.2.3, PrimaFaces Extensions 6.2.3
Mojarra 2.2.11-jbossorg-1, MyFaces 2.2.8, Deltaspike 1.7.1
MySQL, Oracle, MS-SQL, PostgreSQL, NoSQL

Rapster
Posts: 17
Joined: 08 May 2018, 21:58

09 May 2018, 13:49

Alright thanks!

So, I gave it a try using showcase (sorry, it's just it's much more easier and faster to see what's wrong...) Using ClearInputsExecutor from showcase, I disabled component instead of clearing values and it works just fine.

The only hint I have in your case, is the shouldExecute method from FieldRightsInputExecutor. Since it always return true, it will execute the entire tree, meaning it will try to disable everything from there. Are you sure, by debugging for example, that setDisabled is only called once? In your case, it feels like it's called more than once

pzoli
Posts: 100
Joined: 27 Feb 2012, 20:52
Location: Hungary
Contact:

09 May 2018, 19:56

The ClearInputsExecutor didn't change the css. Is it possible that disabling one component is change all same css that is shared each selectonemenu?
The visitor control filtered by f:attributes namely propertyName. Each component that has propertyName attribute and FieldModel has FieldEntitySpecificRightsInfo and rights.disabled() not empy must processed. I won't check things twice, but I redesigned the FieldRightsInputExecutor for test. Result is same. Please see repository:
https://github.com/pzoli/Homework4Telek ... cutor.java
Here is a debug video that presents only one selectonemenu will disabled by Visitor: link to Youtube
JBoss Developer Studio 11.3.0.GA
Eclipse Oxygen
Wildfly 11
PrimeFaces 6.2.3, PrimaFaces Extensions 6.2.3
Mojarra 2.2.11-jbossorg-1, MyFaces 2.2.8, Deltaspike 1.7.1
MySQL, Oracle, MS-SQL, PostgreSQL, NoSQL

pzoli
Posts: 100
Joined: 27 Feb 2012, 20:52
Location: Hungary
Contact:

10 May 2018, 20:37

Have any idea?
JBoss Developer Studio 11.3.0.GA
Eclipse Oxygen
Wildfly 11
PrimeFaces 6.2.3, PrimaFaces Extensions 6.2.3
Mojarra 2.2.11-jbossorg-1, MyFaces 2.2.8, Deltaspike 1.7.1
MySQL, Oracle, MS-SQL, PostgreSQL, NoSQL

Rapster
Posts: 17
Joined: 08 May 2018, 21:58

11 May 2018, 18:15

I honestly have no idea and i don't have time to do personal support. What I would recommand you to do is to reproduce your problem in a sample (your project has a bunch of dependencies) and db installation etc. Try with the showcase for example. But again, are you sure setDisabled(true) is called only once?

pzoli
Posts: 100
Joined: 27 Feb 2012, 20:52
Location: Hungary
Contact:

13 May 2018, 12:04

So, I made a test project. Please visit this at github Homework4PFExt. I added InputText elements on 'Add' link, and I try disable rcIndex=1. The result is same as I found with SelectOneMenu.
JBoss Developer Studio 11.3.0.GA
Eclipse Oxygen
Wildfly 11
PrimeFaces 6.2.3, PrimaFaces Extensions 6.2.3
Mojarra 2.2.11-jbossorg-1, MyFaces 2.2.8, Deltaspike 1.7.1
MySQL, Oracle, MS-SQL, PostgreSQL, NoSQL

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests