如何检索JSF托管bean中通过循环生成的文本框的值?
我需要通过如下循环生成文本框如何检索JSF托管bean中通过循环生成的文本框的值?,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我需要通过如下循环生成文本框 <p:panel id="dataPanel" closable="true" toggleOrientation="horizontal" toggleable="true" header="Data"> <h:panelGrid id="dataPanelGrid" columns="3" cellpadding="5"> <c:forEach var="row" items="#{zoneChargeM
<p:panel id="dataPanel" closable="true" toggleOrientation="horizontal" toggleable="true" header="Data">
<h:panelGrid id="dataPanelGrid" columns="3" cellpadding="5">
<c:forEach var="row" items="#{zoneChargeManagedBean.list}">
<p:outputLabel for="txtCharge" value="#{row[1]}"/>
<p:inputText id="txtCharge" value="#{row[2]}" converter="#{bigDecimalConverter}" onkeydown="return isNumberKey(event, this.value);" label="#{row[1]}" required="false" maxlength="45">
<f:validator validatorId="negativeNumberValidator"/>
<f:attribute name="isZeroAllowed" value="false"/>
<f:validator validatorId="bigDecimalRangeValidator"/>
<f:attribute name="minPrecision" value="1"/>
<f:attribute name="maxPrecision" value="33"/>
<f:attribute name="scale" value="2"/>
</p:inputText>
<p:message for="txtCharge" showSummary="false"/>
</c:forEach>
<p:commandButton id="btnSubmit" update="dataPanel messages" actionListener="#{zoneChargeManagedBean.insert}" icon="ui-icon-check" value="Save"/>
<p:commandButton value="Reset" update="dataPanel" process="@this">
<p:resetInput target="dataPanel" />
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:panel id="dataPanel" rendered="#{zoneChargeManagedBean.renderedDataPanel}" closable="true" toggleOrientation="horizontal" toggleable="true" header="Data">
<p:dataGrid columns="3" value="#{zoneChargeManagedBean.list}" var="row" paginator="true" paginatorAlwaysVisible="false" pageLinks="10" rows="15">
<p:watermark for="txtCharge" value="Enter charge."/>
<p:tooltip for="lblCharge" value="Some message."/>
<p:column>
<p:outputLabel id="lblCharge" for="txtCharge" value="#{row[1]}"/><br/>
<p:inputText id="txtCharge" value="#{row[2]}" onkeydown="return isNumberKey(event, this.value);" converter="#{bigDecimalConverter}" label="#{row[1]}" required="false" maxlength="45">
<f:validator validatorId="negativeNumberValidator"/>
<f:attribute name="isZeroAllowed" value="false"/>
<f:validator validatorId="bigDecimalRangeValidator"/>
<f:attribute name="minPrecision" value="1"/>
<f:attribute name="maxPrecision" value="33"/>
<f:attribute name="scale" value="2"/>
</p:inputText>
<h:message for="txtCharge" showSummary="false" style="color: #F00;"/>
</p:column>
</p:dataGrid>
<p:commandButton id="btnSubmit" update="dataPanel messages" actionListener="#{zoneChargeManagedBean.insert}" icon="ui-icon-check" value="Save"/>
<p:commandButton value="Reset" update="dataPanel" process="@this">
<p:resetInput target="dataPanel" />
</p:commandButton>
</p:panel>
给定文本框的值是数据库中的BigDecimal
类型
当按下给定的命令按钮时,应该从相应的JSF托管bean中检索这些文本框所持有的值,以便在数据库中插入或更新这些值
如果可以在某种集合(如java.util.List
)中一次检索所有这些文本字段的值,当按下给定的按钮时,效果会更好。,渲染时间标记可以正常工作,但视图构建时间组件不能正常工作(我无法解释原因)但在这种特殊情况下,我发现
更合适。XHTML被相应地修改如下
<p:panel id="dataPanel" closable="true" toggleOrientation="horizontal" toggleable="true" header="Data">
<h:panelGrid id="dataPanelGrid" columns="3" cellpadding="5">
<c:forEach var="row" items="#{zoneChargeManagedBean.list}">
<p:outputLabel for="txtCharge" value="#{row[1]}"/>
<p:inputText id="txtCharge" value="#{row[2]}" converter="#{bigDecimalConverter}" onkeydown="return isNumberKey(event, this.value);" label="#{row[1]}" required="false" maxlength="45">
<f:validator validatorId="negativeNumberValidator"/>
<f:attribute name="isZeroAllowed" value="false"/>
<f:validator validatorId="bigDecimalRangeValidator"/>
<f:attribute name="minPrecision" value="1"/>
<f:attribute name="maxPrecision" value="33"/>
<f:attribute name="scale" value="2"/>
</p:inputText>
<p:message for="txtCharge" showSummary="false"/>
</c:forEach>
<p:commandButton id="btnSubmit" update="dataPanel messages" actionListener="#{zoneChargeManagedBean.insert}" icon="ui-icon-check" value="Save"/>
<p:commandButton value="Reset" update="dataPanel" process="@this">
<p:resetInput target="dataPanel" />
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:panel id="dataPanel" rendered="#{zoneChargeManagedBean.renderedDataPanel}" closable="true" toggleOrientation="horizontal" toggleable="true" header="Data">
<p:dataGrid columns="3" value="#{zoneChargeManagedBean.list}" var="row" paginator="true" paginatorAlwaysVisible="false" pageLinks="10" rows="15">
<p:watermark for="txtCharge" value="Enter charge."/>
<p:tooltip for="lblCharge" value="Some message."/>
<p:column>
<p:outputLabel id="lblCharge" for="txtCharge" value="#{row[1]}"/><br/>
<p:inputText id="txtCharge" value="#{row[2]}" onkeydown="return isNumberKey(event, this.value);" converter="#{bigDecimalConverter}" label="#{row[1]}" required="false" maxlength="45">
<f:validator validatorId="negativeNumberValidator"/>
<f:attribute name="isZeroAllowed" value="false"/>
<f:validator validatorId="bigDecimalRangeValidator"/>
<f:attribute name="minPrecision" value="1"/>
<f:attribute name="maxPrecision" value="33"/>
<f:attribute name="scale" value="2"/>
</p:inputText>
<h:message for="txtCharge" showSummary="false" style="color: #F00;"/>
</p:column>
</p:dataGrid>
<p:commandButton id="btnSubmit" update="dataPanel messages" actionListener="#{zoneChargeManagedBean.insert}" icon="ui-icon-check" value="Save"/>
<p:commandButton value="Reset" update="dataPanel" process="@this">
<p:resetInput target="dataPanel" />
</p:commandButton>
</p:panel>
我无法使用相应的JPA条件查询,因为JPA条件API似乎不支持with
运算符
当选择了
中本问题未涉及的项目时,将调用此方法。您可以使用PrimeFaces DataTable-行编辑功能。这个问题我不清楚。ZoneChargeManagedBean是您的代码,您应该最了解如何访问它的数据。顺便说一句,使用索引访问行数据看起来很尴尬,但如果没有bean的代码,就很难说了。您的具体问题是什么?您已经有一个#{zoneChargeManagedBean.list}
来保存这些值。当您在action method中选中它时,它是否为空?新值不会累积在zoneChargeManagedBean.列表中
,当然,当与
一起使用时,新值不会与填充了新值的
一起出现(如果数据库表中有相应的行,则在从数据库检索时已填充列表。更新只需在列表中保存的对象数组行[2]
的最后一个元素中进行。最后一个元素的值显示在
中)。哦,对了,您仍然在使用Spring来管理bean。显然,它的视图范围与c:forEach
不兼容,这导致每次迭代都会重新创建bean。在较旧的Mojarra版本中,JSF自己的视图范围中也存在类似的错误。在以后的问题中,请描述实际问题!(为了消除代码噪音,我不认为使用BigDecimal
而不是String
,以及使用那些验证器/转换器,
等与具体问题有什么关系。