'null Converter'的转换错误设置值'948'

时间:2013-03-27 08:57:17

标签: jsf-2 ejb

我想在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()));
            }
        }

    }
}

acceped.xhtml:

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

当我尝试用.xhtml中的绑定替换 value 时我得到了

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

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

1 个答案:

答案 0 :(得分:0)

<f:viewParam>不支持多个参数值。去掉它。在这种特殊情况下你不需要它。您已经设置了@ManagedProperty("#{paramValues.acceptMsg}")

另见:


对具体问题

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