在支持 bean 操作方法中调用 JOptionPane.showMessageDialog 时出现 java.awt.HeadlessException
我正在尝试以下操作:
labelconfig.xhtml
:
<h:form id="ok">
<h:commandButton value="click">
<f:ajax event="click" listener="#{canvasController.oeps}" />
</h:commandButton>
</h:form>
我试图在这里获取它:
CanvasController.java
@ManagedBean(name = "canvasController")
@SessionScoped
public class CanvasController
public void oeps(AjaxBehaviorEvent event) {
JOptionPane.showMessageDialog(null, "SUCCES3");
}
}
但是当我单击按钮时,我得到:
服务器错误:类java.awt.HeadlessException
这是如何引起的以及如何解决它?
I'm trying the following:
labelconfig.xhtml
:
<h:form id="ok">
<h:commandButton value="click">
<f:ajax event="click" listener="#{canvasController.oeps}" />
</h:commandButton>
</h:form>
And I'm trying to get it here:
CanvasController.java
@ManagedBean(name = "canvasController")
@SessionScoped
public class CanvasController
public void oeps(AjaxBehaviorEvent event) {
JOptionPane.showMessageDialog(null, "SUCCES3");
}
}
But when I click the button, I get:
serverError: class java.awt.HeadlessException
How is this caused and how can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正尝试在没有任何桌面 GUI 的情况下从服务器应用程序调用 Swing。使用 logger 或 FacesContext.addMessage 代替 JOptionPane 来获取反馈。如果由于某种原因您确实想通过 JSF 控制 Swing 应用程序,请确保设置了 DISPLAY 等,但我建议重新表述您的问题。
You are trying to call Swing from server application without any desktop GUI. Instead of JOptionPane use logger or FacesContext.addMessage to get feedback. If for some reason you do want to control Swing app through JSF make sure DISPLAY etc are set but then I suggest rephrasing your question.