How to initialize inputtextfield with a value from database on runtime without the use of @PostContruct?

夙愿已清 提交于 2019-11-28 14:40:37

Actually I couldn't reproduce your issue. It works fine for me. I tested with Mojarra 2.2.8 and Apache Tomcat 7.0.47. Did you see any Errors?`maybe in your Database code? Was the background style applied?


However I'm not sure whether you really need the binding? You can also try the following approach.

private String input= fetchValueFromDatabase();

public PreInitializeBean(){
}

private String fetchValueFromDatabase() {
    String resultValue = "preSetValue";
    return resultValue;
}

public String getInput() {
    return input;
}

public void setInput(String input) {
    this.input = input;
}

And the xml:

<h:inputText value="#{data.input}" maxlength="15" style="background: pink;">
</h:inputText>

I think this is more conventional.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!