DynaForm adding and removing fields

Community Driven Extensions Project
Post Reply
d34d_d3v1l
Posts: 193
Joined: 01 Nov 2012, 04:48

29 Nov 2012, 20:41

Hi guys,

first congrads for DynaForm component. It is very cool.
But I didn´t see a feature that adds and removes fields dynamicly.
I´m trying to do that "by hand" with the methods:

Code: Select all

public boolean filterIsVisible(String path) {
		boolean exists = false;

		// verificar se o campo ja esta no modelo
		for (DynaFormControl control : getDynaFormModel().getControls()) {
			PropertyFilter filter = (PropertyFilter) control.getData();
			if (filter.getPath().equals(path)) {
				exists = true;
				break;
			}
		}
		return exists;
	}
    
	public void forbidPermission(String path){
		DynaFormControl control = null;
		
		for (DynaFormControl co : getDynaFormModel().getControls()) {
			PropertyFilter filter = (PropertyFilter) co.getData();
			if (filter.getPath().equals(path)) {
				control = co;
			}
		}
		
		if(control != null){
			getDynaFormModel().getControls().remove(control);
		}
		
	
	}
        
    public void givePermission(ActionEvent er){    	    	
    	boolean exists = filterIsVisible(selectedFilter);
    	
    	//adicionar somente se nao estiver
    	if(!exists){
    		addFilterToForm(selectedFilter);
    	}
    
    }
    
    
    private void addFilterToForm(String filterPath){
    	PropertyFilter filter = getFilter(filterPath);    	
    	DynaFormRow row = getDynaFormModel().createRegularRow();
    	DynaFormLabel label = row.addLabel(filter.getLabel(), 1, 1);    	
    	DynaFormControl control = row.addControl(filter, filter.getType().name(), 1, 1);
    	label.setForControl(control);    	    
    }

    
    private PropertyFilter getFilter(String path) {
		PropertyFilter filter = null;
    	
    	for(PropertyFilter f : getFilters()){
    		if(f.getPath().equals(path)){
    			filter = f;
    		}
    	}
    	
    	if(filter == null)
    		throw new IllegalArgumentException("Filtro pesquisado não encontrado no modelo de filtros!");
    	
		return filter;
	}

    
it works when I add:

Code: Select all


				<p:selectOneMenu value="#{cc.attrs.controller.selectedFilter}">
					<f:selectItem itemLabel="Selecione um filtro..." itemValue="" />
					<f:selectItems value="#{cc.attrs.controller.filters}" var="f"
						itemLabel="#{f.label}" itemValue="#{f.path}" />
				</p:selectOneMenu>

				<p:commandButton icon="ui-icon-circle-plus"
					actionListener="#{cc.attrs.controller.givePermission}"
					update=":filterForm" />
but not when I remove:

Code: Select all

			<p:commandButton icon="ui-icon-circle-minus"
				actionListener="#{cc.attrs.controller.forbidPermission(data.path)}"
				update=":filterForm" disabled="#{data.defaultField}" />
PS: I´m writting all that inside a COMPOSITE COMPONENT. But I get the exception:

Code: Select all

EVERE: Method not found: br.com.sol7.olimpio.control.controllers.GrupoController@cf955a.forbidPermission()
javax.faces.event.AbortProcessingException: Method not found: br.com.sol7.olimpio.control.controllers.GrupoController@cf955a.forbidPermission()
Is it because I´m trying to pass a String as argument "data.path" of my PE's dynaForm component ?

Another thing...
The filter component looks like this:

Image

See? All messy...
Heres the code:

Code: Select all

	<p:panelGrid columns="1">

		<f:facet name="header">
			<p:panelGrid columns="2" styleClass="ui-button-container"
				style="float: right;">

				<p:selectOneMenu value="#{cc.attrs.controller.selectedFilter}">
					<f:selectItem itemLabel="Selecione um filtro..." itemValue="" />
					<f:selectItems value="#{cc.attrs.controller.filters}" var="f"
						itemLabel="#{f.label}" itemValue="#{f.path}" />
				</p:selectOneMenu>

				<p:commandButton icon="ui-icon-circle-plus"
					actionListener="#{cc.attrs.controller.givePermission}"
					update=":filterForm" />
			</p:panelGrid>
		</f:facet>
	

	
	<pe:dynaForm id="dynaForm" value="#{cc.attrs.controller.dynaFormModel}" var="data">
               <!-- my fields here -->
	</pe:dynaForm>
	
			<f:facet name="footer">
			<p:panel styleClass="ui-button-container">

				<p:panel styleClass="ui-button-container" style="float: left;">
					<p:commandButton id="search" value="#{msg['button.search']}"
						icon="ui-icon-search"
						actionListener="#{cc.attrs.controller.addFiltersToSession}"
						update=":mainForm:datatable:table" />
					<p:commandButton id="new" value="#{msg['button.new']}"
						icon="ui-icon-document" action="#{cc.attrs.controller.getFormPath}"
						actionListener="#{cc.attrs.controller.insert}" ajax="false" />
				</p:panel>

				<p:panel styleClass="ui-button-container" style="float: right;">
					<h:commandLink>
						<p:graphicImage value="/resources/images/xls.png" />
						<p:dataExporter type="xls" target=":mainForm:datatable:table"
							fileName="#{cc.attrs.fileName}" />
					</h:commandLink>

					<h:commandLink>
						<p:graphicImage value="/resources/images/pdf.png" />
						<p:dataExporter type="pdf" target=":mainForm:datatable:table"
							fileName="#{cc.attrs.fileName}" />
					</h:commandLink>

					<h:commandLink>
						<p:graphicImage value="/resources/images/csv.png" />
						<p:dataExporter type="csv" target=":mainForm:datatable:table"
							fileName="#{cc.attrs.fileName}" />
					</h:commandLink>
				</p:panel>

			</p:panel>
		</f:facet>
	
	</p:panelGrid>
INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
INFO: Initializing Mojarra 2.1.10
INFO: Running on PrimeFaces 3.5
INFO: Running on PrimeFaces Extensions 0.6.1

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests