我想在 URL 中传递一些 ID,这些 ID 稍后将由支持 bean 读取。对于每个 ID,将遵循特定的操作。
fg URL: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 中的绑定替换值时,我得到了
Cannot convert javax.faces.component.UIViewParameter@ee2549 of type class javax.faces.component.UIViewParameter to class [Ljava.lang.String;
任何有关如何解决转换错误的想法将不胜感激!