【问题标题】:Autocomplete not sending the right converter value if typed manually如果手动输入,自动完成不会发送正确的转换器值
【发布时间】:2011-08-22 04:04:42
【问题描述】:

这里有几点:

  1. 我有一个 primefaces 自动完成示例,它使用带有自定义转换器的 POJO。
  2. 我正在为转换器中的 getAsString 返回一个 UUID 字符串。
  3. 如果我通过键盘或鼠标单击从自动完成下拉对话框中选择值,则转换器的字符串值可以正常发送。
  4. 但是当我自己键入值而不从自动完成下拉对话框中选择,或者只是将值粘贴到文本字段中时,验证错误:需要值。会发生错误。
  5. 我注意到这个错误的发生是因为发送到服务器端的值不是我的转换器生成的字符串,而是自己键入的值。

使用 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


    【解决方案1】:

    你能发布你的 .xhtml,我需要检查

    请检查:

    1. 你是否添加了 属性 forceSelection
    2. 当用户在 autoComplete 给出的建议列表上进行选择时,它应该使用 selectListener,并使用 onSelectUpdate 更新部分视图

    3. 检查里面是否有,尝试删除

    【讨论】:

    • 感谢您的回复。我已经更新了我原来的帖子。但简而言之,#1:是的,#2:我从自动完成中选择后不会尝试更新任何内容,#3:no p:ajax
    猜你喜欢
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 2017-11-28
    • 2018-01-25
    • 2013-07-18
    相关资源
    最近更新 更多