简体   繁体   中英

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

Can someone help me figure out the problem i'm new on JSF. I have built a Spring WebMVC App with Primefaces. This app contains a list of nodes which can be dragged into the spreadSheet (I m working with SpreadJS). Behind each node there is a model and a bean. Evey node has a name and an input type. I need to do the synchronization between the node value and its value in the spreadSheet and aim-versa. So in every changeEvent i call a remoteCommand and i pass five parameters to my managedBean. The problem is whenever i load my page and i get this error : here is my code :

@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");
    }

and my xhtml file look like :

<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>

and this is the Stack Trace :

  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

any help ??

You are setting a value of an Integer to a String variable as the exception says

java.lang.NumberFormatException: For input string: "param.nodeId"

The nodeId variable should be an Integer variable .

OR You can parse the Integer value using toString() method

Instead of @ManagedProperty ("# {param.nodeId}"), I made @ManagedProperty ("# {nodeId}") and it works:

@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; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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