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;
}
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" />
Code: Select all
<p:commandButton icon="ui-icon-circle-minus"
actionListener="#{cc.attrs.controller.forbidPermission(data.path)}"
update=":filterForm" disabled="#{data.defaultField}" />
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()
Another thing...
The filter component looks like this:
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>