简体   繁体   English

未在bean中设置h:inputText值

[英]h:inputText value not set in bean

The <h:inputText> value is not been set in a request scoped bean. <h:inputText>值未在请求范围的bean中设置。 If the value is preserved from DB, it works fine. 如果从数据库保留该值,则可以正常工作。

view: 视图:

<h:inputText id="receipient" size="90" styleClass="text" readonly="#{!bean.enable}" value="#{bean.recipient}" />

bean: 豆角,扁豆:

public class Bean {
    private String recipient;
    Bean(){
        recipient = //load from db
    }
    //set 
    //get
}

What is the problem and how can I solve this? 有什么问题,我该如何解决?

Ensure that readonly="#{!bean.enable}" evaluates the same as it was in initial view. 确保readonly="#{!bean.enable}"评估结果与初始视图中的评估结果相同。 If it evaluates true during apply request values phase of the form submit, then the component's value won't be processed (because it is marked as read only). 如果在表单提交的“应用请求值”阶段评估为true ,则将不处理组件的值(因为它被标记为只读)。

An easy test is to put the bean in session scope. 一个简单的测试是将bean放入会话范围。 If that fixes it, then you know the culprit. 如果这样可以解决问题,那么您就知道罪魁祸首。 If you're using JSF 2.0, just put bean in view scope by using @ViewScoped instead of @RequestScoped . 如果使用的是JSF 2.0,只需使用@ViewScoped而不是@RequestScoped将bean放入视图范围。 If you're still on JSF 1.x, use Tomahawk's <t:saveState> component to let the bean act like the JSF 2.0 view scoped one. 如果您仍在使用JSF 1.x,请使用Tomahawk的<t:saveState>组件让Bean像JSF 2.0视图那样作用。

<t:saveState value="#{bean}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM