繁体   English   中英

JSF:java.lang.IllegalArgumentException:无法解析参数编号

[英]JSF : java.lang.IllegalArgumentException: can't parse argument number

有人可以帮我弄清楚我刚接触JSF的问题。 我已经用Primefaces构建了一个Spring WebMVC App。 这个应用程序包含可以拖到spreadSheet中的节点列表(我正在使用SpreadJS)。 每个节点后面都有一个模型和一个bean。 Evey节点具有名称和输入类型。 我需要在spreadSheet中进行节点值与其值之间的同步,反之亦然。 因此,在每个changeEvent中,我都调用一个remoteCommand,并将五个参数传递给我的ManagedBean。 问题是每当我加载页面时出现此错误:这是我的代码:

@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @ManagedProperty("#{param.nodeId}")
    private String nodeId;
    @ManagedProperty("#{param.paramId}")
    private String paramId;
    @ManagedProperty("#{param.row}")
    private int row;
    @ManagedProperty("#{param.cel}")
    private int cel;
    @ManagedProperty("#{param.value}")
    private String value;

    public String getNodeId() {
        return nodeId;
    }

    public void setNodeId(String nodeId) {
        this.nodeId = nodeId;
    }

    public String getParamId() {
        return paramId;
    }

    public void setParamId(String paramId) {
        this.paramId = paramId;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public int getCel() {
        return cel;
    }

    public void setCel(int cel) {
        this.cel = cel;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public void execCmd() {
        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        String nodeId = params.get("nodeId");
    }

和我的xhtml文件看起来像:

<h:body>
    <div class="container">
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-6">
                <h:form id="myForm">
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="inputEmail4">Test Submit Value</label>
                            <h:inputText name="text1" id="text1" value="#{helloBean.value}" >
                            </h:inputText>
                        </div>
                    </div>
                    <p:remoteCommand name="callRemoteMethod" actionListener="#{helloBean.execCmd()}" />
                </h:form>
            </div>
            <div class="col-lg-6 col-md-6 col-sm-6">
                <div name="right_frame" id="ss" style="height: 600px; width: 100%;"></div>
            </div>
        </div>
    </div>
    <h:form>
        <br />

    </h:form>

</h:body>
<script type="text/javascript">
       var nodeId = null;
       var paramId = null;
       var row = null;
       var cell= null;
       var value = null; 
       var spread; 
        window.onload = function() {
            spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
            var sheet = spread.getActiveSheet();
                        sheet.setValue(0, 1,    123, GC.Spread.Sheets.SheetArea.viewport);
                        sheet.bind(GC.Spread.Sheets.Events.CellChanged , function (e, args) {
                            if (args.propertyName === "value") {
                                if(sheet.getTag(0,1) != null){
                                    var obj = JSON.parse(sheet.getTag(0,1));
                                    nodeId = obj.nodeId;
                                    paramId = obj.paramId;
                                    row = args.row;
                                    cell = args.col;
                                    callRemoteMethod({name: 'nodeId', value: ""}, {name: 'paramId', value: ""}, {name: 'row', value: 1}, {name: 'cel', value: 1}, {name: 'value', value: "Test"}]);
                                }                                   
                            }
                            });
        };

    </script>
</html>

这是堆栈跟踪:

  Caused by: java.lang.IllegalArgumentException: can't parse argument number: param.nodeId
    at java.text.MessageFormat.makeFormat(MessageFormat.java:1420)
    at java.text.MessageFormat.applyPattern(MessageFormat.java:479)
    at java.text.MessageFormat.<init>(MessageFormat.java:363)
    at java.text.MessageFormat.format(MessageFormat.java:835)
    at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:396)
    at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:604)
    at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:553)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
    ... 49 more
Caused by: java.lang.NumberFormatException: For input string: "param.nodeId"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.parseInt(Integer.java:527)
    at java.text.MessageFormat.makeFormat(MessageFormat.java:1418)
    ... 57 more

任何帮助?

您正在将Integer的值设置为String变量,如异常所示

java.lang.NumberFormatException:对于输入字符串:“ param.nodeId”

nodeId变量应为Integer变量。

您可以使用toString()方法解析Integer

我制作了@ManagedProperty(“#{nodeId}”)而不是@ManagedProperty(“#{param.nodeId}”),它可以工作:

@ManagedProperty("#{nodeId}") 
private String nodeId; 
@ManagedProperty("#{paramId}") 
private String paramId; 
@ManagedProperty("#{row}") 
private int row; 
@ManagedProperty("#{cel}") 
private int cel; 
@ManagedProperty("#{value}")
private String value; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM