0

I have a datatable with primefaces, loaded about three records, it happens that I have in a column one inputText, it happens that the button is outside the datable record, and click the button I want to record, capture me inputText values​​, and to update records each dataTable.

    <p:dataTable id="dataTable" var="confParamGen" value="#{regRolMB.paramLdap}"
        rowIndexVar="rowIndex"> 
        <p:column>
            <f:facet name="header" >
                <h:outputText value="N°" />
            </f:facet>
            <h:outputText value="#{rowIndex+1}" />
        </p:column>
        <p:column>
            <f:facet name="header">
                <h:outputText value="Number Long" />
            </f:facet>
            <h:outputText value="#{confParamGen.numberCort}" />
        </p:column> 
        <p:column>
            <f:facet name="header">
                <h:outputText value="Value Role" />
            </f:facet>
            <p:inputText value="#{confParamGen.valuesRole}" style="width: 200px;" />
        </p:column> 
</p:dataTable>

<p:commandButton value="Save" rendered="#{regRolMB.showButtonUpdate}"
actionListener="#{regRolMB.actualizarRol}" styleClass="positionButton"> 
    <f:attribute name="confParamGen" value="#{confParamGen}" />
</p:commandButton>

In the controller I have it so, but it falls to cast the Arraylist.

public void updateRol(ActionEvent event) {
    List<DateGeneral> rolConPar = new ArrayList<DateGeneral>();
    rolConPar = ((ArrayList<DateGeneral>) event.getComponent().getAttributes().get("confParamGen"));
    for(DateGeneral dato: rolConPar){
        System.out.println("===> "+dato.getValuesRole());
    }
}   

I get this error, although the problem is not the modified data capture of inputText, only captures the data loaded from DataTable

java.lang.ClassCastException: com.bbva.sca.adm.bean.DatoGeneral cannot be cast to java.util.ArrayList
4

2 回答 2

2

The ClassCastException is being thrown because you've actually set an instance of DatoGeneral as attribute here:

<f:attribute name="confParamGen" value="#{confParamGen}" />

This is clearly not a List<DatoGeneral> (or List<DateGeneral> or whatever typo you made during careless oversimplifying/translating of the code; just use English all the time in code). Technically, you can solve it by passing the list itself instead:

<f:attribute name="confParamGen" value="#{regRolMB.paramLdap}" />

After all, this approach isn't making any sense. Your sole purpose seems to be just collecting the submitted values. In that case, you seem to be completely new to JSF and not yet fully understand why you're using JSF and what it is all capable of. JSF has already updated the model values with the submitted values. You just have to access the very same list behind <p:dataTable value> directly.

public void actualizarRol(ActionEvent event) {
    for(DateGeneral dato: paramLdap){
        System.out.println("===> "+dato.getValuesRole());
    }
}  

This way you can just get rid of the whole <f:attribute>.

于 2013-09-27T15:51:47.847 回答
0

My datatable load it like this:

public ArrayList<DatoGeneral> getParamLdap() {
    try{
        if(codSistema != null){             
            confParamGen = new ArrayList<DatoGeneral>();
            confParamGen = datoGeneralService.obtenerParamGen(sistema.getConfLdap().getCdCodigo());
        }
    }catch(Exception e){
        e.printStackTrace();
    }
    return (ArrayList<DatoGeneral>) confParamGen;
}
于 2013-09-27T17:26:50.120 回答