2010-11-30 30 views
0

我想在驗證保存(Toolbar.xhtml)時在不同表單上驗證必填字段。我怎樣才能做到這一點?在此先感謝JSF上的Ajax驗證

我有以下代碼:

Father.xhtml

.. 
<ui:include src="/jsf/Toolbar.xhtml"/> 
<ui:include src="/jsf/Adquisicion.xhtml"/> 
.. 

Toolbar.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:a4j="http://richfaces.org/a4j" 
     xmlns:rich="http://richfaces.org/rich" 
     > 

<ui:insert name="toolbarComponent"> 
    <h:form name="ToolbarForm" > 
    <a4j:commandLink id="save" action="#{backingBean1.save}"/> 
    </h:form> 
</ui:insert> 

</ui:composition>  

Adquisicion.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:a4j="http://richfaces.org/a4j" 
     xmlns:rich="http://richfaces.org/rich"> 

<ui:insert name="component"> 
    <a4j:form id="Adquisicion"> 
    <rich:panel> 
     <f:facet name="header"> 
      <h:outputText value="Header" /> 
     </f:facet> 
     <h:panelGrid columns="3"> 
    <h:outputText value="Name" /> 
    <h:inputText id="nameId" value="#{adquisicion.name}"     style="width:500px;" required="true" requiredMessage="Required" > 
      <a4j:support event="onblur"/> 
     </h:inputText> 
    <rich:message for="nameId" style="color: red;"/> 
    </rich:panel> 
    <a4j:form> 
</ui:insert> 
<ui:composition> 

回答

0

輸入字段必須在相同<h:form>(或<a4j:form>,無論你喜歡)作爲命令鏈接/按鈕。

+0

還有其他解決方案嗎?謝謝 – Martin 2010-11-30 18:20:32