1

我将为我的输入字段创建一个自定义数据类型。(见分类“金额”)。在输入字段“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)
4

1 回答 1

3

我认为您应该添加转换器来查看JSF 2.0<h:inputText中的这个自定义转换器,因为您尝试提交到对象StringAmount

于 2012-04-11T12:48:28.880 回答