2014-03-06 95 views
0

我创建了一个名为loginRegisterTemplate.xhtml的facelet模板。当我在一个模板客户端中使用它时,我将它放在里面,托管bean中的方法不会被调用。没有模板,按钮工作正常。这是为什么发生?<h:commandButton> not working <ui:define>

<ui:composition template="resources/css/faceletsTemplates/loginRegisterTemplate.xhtml"> 
     <ui:define name="top"> 
      Login Page 
     </ui:define> 
     <ui:define name="content"> 
      <div align="center"> 
       <h:panelGrid columns="3" columnClasses="rightalign,leftalign,leftalign"> 

        <h:outputLabel value="Username:" for="userName"/> 
        <h:inputText id="userName" label="Username" required="true" value="#{loginBean.userName}" /> 
        <h:message for="userName" /> 

        <h:outputLabel value="Password:" for="password"/> 
        <h:inputText id="password" label="Password" required="true" value="#{loginBean.password}" /> 
        <h:message for="password" /> 
       </h:panelGrid><br/> 

       <h:button value="Back to Home" outcome="home"/> 
       <h:commandButton id="login" value="Login" action="#{loginBean.doLogin}"/> 
      </div> 
     </ui:define> 
    </ui:composition> 
</h:body> 

它旁边的简单<h:button>工作正常。

这里是我的模板文件的主体:

<h:body> 
    <div id="top"> 
     <ui:insert name="top">Top</ui:insert> 
    </div> 
    <div id="content" class="center_content"> 
     <ui:insert name="content">Content</ui:insert> 
    </div> 
</h:body> 

我已经在这里看了:h:commandLink/h:commandButton is not being invoked但我找不到这问题会导致。

谢谢!

回答

0

为什么h:commandButton无法正常工作?

您的问题是answer you have checked中的编号1。

UICommand和UIInput组件必须放置在UIForm 组件的内部,例如, <h:form>

为什么h:button工作呢?

h:button docs

渲染类型的 “按钮” 的HTML “输入” 元素。 组件的值以按钮文本形式呈现,并且 组件的结果用于确定由onclick激活的目标URL。

所以...

JSF会把你h:buttonoutcome值将在onclick事件执行的JavaScript函数。但它会在POST方法提交的表单上执行h:commandButtonaction,所以应该有一个表单提交。

+0

非常感谢!我真的不知道我是如何错过的,而且我一直在寻找更复杂的解决方案! – BrainArchitect

相关问题