JSF 2.0;自定义数据类型类的“参数类型不匹配”?

时间:2012-04-11 12:10:50

标签: jsf-2 illegalargumentexception

我将为输入字段创建自定义数据类型。 (见“金额”)。 在inputfield“amountId”中设置值确实很有效。但是,如果我想提交表单并转到另一个页面,那么我就有“参数类型不匹配”的例外。

有人可以解释一下,为什么我会得到这个例外?

  • 我是否需要转换器将输入值转换为字符串?
  • 我忘记了我的Amount类中要实现的一些方法,JSF需要获取这些值吗?

这是我的代码:

public class Amount implements Serializable {
    public Amount(BigDecimal bd){
    }

    public Amount(String s) {
    }

    @Override
    public String toString() {
    }
}



@ManagedBean(name="myBean")
    @RequestScoped
    public class MyBean extends BaseBean {
        private Amount amountValue;
        private UIInput amountValueId;

        public Amount getAmountValue() {
            return amountValue;
        }

        public void setAmountValue(Amount amountValue) {
            this.amountValue = amountValue;
            if (this.amountValueId != null)
                this.amountValueId.setSubmittedValue(amountValue);
        }

        public UIInput getAmountValueIdId() {
            return amountValueId;
        }

        public void setAmountValueId(UIInput amountValueId) {
            this.amountValueId = amountValueId
        }
    }



<h:inputText id="amountValueId" binding="#{myBean.amountValueId}" size="30" value="#{myBean.amountValue}" />




javax.servlet.ServletException: javax.el.ELException: java.lang.IllegalArgumentException: argument type mismatch
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:229)
    org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)


org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: java.lang.IllegalArgumentException: argument type mismatch
    org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.setValue(ContextAwareTagValueExpression.java:166)
    javax.faces.component.UIInput.updateModel(UIInput.java:406)
    javax.faces.component.UIInput.processUpdates(UIInput.java:328)
    javax.faces.component.UIForm.processUpdates(UIForm.java:263)
    javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1469)
    javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1469)
    javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1469)
    javax.faces.component.UIViewRoot._processUpdatesDefault(UIViewRoot.java:1397)
    javax.faces.component.UIViewRoot.access$600(UIViewRoot.java:74)
    javax.faces.component.UIViewRoot$UpdateModelPhaseProcessor.process(UIViewRoot.java:1535)
    javax.faces.component.UIViewRoot._process(UIViewRoot.java:1358)
    javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:806)
    org.apache.myfaces.lifecycle.UpdateModelValuesExecutor.execute(UpdateModelValuesExecutor.java:38)
    org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
    org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
    org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)

1 个答案:

答案 0 :(得分:3)

我认为您应该在<h:inputText添加转换器,看看此Custom converter in JSF 2.0因为您尝试将String提交到Amount对象