【发布时间】:2012-09-20 14:43:09
【问题描述】:
我有这段代码用于选择在 jsf 表中显示多少行:
<!-- Set rows per page -->
<h:outputLabel for="rowsPerPage" value="Rows per page" />
<h:inputText id="rowsPerPage" value="#{AccountsController.rowsPerPage}" size="3" maxlength="3" />
<h:commandButton styleClass="bimage" value="Set" action="#{AccountsController.pageFirst}" >
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
<h:message for="rowsPerPage" errorStyle="color: red;" />
我想以这种方式编辑代码:我想用 h:selectOneManu 替换代码并选择插入自定义值并支持 AJAX:
<h:selectOneMenu id="setrows" value="#{AccountsController.rowsPerPage}" converter="javax.faces.Integer" maxlength="3">
<f:selectItem itemValue="10" itemLabel="10" />
<f:selectItem itemValue="50" itemLabel="50" />
<f:selectItem itemValue="100" itemLabel="100" />
<f:selectItem itemValue="500" itemLabel="500" />
<f:selectItem itemValue="332" itemLabel="Custom" />
<f:ajax render="customrowperpage" />
</h:selectOneMenu>
<h:inputText id="customrowperpage" value="#{AccountsController.rowsPerPage}" rendered="#{AccountsController.rowsPerPage == '332'}" required="true" />
但由于某种原因,代码无法正常工作。你能帮我找出问题所在吗。当我从 h:selectOneMenu 列表 AJAX 调用中选择数字以更新表单时,我还想更新 AJAX 功能。
【问题讨论】:
-
如果您的组件将
rendered属性设置为false,则以后无法更新。您应该将<h:inputText id="customrowperpage">包装在另一个 UI 组件中(例如<h:panelGrid>)并重新渲染容器。 -
我测试了你的建议 - 它不起作用。我会让它更简单。如何重写源代码,以便当我从
h:selectOnemenuAJAX 调用中选择行时更新行数?