Problem with dataTable + SelectOneMenu

UI Components for JSF
Post Reply
santima17
Posts: 3
Joined: 30 Jul 2010, 22:15

06 Dec 2010, 20:50

I have the next source in my page.

<p:dataTable
var="cupo"
value="#{visualizarCuposBean.cupos}"
paginator="true"
rows="10"
selection="#{visualizarCuposBean.cupoSeleccionado}"
selectionMode="single"
onRowSelectUpdate="display"
onRowSelectComplete="detalleCupo.show()"
id="tablaCupos"
....

.....
<p:column>
<f:facet name="header">
<h:outputText value="Acciones" />
</f:facet>
<h:selectOneMenu id="cmboxAccion" value="#{visualizarCuposBean.selectedAccion}" >
<f:selectItems value="#{cupo.acciones}" var="item" itemValue="#{item.value}" itemLabel="#{item.label}" />
</h:selectOneMenu>
<p:commandButton value="Ejecutar" action="#{visualizarCuposBean.ejecutarAccion}" />

</p:column>
</p:dataTable>

***cupos.acciones = private dtItemAccion[] acciones,
dtItemAccion have two atributtes, value and label.
-------------------------------------------------------------------------------------------------------------------------------------------
and the next source in my pageBean.

@ManagedBean(name="visualizarCuposBean")
@ViewScoped
public class visualizarCuposBean implements Serializable{

private List<dtCupo> cupos;
private dtCupo cupoSeleccionado = new dtCupo();
private String selectedAccion;
private interfaceBQB iBQB;

public visualizarCuposBean() {
this.iBQB = new interfaceBQB();
cupos = iBQB.listadoCuposWeb(); //this return my cupos list
}

public void ejecutarAccion(){
//assign new value to localeCode
FacesContext context = FacesContext.getCurrentInstance();
UIComponent cmboxAccion = findComponent(context.getViewRoot(), "cmboxAccion");
Map<String,Object> atributos = cmboxAccion.getAttributes();
String accionString = (String)atributos.get("value");
System.out.println("Accion:::"+accionString);
}

public dtCupo getCupoSeleccionado() {
return cupoSeleccionado;
}

public void setCupoSeleccionado(dtCupo cupoSeleccionado) {
this.cupoSeleccionado = cupoSeleccionado;
}

public List<dtCupo> getCupos() {
return cupos;
}

public void setCupos(List<dtCupo> cupos) {
this.cupos = cupos;
}

public String getSelectedAccion() {
return selectedAccion;
}

public void setSelectedAccion(String selectedAccion) {
this.selectedAccion = selectedAccion;
}

private UIComponent findComponent(UIComponent parent, String id){
if(id.equals(parent.getId())){
return parent;
}else{
Iterator<UIComponent> kids = parent.getFacetsAndChildren();
while(kids.hasNext()){
UIComponent kid = kids.next();
UIComponent found = findComponent(kid,id);
if (found != null){
return found;
}
}
return null;
}
}

}

in ejecutarAccion() i'm use findelement(), this function return properly the current selectOneMenu , but the value of this current select is always the first elemento of cupos.acciones.

Can you help my with this error?

I'm using primefacesRC2.2

Thank you
Santiago

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests