Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF:转换错误设置值'&书信电报;一些字符串>';对于';空转换器';_Jsf_Jsf 2 - Fatal编程技术网

JSF:转换错误设置值'&书信电报;一些字符串>';对于';空转换器';

JSF:转换错误设置值'&书信电报;一些字符串>';对于';空转换器';,jsf,jsf-2,Jsf,Jsf 2,对于我认为非常简单的场景,我得到了空转换器错误: <!-- My View --> <ui:composition template="/template/template_v1.xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.su

对于我认为非常简单的场景,我得到了空转换器错误:

<!-- My View -->
<ui:composition template="/template/template_v1.xhtml"
            xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html">
<!-- Simplified for clarity -->    
<h:form>
    <div class="block-panel customer-data">
        <h:outputLabel for="txtUsername">Username:</h:outputLabel>
        <h:inputText id="txtUsername" name="Username" 
                     value="#{userBean.user.id}"
                     styleClass="text" />
        <rich:message id="errorUsername" for="txtUsername"/>
    </div>
    <!--  Other fields omitted for clarity  -->
</h:form>
} 然后对我的视图进行必要的更改,以绑定到tmpId而不是id,一切正常

对我来说,这似乎是一个bug,与我绑定到接口中定义的getter/setter、泛型接口中定义的getter/setter或者因为getter用Id属性标记有关。不过,我会很感激其他人的想法


顺便说一句,我继承了这个设计,并不特别喜欢它,所以我可能会重构它来引入一个新的用户名属性,而不是尝试使用Id。

据我所知,我相信这是由BeanELResolver中一个模糊的bug引起的,该bug用于获取绑定到的属性类型,而不是返回字符串返回Serializable,没有转换器,因此我看到了错误

它不是特别优雅,但我已经解决了这个问题,将userId属性添加到我的userBean中,然后在我的视图中绑定到该属性,而不是用户实体上的Id属性。然后,在保存实体时,我使用该值手动设置该实体的Id:

<!-- My New View -->
<ui:composition template="/template/template_v1.xhtml"
            xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html">
<!-- Simplified for clarity -->    
<h:form>
    <div class="block-panel customer-data">
        <h:outputLabel for="txtUsername">Username:</h:outputLabel>
        <h:inputText id="txtUsername" name="Username" 
                     value="#{userBean.userId}"
                     styleClass="text" />
        <rich:message id="errorUsername" for="txtUsername"/>
    </div>
    <!--  Other fields omitted for clarity  -->

作为
,您得到的确切信息是什么?到底是哪个对象的
toString()
表示法?对不起,我不清楚。。。我在文本框中输入了什么字符串来代替哦,好吧,只是字面上输入的字符串?那就奇怪了。您确定
#{userBean.user}
不是null,也没有在提交过程中发生不兼容的更改吗?首先,在像
getUser()
这样的getter中执行DB交互作业看起来不太合适。是的,您可能是对的,它可能不是最干净的设计,但我继承了这段代码,希望在进行更改之前理解它为什么不起作用。尽管设计可能有点可疑,但我不认为它与getUser()有任何关系,就好像我绑定到用户实体上的其他属性一样(请参见原始问题),它按预期工作。是的,错误消息中显示的是按字面输入的字符串。
/* The user Entity - Simplified */
@Entity
@Table(name = "user")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "user_type", discriminatorType = DiscriminatorType.STRING)
public class User implements IEntity<String>, Serializable {
private static final long serialVersionUID = 1L;

    private String id;

    @Id
    @Column(name = "username", length = 50)
    @NotNull(message = "{userIdMandatory}")
    @Size(max = 50)
    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }
/* The IEntity interface */
public interface IEntity<ID extends Serializable> {
    ID getId();
    void setId(final ID pId);
}
public String getTmpId() {
    return this.id;
}

public void setTmpId(String id) {
    this.id = id;
}
<!-- My New View -->
<ui:composition template="/template/template_v1.xhtml"
            xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html">
<!-- Simplified for clarity -->    
<h:form>
    <div class="block-panel customer-data">
        <h:outputLabel for="txtUsername">Username:</h:outputLabel>
        <h:inputText id="txtUsername" name="Username" 
                     value="#{userBean.userId}"
                     styleClass="text" />
        <rich:message id="errorUsername" for="txtUsername"/>
    </div>
    <!--  Other fields omitted for clarity  -->
/* The New User Bean - simplified */
@ManagedBean
@ViewScoped
public class UserBean implements Serializable {
    private string userId;
    private User user;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public User getUser() {
        // Contains logic for reading a user from the database or creating a new
        // user object
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void saveUser() {
        if (user.getId() == null) {
            user.setId(userId);
        }
        // Actual saving omitted for brevity
    }
}