无法<String>从 <ui:repeat> var 状态设置列表值



在我的xhtml中,我定义了一个inputText变量,我想从中为列表中的特定字段设置一个特定值。每次我点击确认并调试我的代码时,值都返回为"0"(我在init函数中设置的(。我还尝试将inputText值硬编码为dashboardFilterDialogBean.dashboardObject.texts[0],这是我定义的列表中唯一的项目,但仍然没有结果。我的控制台中有0个异常

Xhtml

<p:dialog id="dashboardFilterDialog">
<h:form id="dashboard_filter_dialog_form">
<ui:repeat value="#{dashboardFilterDialogBean.dashboardObject.texts}" varStatus="loop">
<p:row>
<p:column>
<h:outputText value="Text" />
</p:column>
<p:column>
<p:inputText value="#{dashboardFilterDialogBean.dashboardObject.texts[loop.index]}" />
</p:column>
</p:row>
</ui:repeat>
</h:form>
<f:facet name="footer">
<h:form id="submit_dashboards_dialog_form">
<p:commandButton id="confirm_button" actionListener="#{dashboardFilterDialogBean.confirm()}" />
</h:form>
</f:facet>
</p:dialog>

Bean

public class DashboardFilterDialogBean {
private DashboardObject dashboardObject;
@PostConstruct
public void init() {
dashboardObject.getTexts().add("");
}
public void confirm() {
for (String txtValue : getDashboardObject().getTexts()) {
if (!txtValue.equals("")) {
...;
}
}
}
public DashboardObject getDashboardObject() {
return dashboardObject;
}
public void setDashboardObject(DashboardObject dashboardObject) {
this.dashboardObject = dashboardObject;
}
}

对象

public class DashboardObject {
private List<String>            texts;
public DashboardObject() {
texts = new ArrayList<String>();
}
public List<String> getTexts() {
return texts;
}
public void setTexts(List<String> texts) {
this.texts = texts;
}
}

我通过在inputText中添加<p:ajax event="blur" process="@this" />来解决问题,这样它就可以在我单击确认之前保存值。所以最终代码看起来是这样的:

<p:inputText value="#{dashboardFilterDialogBean.dashboardObject.texts[loop.index]}" />
<p:ajax event="blur" process="@this" />
</p:inputText>

最新更新