checkbox selected in the table

UI Components for JSF
Post Reply
alexzipps
Posts: 1
Joined: 27 Dec 2011, 14:21

27 Dec 2011, 14:36

I want the value that is placed on the selected items will already mark the checkbox dataTable

Code: Select all

<h:form id="formPerfilTela" method="post">
		
	<h:panelGrid id="panelPerfilTela" columns="2" cellpadding="5">

							<h:outputLabel 		value="#{msg['sce.label.perfil']}" />
							<h:selectOneMenu 	id="Perfil"
												style="width:170px;"
												value="#{perfilTelaBean.perfilTela.perfil}"
												converter="simpleEntityConverter" 
												onchange="submit()"
												valueChangeListener="#{perfilTelaBean.pesquisaPerfilTela}"
												immediate="true" >

								<c:selectItem 	itemLabel="#{msg['sce.select.perfil']}"
												itemValue="" 
												noSelectionOption="true" />

								<c:selectItems 	value="#{perfilTelaBean.perfis}" 
												var="perfil"
												itemLabel="#{perfil.nomePerfil}" 
												itemValue="#{perfil}" />
								
							</h:selectOneMenu>

							<h:outputLabel 		value="#{msg['sce.label.telas.acessada.perfil']}" />

						</h:panelGrid>

						<fieldset>
							<legend>
								<h:outputLabel 	value="#{msg['sce.legend.telas.existentes']}" />
							</legend>
							
							<p:outputPanel autoUpdate="true" layout="block" id="panelTabela">
							
							<p:dataTable 		id="tblPerfilTela"
												value="#{perfilTelaBean.perfisTelas}"
												var="t"
												selection="#{perfilTelaBean.selecionados}"
												rowKey="#{t.tela.idTela}">
										
								<p:column headerText="#{msg['sce.selecionar']}" selectionMode="multiple" style="width:70px;text-align:center;">
									
								</p:column>

								<p:column >

									...

								</p:column>

							</p:dataTable>
							
							</p:outputPanel>
							
						</fieldset>

						<center>

							<h:panelGrid columns="2" cellspacing="10">

								<p:commandButton 	id="btnCadastrar" 
													styleClass="btnConfirm"
													value="#{msg['sce.button.incluir.alterar']}" 
													type="submit"
													ajax="false"
													actionListener="#{perfilTelaBean.incluiAltera}"
													update="formPerfilTela" />

							</h:panelGrid>
							
						</center>

					</h:form>
>>> When the "btnCadastrar" is clicked the checkbox are selected <<<

:?:

>> But in the event anything happens selectOneMenu <<

Code: Select all

 @ManagedBean
@RequestScoped
public class PerfilTelaBean extends AbstractBean {

public void pesquisaPerfilTela(ValueChangeEvent event) throws IOException, ServletException {
		
		Perfil perfil = (Perfil) event.getNewValue();
		
		if(perfil != null ){
			
			perfilTela		 = new PerfilTela();
			
			perfilTela.setPerfil(perfil);
			
			listaPerfilTelas = new ArrayList<PerfilTela>();
			
			listaPerfilTelas.clear();
			
			try {
				
				listaPerfilTelas = (List<PerfilTela>) perfilTelaService.searchPerfilTela( perfilTela );
				
				perfisTelas = new PerfilTelaDataModel(listaPerfilTelas);
				
				int occurs = 0;
				
				for(PerfilTela pt : perfisTelas)					
					if(pt.getTela().getSelecionada())
						occurs++;
				
				selecionados = new PerfilTela[occurs];
				
				occurs = 0;
				
				for(PerfilTela pt : perfisTelas)					
					if(pt.getTela().getSelecionada())
						selecionados[occurs++] = pt;
				
				
			} catch (BusinessException e) {
				
				log.info(e);

			} catch (Exception e) {

				log.error("Erro do Sistema", e);
				
			}
		}
	}

}
[img]
http://imageshack.us/photo/my-images/442/parte01.jpg/
[/img]

[img]
http://imageshack.us/photo/my-images/842/parte02w.jpg/
[/img]

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

27 Dec 2011, 19:46

1. Please see my signature below and respond with your test/development environment details like you see in my signature. That helps us/community respond to your question/posts.

2. If you are using PrimeFaces version 3.0+, then please see this Showcase Labs example (code is documented on the page), DataTable - RadioCheckbox.


3. If you are using PrimeFaces version 2.2+, then please see this Showcase example (code is documented on the page), DataTable - RadioCheckbox.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

03 Jan 2012, 19:04

The labs showcase is incomplete in that it does not show the need for a rowKey. If that is not there, selection does not happen at all. But the case described here seems to be a bug. I have the same behaviour with PF 3.0 final on JBoss 7.0.2 (Mojara 2.1.6). If your selection contains objects, the corresponding checkboxes are not checked.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests