java.lang.IllegalArgumentException:无法将类型类java.lang.String的45转换为类[I

时间:2016-10-10 09:39:28

标签: jsf primefaces celleditorlistener

我的豆
 @ManagedBean  @ViewScoped

public class OpenJobOrderBean implements Serializable {

private static final long serialVersionUID = 1L;
private List<OpenJobOrderBean> smtOrder;
private int[] quantity;
private String department;
private String materialName;
private int materialQuantity;

public int[] getQuantity() {
    return quantity;
}

public void setQuantity(int[] quantity) {
    this.quantity = quantity;
}

public List<OpenJobOrderBean> getSmtOrder() {
    try {
        this.smtOrder = new OpenJobOrder().retrieveSMTMaterials();
    } catch (Exception e) {
        e.printStackTrace();
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "", e.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    return smtOrder;
}

public void setSmtOrder(List<OpenJobOrderBean> smtOrder) {
    this.smtOrder = smtOrder;

}
}

<p:dataTable editable="true" editMode="cell" rendered="#{openJobOrderBean.department == 4}" id="qty" selection="#{openJobOrderBean.selectedMaterials}"  rowKey="#{openJobOrderBean.materialId}"
             rows="5" var="openJob" value="#{openJobOrderBean.smtOrder}" paginator="true" paginatorPosition="bottom"
             paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             rowsPerPageTemplate="5,10,15" widgetVar="theWidget"  > 
    <p:growl id="msgs" showDetail="true"/>
    <f:facet name="header">
        <h3>
            Raw Materials for SMT
        </h3>
    </f:facet>

    <p:ajax event="cellEdit" listener="#{openJobOrderBean.onCellEdit}" oncomplete="onCellEdit()" update=":mainform:msgs" />
    <p:column selectionMode="multiple" style="text-align: center; width: 80px" headerText="Select Requested Materials" />

    <p:column id="tmp" headerText="Quantity Requested(click to edit)" style="width: 150px; text-align: center" >

        <p:cellEditor>
            <f:facet name="output"> 
                <h:outputText value="#{openJob.quantity}" id="output"  />  
            </f:facet>

            <f:facet name="input">  
                <p:inputText id="modelInput" value="#{openJob.quantity}" required="true" immediate="true" style="width:96%" rendered="true" >
                    <p:ajax event="keyup" update="output" />
                </p:inputText> 
            </f:facet> 
        </p:cellEditor>
    </p:column>

    <p:column headerText="Material Name" sortBy="#{openJob.materialName}" filterBy="#{openJob.materialName}" style="width: 200px " >
        <h:outputText value="#{openJob.materialName}" />
    </p:column>
    <p:column headerText="Available Quantity" >
        <h:outputText value="#{openJob.materialQuantity}" />
    </p:column>

    <f:facet name="footer">
        <p:commandButton oncomplete="PF('multimaterials').show()" value="Show" process="qty" update=":mainform:materialdetails" icon="ui-icon-check" /> 
    </f:facet>
</p:dataTable>

实体这是实体

    public List<OpenJobOrderBean> retrieveSMTMaterials() throws Exception {

    List<OpenJobOrderBean> open = new ArrayList<>();
    Connection connection = new DbConnection().getConnection();
    // String query = String.format("Select * from RawMaterialsSMT");
    PreparedStatement prs = connection.prepareStatement("select * from availablematerial where DepartmentId = 101");
    ResultSet res = prs.executeQuery();
    while (res.next()) {
        OpenJobOrderBean opjo = new OpenJobOrderBean();
        opjo.setMaterialName(res.getString("MaterialName"));
        opjo.setMaterialQuantity(res.getInt("Quantity"));
        opjo.setItemType(res.getString("ItemType"));
        opjo.setMaterialUnit(res.getString("MaterialUnit"));
        opjo.setSerialNo(res.getString("SerialNum"));
        opjo.setMaterialId(res.getInt("MaterialId"));
        open.add(opjo);
    }
    if (res != null) {
        res.close();
    }
    if (prs != null) {
        prs.close();
    }
    if (connection != null) {
        connection.close();
    }
    return open;

}

如果我有这个例外我该怎么办?

Caused by: java.lang.IllegalArgumentException: Cannot convert 45 of type class java.lang.String to class [I
    at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:424)
    at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:382)
    at com.sun.el.parser.AstValue.setValue(AstValue.java:248)
    at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
    at javax.faces.component.UIInput.updateModel(UIInput.java:832)
    ... 55 more

0 个答案:

没有答案