- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 setPropertyActionListener 设置枚举属性,但我不知道该怎么做。这是实体:
@Entity
public class Invoice {
public enum InvoiceStatus { ACTIVE, CANCELED }
...
@Enumerated(EnumType.STRING)
private InvoiceStatus status;
...
public InvoiceStatus getStatus() {
return status;
}
public void setStatus(InvoiceStatus status) {
this.status = status;
}
这是命令按钮,它应该使用 setPropertyActionListener 将状态设置为 ACTIVE
...
<h:form id="invoiceCreatedSuccessfully">
<p:dialog header="#{msg['title.success']}" widgetVar="invoiceCreatedSuccessfullyDialog" resizable="false" showEffect="fade" hideEffect="fade">
<h:panelGrid columns="2" rows="3" style="margin-bottom: 10px">
<h:outputText value="#{msg['message.invoiceCreatedSuccessfully']}" />
</h:panelGrid>
<p:commandButton value="#{msg['label.acknowledged']}" actionListener="#{invoiceManager.reload}" action="viewInvoices">
<f:setPropertyActionListener target="#{invoiceManager.invoice.status}" value="ACTIVE" />
</p:commandButton>
</p:dialog>
</h:form>
未报告任何错误,但未设置数据库中的“状态”字段。谁能告诉我为什么?
最佳答案
EL 中的字符串不会直接转换为枚举,您需要在
faces-config 中进行自定义转换,jsf 有一个适合您的枚举转换器,
<converter>
<converter-for-class>java.lang.Enum</converter-for-class>
<converter-class>javax.faces.convert.EnumConverter</converter-class>
</converter>
现在查看 EnumConverter 的源代码,似乎只有当 targetClass 在转换器中可用时它才有效。
因此您需要扩展它以与您的枚举一起使用,
public class MyEnumConverter extends EnumConverter {
public MyEnumConverter () {
super(MyEnum.class);
}
}
<converter>
<converter-id>MyEnum</converter-id>
<converter-class>com.test.MyEnumConverter</converter-class>
</converter>
添加<f:converter converterId="MyEnum"/>
在您的组件中。
如果您有很多枚举并且为了让事情变得简单,您可以查看omnifaces http://showcase.omnifaces.org/converters/GenericEnumConverter
关于java - 使用 setPropertyActionListener 设置 ENUM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15571980/
我正在尝试移动 p:dialog出h:form ,因为我已经读到这是首选方式(但是我想了解原因,因为我在 p:dialog 中的 form 在我的应用程序中运行良好)。 唯一的困难是对话框标题需要动态
我的 jsf 2.1 页面上有以下 primefaces 按钮: 在应用程序的另一点,我读取了值 ... ... 现在重点是读取按预期工
我使用的数据表有两列,其中有一个标签和一个 selectOneMenu。 我需要动态显示 selectOneMenu 列表,为此我需要在 bean 中设置级别 id。在 commandbutton/c
基本上我正在尝试为 设置动态列. 我的一个专栏的内容是p:commandLink它曾经显示用于文本编辑的对话框,我在 XHTML 中的工作就像一个魅力,但我需要将它转换为 Java 以实现动态用户自
我正在尝试使用 setPropertyActionListener 设置枚举属性,但我不知道该怎么做。这是实体: @Entity public class Invoice { public e
PrimeFaces 和 GAE 的结合再次让我发疯。内部 p:dataTable我想单击一个图像,调用一个 bean 方法并设置一个参数。方法被调用,但参数不起作用。这是一个简化的示例(没有表格):
我想在单击表格行时传递值: 我收到此错误: Parent is not of type ActionSource, type is: javax.faces.component.htm
我似乎无法让 View 范围的托管 bean 与 setPropertyActionListener 一起使用: 如果 companyHolder 是
我正在尝试将当前迭代的 使用 作为托管 bean 的属性.但是,它始终设置为 null . View ,dentistas.xhtml :
从 primefaces 3.0.M3 升级到 3.0.M4-SNAPSHOT 时出现此错误 @60,114 Parent is not of type ActionSource, type is:
我有一个用普通旧式 JSF 编写的 Web 应用程序,我想将其部分迁移到 ICEfaces 以使用它的一些组件,即现在的确认面板。为了使用它,我更改了我的表单,其中包含需要确认从 h: 到ice: 标
你能告诉我如何在 jsf 中使用 Primefaces 为程序化菜单添加 f:setPropertyActionListener public MenuBean() { model
我有一个基于 LazyDataModel 的 Primefaces DataTable。我成功地在表中加载数据,但无法使用 setPropertyActionListener 在对话框中显示所选项目,
我正在尝试创建一个接收链接并添加样式类的自定义组件。 在原始链接中,用户可能有 f:setPropertyActionListener不止一次。 我不想为每个创建 propertyActionList
在 JSF2 中我想设置一些整数值。 例如: 如何从 javascript 命令设置整数值: PrimeFaces.widgets["widgerVarValue"].paginator.getCu
它的作用 我有一个使用 PrimeFaces 3.1.1 的网络应用程序。该应用程序的目的是提供一种更加用户友好的方式来遍历我们拥有的 XML 聚合器。它最初是用 SCALA 编写的,但现在我用 Ja
我可以使用 吗?在自动完成组件中? 自动完成使用托管 bean mbAC例如,我想发送 cliCod从它到另一个 bean: 是这样做的正确方法是什么? 最佳答案 仅在实现 ActionSourc
我希望当用户单击按钮时会发生两件事: 首先触发 setPropertyActionListener,以更新我的 bean 的属性 然后进行 ajax 调用以执行 bean 中的方法 看来我必须在 f:
我在数据表中有一个 fileDownload 组件,但是当我单击它时,似乎在 setPropertyActionListener 设置 datlis.filepath 变量之前调用了 filedown
我想在我的 commandLink 中嵌套多个 setPropertyActionListener,但只有一个有效。你如何尝试这个?此命令链接设置属性,然后打开一个对话框,以便它基本上初始化对话框。
我是一名优秀的程序员,十分优秀!