【问题标题】:Conversion Error setting value '948' for 'null Converter''null Converter' 的转换错误设置值'948'
【发布时间】:2013-03-17 07:15:36
【问题描述】:

我想在 URL 中传递一些 ID,这些 ID 稍后将由支持 bean 读取。对于每个 ID,将遵循特定的操作。

F.g.网址:localhost:8585/monit/accepted.jsf?acceptMsg=948&acceptMsg=764

豆子:

@ManagedBean
@RequestScoped
public class AcceptedBean {
    @EJB
    private MessageService messageService;

    @ManagedProperty("#{paramValues.acceptMsg}")
    private String[] acceptMsg;

    public String[] getAcceptMsg() {
        return acceptMsg;
    }

    public List<Message> getMessages() {
        return messageService.getAcceptedMessages();
    }

    public void setAcceptMsg(String[] acceptMsgs) {
        this.acceptMsg = acceptMsgs;

        if(acceptMsg != null) {
            try {
                for (String accept: acceptMsg) {
                    final Message o = messageService.find(Integer.parseInt(accept));

                    messageService.accept(o);

                    FacesContext.getCurrentInstance().
                            addMessage(null,
                                    new FacesMessage(FacesMessage.SEVERITY_INFO,
                                            "Message was accepted:", o.getSubject()));
                }

            } catch (Exception e) {
                FacesContext.getCurrentInstance().
                        addMessage(null,
                                new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                        "Error:", e.getMessage()));
            }
        }

    }
}

接受.xhtml:

....
<f:metadata>
    <f:viewParam name="acceptMsg" value="#{acceptedBean.acceptMsg}" />
</f:metadata>
....

当我尝试在 .xhtml 中用 binding 替换 value 时,我得到了

Cannot convert javax.faces.component.UIViewParameter@ee2549 of type class javax.faces.component.UIViewParameter to class [Ljava.lang.String;

任何关于如何解决转换错误的想法都将不胜感激!

【问题讨论】:

  • 不应该是localhost:8585/monit/accepted.jsf?acceptMsg[]=948&amp;acceptMsg[]=764和ManagedBean中的@ManagedProperty("#{param.acceptMsg}")吗?
  • 感谢您的想法,但没有帮助。

标签: jsf-2 ejb


【解决方案1】:

&lt;f:viewParam&gt; 不支持多个参数值。去掉它。在这种特殊情况下,您不需要它。您已经有一个 @ManagedProperty("#{paramValues.acceptMsg}") 已经设置了它们。

另见:


与具体问题无关,我只会用@PostConstruct 方法替换setter 中的业务工作。原则上,getter/setter 不应该做任何其他事情,只是获取或设置属性,这表明设计不佳,因为它们只是访问点,并且可以在每个请求的基础上多次调用。

【讨论】:

    猜你喜欢
    • 2012-10-31
    • 1970-01-01
    • 2012-10-22
    • 2021-05-12
    • 1970-01-01
    • 2011-09-23
    • 2012-06-06
    • 2011-10-31
    • 2017-09-01
    相关资源
    最近更新 更多