Jsf 2 a4j:commandButton在模板化jsf中不起作用

Jsf 2 a4j:commandButton在模板化jsf中不起作用,jsf-2,Jsf 2,我的问题是,, 我有一个template.xhtml,用于web应用程序的布局 <div id="header"> <ui:insert name="header"> [Top Bar content will be inserted here] </ui:insert> </div> <div id="main"> <ui:insert name="main"

我的问题是,, 我有一个template.xhtml,用于web应用程序的布局

<div id="header">
   <ui:insert name="header">
        [Top Bar content will be inserted here]
     </ui:insert>
    </div>



    <div id="main">
        <ui:insert name="main">
            [Nav Bar Left content will be inserted here]
         </ui:insert>
    </div>

    <div id="button">
         <ui:insert name="button">
            [Nav Bar Left content will be inserted here]
         </ui:insert>
    </div>

[顶部栏内容将插入此处]
[导航栏左侧内容将插入此处]
[导航栏左侧内容将插入此处]
然后我有一个addOrder.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="/WEB-INF/template/popUpInsert.xhtml">

<ui:define name="header">
  <h:outputLabel value="Status" />
  <rich:inplaceInput value="#{ordineController.orderToSave.status}"   />
  <h:outputLabel value="Code" />
  <rich:inplaceInput value="#{ordineController.orderToSave.code}"  />
</ui:define>
<ui:define name="main">
  Here there is a data table that contains lines of the order
</ui:define>
<ui:define name="button">
 <h:form>
 <a4j:commandButton value="Save" action="#{ordineController.addOrder()}" />
 <h:form>
</ui:define>

这里有一个包含订单行的数据表
但当我试图保存订单时,状态和代码都为null,我试图将范围更改为button save(execute=“@all”),但什么都没有


怎么了?

将此添加到您的页面
,您将看到来自JSF的更多警告,在您的情况下,应该会有关于缺少表单的警告,因为JSF知道哪些元素需要在表单中。最后都是HTML和JavaScript,因此如果要提交,输入需要在表单中。

您需要将相关的输入组件与命令组件放在相同的表单中。任何与命令组件形式不同的输入组件在提交时都会被忽略。请注意,这是一个HTML限制,而不是JSF限制

因此,这对您来说应该是:

<h:form>
    <div id="header">
        <ui:insert name="header">
            [Top Bar content will be inserted here]
        </ui:insert>
    </div>

    <div id="main">
        <ui:insert name="main">
            [Nav Bar Left content will be inserted here]
        </ui:insert>
    </div>

    <div id="button">
        <ui:insert name="button">
            [Nav Bar Left content will be inserted here]
        </ui:insert>
    </div>
</h:form>

[顶部栏内容将插入此处]
[导航栏左侧内容将插入此处]
[导航栏左侧内容将插入此处]
以及:


这里有一个包含订单行的数据表

注意不要以这种方式创建“上帝”表单。

为什么选择在模板中不包含任何表单?任何未包装在
中的内容都不会提交到服务器。因此,所有这些输入组件都不会在服务器端处理它们的值
<ui:define name="header">
    <h:outputLabel value="Status" />
    <rich:inplaceInput value="#{ordineController.orderToSave.status}" />
    <h:outputLabel value="Code" />
    <rich:inplaceInput value="#{ordineController.orderToSave.code}"  />
</ui:define>
<ui:define name="main">
    Here there is a data table that contains lines of the order
</ui:define>
<ui:define name="button">
    <a4j:commandButton value="Save" action="#{ordineController.addOrder()}" />
</ui:define>