【发布时间】:2011-08-22 04:04:42
【问题描述】:
这里有几点:
- 我有一个 primefaces 自动完成示例,它使用带有自定义转换器的 POJO。
- 我正在为转换器中的 getAsString 返回一个 UUID 字符串。
- 如果我通过键盘或鼠标单击从自动完成下拉对话框中选择值,则转换器的字符串值可以正常发送。
- 但是当我自己键入值而不从自动完成下拉对话框中选择,或者只是将值粘贴到文本字段中时,验证错误:需要值。会发生错误。
- 我注意到这个错误的发生是因为发送到服务器端的值不是我的转换器生成的字符串,而是自己键入的值。
使用 firebug 显示了这一点。
这是当我通过键盘或鼠标单击从自动完成下拉对话框中选择值时,我们可以注意到该值是 UUID 格式,由我的 pojo 转换器返回:
<input aria-haspopup="true" aria-autocomplete="list" role="textbox"
autocomplete="off" id="DetailDialogForm:Bagian_input"
name="DetailDialogForm:Bagian_input" value="PERSO"
class="ui-inputfield ui-widget ui-state-default ui-corner-all ui-autocomplete-input"
type="text">
<input id="DetailDialogForm:Bagian_hinput"
name="DetailDialogForm:Bagian_hinput"
value="b0019ab2-28c3-451a-90f6-62a6941ffcaa" type="hidden">
这是当我输入或粘贴值时,我们可以注意到该值正是我输入的,我的 pojo 转换器没有返回:
<input aria-haspopup="true" aria-autocomplete="list"
role="textbox" autocomplete="off" id="DetailDialogForm:Bagian_input"
name="DetailDialogForm:Bagian_input" value="PERSO"
class="ui-inputfield ui-widget ui-state-default ui-corner-all ui-autocomplete-input"
type="text">
<input id="DetailDialogForm:Bagian_hinput"
name="DetailDialogForm:Bagian_hinput" value="PERSO" type="hidden">
这是该元素的预期行为吗?
我使用的是 tomcat 7,这些是我的依赖项:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
请分享你的想法,谢谢!
更新
这是 JSF 节选:
<p:autoComplete id="Bagian" label="Bagian yang di limpahkan"
value="#{tInputBean.activeDetail.map['department']}"
completeMethod="#{tInputBean.filterDepartment}" var="department"
itemLabel="#{department.map['departmentName']}"
itemValue="#{department}" converter="genericConverter"
forceSelection="true" required="true" />
转换器可在this page 获得,在 BalusC 对 EntityConverter 的回答中
【问题讨论】:
标签: jsf jsf-2 primefaces