JSF 实体转换错误:丰富建议框转换错误设置值“*”对于“空转换器”

发布于 2024-12-01 01:09:02 字数 2983 浏览 2 评论 0原文

我正在使用rich:suggestionbox

  • 从建议框中选择建议
  • 然后保存我的表单
  • 它会引发验证错误,提示“null Converter”的“rich suggestbox Conversion Error”设置值“568-UNIMED-2005”。

帮助

  • 我需要有关我的代码有什么问题的
  • 吗?如何解决这个问题?

这是我的 LcInfo bean

@AutoCreate
@Scope(ScopeType.CONVERSATION)
@Name("lcInfo")
@Entity
@Table(name="lc_info")
public class LcInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer id;
    private ItemIndentMast itemIndentMastBean;

    public LcInfo() {
    }


    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    //bi-directional many-to-one association to ItemIndentMast
    @ManyToOne
    @JoinColumn(name="item_indent_mast", nullable=false)
    public ItemIndentMast getItemIndentMastBean() {
        return this.itemIndentMastBean;
    }

    public void setItemIndentMastBean(ItemIndentMast itemIndentMastBean) {
        this.itemIndentMastBean = itemIndentMastBean;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        return result;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null) return false;
        if (getClass() != object.getClass()) return false;
        LcInfo other = (LcInfo) object;
        return id.equals(other.id);
    }


}

这是我的带有 rich:suggestionbox 的 XHTML 源代码。

            <h:inputText value="#{lcInfo.itemIndentMastBean}" id="itemIndentMastBean" required="true"/>
            <rich:suggestionbox for="itemIndentMastBean"
                suggestionAction="#{lcInfoController.suggestion}"
                var="result" 
                fetchValue="#{result}"
                minChars="3"
                nothingLabel="No capitals found" >
                <f:facet name="header">
                    <h:outputText value="Select Indent Number" style="font-size: 10px; padding-left: 5px"/>
                </f:facet>
                <h:column>
                    <h:outputText value="#{result}" />
                </h:column>
            </rich:suggestionbox>                

这是控制器代码如何从控制器加载建议

@Name("lcInfoController")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
public class LcInfoController {


    public List<ItemIndentMast> suggestion(Object query) {
        String queryText = query.toString();
        if(StringUtils.isBlank(queryText) || queryText.length() < 3) {
            return Collections.emptyList();
        }

        return itemIndentMastService.filterIndent(queryText+"%");
    }

}

I am using rich:suggestionbox.

  • Select a suggestion from the suggestion box
  • Then save my form
  • It raises the validation error saying rich suggestionbox Conversion Error setting value '568-UNIMED-2005' for 'null Converter'.

I need help with

  • What is wrong with my code?
  • How to fix the issue?

Here is my LcInfo bean

@AutoCreate
@Scope(ScopeType.CONVERSATION)
@Name("lcInfo")
@Entity
@Table(name="lc_info")
public class LcInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer id;
    private ItemIndentMast itemIndentMastBean;

    public LcInfo() {
    }


    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    //bi-directional many-to-one association to ItemIndentMast
    @ManyToOne
    @JoinColumn(name="item_indent_mast", nullable=false)
    public ItemIndentMast getItemIndentMastBean() {
        return this.itemIndentMastBean;
    }

    public void setItemIndentMastBean(ItemIndentMast itemIndentMastBean) {
        this.itemIndentMastBean = itemIndentMastBean;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        return result;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null) return false;
        if (getClass() != object.getClass()) return false;
        LcInfo other = (LcInfo) object;
        return id.equals(other.id);
    }


}

Here is my XHTML source with a rich:suggestionbox.

            <h:inputText value="#{lcInfo.itemIndentMastBean}" id="itemIndentMastBean" required="true"/>
            <rich:suggestionbox for="itemIndentMastBean"
                suggestionAction="#{lcInfoController.suggestion}"
                var="result" 
                fetchValue="#{result}"
                minChars="3"
                nothingLabel="No capitals found" >
                <f:facet name="header">
                    <h:outputText value="Select Indent Number" style="font-size: 10px; padding-left: 5px"/>
                </f:facet>
                <h:column>
                    <h:outputText value="#{result}" />
                </h:column>
            </rich:suggestionbox>                

Here is the controller code how suggestions are loaded from controller

@Name("lcInfoController")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
public class LcInfoController {


    public List<ItemIndentMast> suggestion(Object query) {
        String queryText = query.toString();
        if(StringUtils.isBlank(queryText) || queryText.length() < 3) {
            return Collections.emptyList();
        }

        return itemIndentMastService.filterIndent(queryText+"%");
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你搞怪i 2024-12-08 01:09:02

这就是我最后想到的: Seam:创建自定义转换器

This is what I came up with in the end: Seam: Creating a custom converter

奢华的一滴泪 2024-12-08 01:09:02

使输入接收字符串值而不是 bean :
更改

value="#{lcInfo.itemIndentMastBean}",

  value="#{lcInfo.someString}",

JSF 不知道如何处理您的 ItemIndentMast BEAN。
或者,您可以为该 bean 创建一个转换器(将字符串转换为 bean)
http://www.javabeat.net/tips/70 -create-simple-custom-converter-implementation.html

make the input recieve a string value and not a bean :
change

value="#{lcInfo.itemIndentMastBean}",

to

  value="#{lcInfo.someString}",

JSF does not know how handle your ItemIndentMast BEAN.
alternatevly you can create a converter for that bean (convert string to bean)
http://www.javabeat.net/tips/70-create-simple-custom-converter-implementation.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文