【问题标题】:Getting value from dynamically created inputText box in forEach section从 forEach 部分中动态创建的 inputText 框中获取值
【发布时间】:2014-04-26 09:38:19
【问题描述】:

我正在尝试做一些与Getting value from dynamically created inputText 非常相似的事情,我遇到了一些困难,这就是为什么我会在这里问我的问题,希望你能帮助我。我想将动态生成的输入框与对象绑定。我有:

<c:forEach items="${filterTypeBean.listTextFilterTypes()}"
                        var="inputBoxes">
                        <h:outputText value="${inputBoxes.filterTypeName}"
                            style="width: 100px; white-space: normal; border: 3px" />
                        <h:inputText value="${requestBean.filterTypeValue}" />
                    </c:forEach>

在 filterTypeValue 的请求 bean 中我有:

private String filterTypeValue;

public String getFilterTypeValue() {
    return filterTypeValue;
}

public void setFilterTypeValue(String filterTypeValue) {
    this.filterTypeValue = filterTypeValue;
}

我的问题来自于我有三个实体 - TRequest、TRequestFilter、TFilter。 TRequestFilter 是一个映射表,其中我有 TREQUEST、TFILTER 和我想从后者的输入框中获取并插入 DB 的值。

filterTypeBean.listTextFilterTypes() 我取自 FilterTypeBean:

public List<TFilterType> listTextFilterTypes() {
        EntityManager em = HibernateUtil.getEntityManager();
        Query q = em.createQuery("select u from TFilterType u where u.filterType like 'T'");
        List<TFilterType> resultList = q.getResultList();
        return resultList;
    }

我想在 RequestBean 中设置输入框的值,因为首先我在数据库中插入一个新请求,然后我想在 TRequestFilter 表中插入这个新请求的过滤器(我需要 TFilter 和插入的值的原因为了它)。

非常感谢您的帮助!

【问题讨论】:

    标签: java jsf primefaces


    【解决方案1】:

    我设法让它在我的 bean 类中使用映射:

    private Map<TFilterType, Object> values = new HashMap<TFilterType, Object>();
    
    public Map<TFilterType, Object> getValues() {
            return values;
        }
    

    和迭代器:

    while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry) it.next();
                if (pairs.getValue() != null) {
                              System.out.println(pairs.getKey() + '='+ pairs.getValue());
                }
                it.remove(); // avoids a ConcurrentModificationException
            }
    

    通过这种方式,我拥有对象及其值,并且我能够在数据库的新实体中插入一条记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      相关资源
      最近更新 更多