Dynamic DataTable and selectOneMenu
gribeiro May 12, 2010 2:04 PMHi, everyone !
I´ve just started studying Seam abouth a month ago and there are so many doubts in my mind ...
Well,I´m trying to select an item on a combo and using ajax to render a datatable with object attribute´s value.
So, here below some code snippets to clarify the situation:
Managed Bean
@Name("funcionarioBean")
@Scope(ScopeType.CONVERSATION)
public class FuncionarioBeanImpl extends
GenericCrudBackingBeanImpl<Funcionario> implements FuncionarioBean {
@In(create = true)
private FuncionarioBusiness funcionarioBusiness;
@In(create = true)
private CargoBusiness cargoBusiness;
@DataModel(value = "funcionarios")
private List<Funcionario> funcionarios;
// @DataModelSelection(value = "funcionarios")
@Out(required = false)
private Funcionario funcionario;
@DataModel
private List<Cargo> cargosselec;
@DataModelSelection(value = "listaDeCargos")
// @Out(required = false)
private Cargo cargoselec;
@DataModel
private List<Cargo> listaDeCargos;
@Factory(value = "listaDeCargos")
public List<Cargo> getLista() {
return this.listaDeCargos = cargoBusiness.listarTodos();
}
@Begin(nested = true)
public void processMyValueChange(ValueChangeEvent vce){
//FIXME Descobrir porque o cargosselec está sendo instanciado toda vez que chamo este método !!!
cargoselec = (Cargo) vce.getNewValue();
//setSongDetail((Cargo)detail.get(cargoselec));
//System.out.println("Cargo Selecionado :"+cargoselec.getDescricao());
if (cargosselec==null) {
cargosselec = new ArrayList<Cargo>();
cargosselec.add(cargoselec);
System.out.println("Cargo adicionado =>"+ "Código :"+cargoselec.getId()+ "Descrição :"+cargoselec.getDescricao());
System.out.println("Tamanho da lista de cargos selecionados :"+cargosselec.size());
} else {
cargosselec.add(cargoselec);
System.out.println("Cargo adicionado =>"+ "Código :"+cargoselec.getId()+ "Descrição :"+cargoselec.getDescricao());
System.out.println("Tamanho da lista de cargos selecionados :"+cargosselec.size());
}
}
XHTML PAGE
<s:decorate id="comboCargos">
<ui:define name="label">
<h:outputLabel value="Cargos" />
</ui:define>
<h:selectOneMenu value="#{cargoselec}" valueChangeListener="#{funcionarioBean.processMyValueChange}" >
<s:selectItems value="#{listaDeCargos}" var="cargos"
label="#{cargos.descricao}" hideNoSelectionLabel="true"
noSelectionLabel=" Selecione..." />
<a:support event="onchange" reRender="tabelaCargos" onsubmit="if(!confirm('Confirma o cargo selecionado ?')) {form.reset(); return false;}"/>
<s:convertEntity />
</h:selectOneMenu>
</s:decorate>
<ui:define name="tituloDatagrid">
<h:outputLabel value="Dados Profissionais" />
</ui:define>
<ui:define name="tabelaDataGrid">
<h:dataTable id="tabelaCargos" value="#{cargosselec}" var="crgsel"
rendered="#{cargosselec.size > 0}">
<h:column>
<f:facet name="header">
<h:outputLabel value="Codigo" />
</f:facet>
<h:outputText value="#{crgsel.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Descricao" />
</f:facet>
<s:link value="#{crgsel.descricao}"
action="#{funcionarioBean.editar(funcionario)}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Acao" />
</f:facet>
<h:commandLink action="#{cargoBean.deletar(cargo)}"
onclick="return confirmDelete()">
<h:graphicImage value="/_images/false.png" style="border: none" />
<a:support event="oncomplete" reRender="tabelaCargos" />
</h:commandLink>
</h:column>
</h:dataTable>
</ui:define>
At this pont I can add to cargosselect attribute each selected item from my combobox, but It´s not start rendering the datatable as expected.
Please, if anyone could help me out on this I´d be very grateful.
Gribeiro