了解AJAX使用JSF的数据表2.0执行行为数据表、行为、AJAX、JSF

2023-09-10 21:17:07 作者:神经病医院八号床

我想要使用搜索按钮其带回所选择的项目(可以是多个),并将其更新的数据表。然后,我有一个selectBooleanCheckbox相邻colomn,当用户选择N项,然后presses在选择的检查项目它插入数据库。

i'm trying to use an search button which brings back the selected items (can be more than one) and it updates the datatable. Then i have a selectBooleanCheckbox next to each colomn, when user selects "n" items then presses the Select the checked Items it insert DB.

在code可以在下面看到:

The code can be seen below:

<h:panelGrid columns="5">
    <h:form>
      <h:outputText value="Item Name"/>
      <p:inputText value="#{StockController.itemName}"/>
      <h:commandButton value="Search" action="#{StockController.Search}">
         <f:ajax execute="@form" render=":results"/>
      </h:commandButton>
    </h:form>

//将code以下样本属于BalusC看到帖子here

    <h:panelGroup id="results">
    <h:form>
    <h:dataTable value="#{bean.entities}" var="entity">
        <h:column>
            <h:selectBooleanCheckbox value="#{bean.checked[entity.id]}" />
        </h:column>
        ...
    </h:dataTable>
    <h:commandButton value="Select the checked Items" action="#{StockController.insertDao}" >
  <f:ajax execute="@form" render=":results"/>
 </h:commandButton>
 </h:form>
</h:panelGrid>

现在,我看了很多博客和核心的JavaServer Faces 3,我不认为这是在阿贾克斯的使用逻辑错误。我测试通过删除每个AJAX和两个正常工作,但每当我试图使用两个c​​ummondButtons 使用Ajax,第二个:选择的检查项目甚至不叫StockController.insertDao方式。

Now, i have read many blogs and Core javaServer Faces 3, i don't think there is logical error in ajax usage. I tested by removing each ajax then both works fine but whenever i try to use both of cummondButtons with ajax, the second one "Select the checked Items" does not even call the "StockController.insertDao" method.

任何帮助是AP preciated。

Any help is appreciated.

谢谢大家。

推荐答案

当你想AJAX的呈现内容又包含另一种形式,那么你需要包括这种形式的的ID渲染属性为好,否则,其它形式将失去其视图状态并没有什么将在提交处理。

When you want to ajax-render content which in turn contains another form, then you need to include the ID of that form in the render attribute as well, otherwise the other form will lose its view state and nothing will be processed on submit.

<h:form>
  ...
  <h:commandButton value="Search" action="#{StockController.Search}">
    <f:ajax execute="@form" render=":results :resultsForm" />
  </h:commandButton>
</h:form>

<h:panelGroup id="results">
  <h:form id="resultsForm">
    ...
  </h:form>
</h:panelGroup>

如果有但是没有它去外面&LT; H:形式GT; 里面的相同&LT; H:panelGroup中&GT; ,那么你可以省略&LT; H:panelGroup中&GT; 干脆直接重新呈现形式

If there's however nothing which goes outside <h:form> inside the same <h:panelGroup>, then you can just omit the <h:panelGroup> altogether and re-render the form directly.

<h:form>
  ...
  <h:commandButton value="Search" action="#{StockController.Search}">
    <f:ajax execute="@form" render=":results" />
  </h:commandButton>
</h:form>

<h:form id="results">
  ...
</h:form>

这是关系到 JSF规范问题790 。

在JSF2通信 - 内容的Ajax渲染包含另一种形式
 
精彩推荐
图片推荐