jjzjj

java - CommandLink 不在 jsf 表单中,因为我已将它添加到模板中。但是它被禁用了。有没有其他方法可以启用它?

coder 2024-03-27 原文

我已将我的 commandLink(这是注销链接)添加到模板文件中,该文件jsf 表单中。

主模板.xhtml

<h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out">
</h:commandLink>

在使用该模板的网页上,我将所有元素都放在一个 jsf 表单中:

NewWelcome.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:h="http://xmlns.jcp.org/jsf/html"
                 xmlns:f="http://xmlns.jcp.org/jsf/core"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 template="/webpages/templates/MainTemplate.xhtml">

  <ui:define name="infomationPartOfBody">
     <h:form>
<div>  Here i have all the page specific content </div>

 </h:form>
 </ui:define>

 </ui:composition>

我希望一旦我在带有 jsf 表单的页面中使用模板,注销就会起作用。但是,注销命令链接显示错误:

注销:此链接已禁用,因为它未嵌套在 JSF 表单中。

我知道一个明确的解决方案是将此元素单独添加到每个将使用该模板的 xhtml 页面中。但我希望将其添加到模板本身,因为它是所有页面中的公共(public)元素

任何帮助将不胜感激。谢谢你! :)

编辑: 这是我的 MainTemplate.xhtml 的代码

 <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
 xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:ui="http://java.sun.com/jsf/facelets">
 <f:view>

    <h:head>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/cupertino/jquery-ui.css"/>
        <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script type="text/javascript" src="../JavaScriptPages/JQueryFile.js"></script>

        <title>State Transport Department- Work Schedule</title> 
        <link  rel="stylesheet" type="text/css" href="../CSS/CompleteTemplateCSS.css"/>
    <link  rel="stylesheet" type="text/css" href="../CSS/templateCSS.css"/>
    </h:head>

    <h:body>

        <div class="container">
            <div class="header">
                <h:graphicImage id="img"  value="http://s28.postimg.org/ksnr9zs5p/header.jpg" class="img" ></h:graphicImage> 
            </div>
            <div class="menu">
                 <h:outputLabel  class="welcomeNote" style="font-size: x-large; color: white; float: left;
                                margin: 8px 0 0 5px; text-shadow:0 0 3px white" value="#{welcomeBean.fullname}" />

         <ul class="ulForMyAccount">
                        <li> <h:outputLabel value="My Account" id="mainAnchor"/>

                            <ul >
                                <li> <h:link value="Change my Password" outcome="/webpages/ChangePasswordxhtml.xhtml" rendered="true" class="subAnchor"/>  </li>
                                <li><h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out">
                             </h:commandLink> </li>

                            </ul>
                        </li>
                    </ul>     
            </div>
            <div class="contentBody">
                <div class="menuTable">

                    <table class="templateBody" >
                            <tr>
                                <td class="navigationLink" > <ul><li>
                                            <h:link  value="Home" outcome="/webpages/NewWelcome.xhtml"  rendered="#{welcomeBean.home}" class="mainLinks"/> 
                                        </li></ul> </td>

                            </tr>

                            <tr>
                                <td class="navigationLink"> <ul> <li>
                                            <h:link value="My Schedule" outcome="/webpages/MyTask.xhtml" rendered="#{welcomeBean.myTask}"   class="mainLinks"/>    
                                        </li></ul></td>
                            </tr>

                            <tr>
                                <td class="navigationLink"> <ul> <li>
                                            <h:link value="Employee Work Schedule" outcome="/webpages/EmpDutySched.xhtml" rendered="#{welcomeBean.workSchedule}"   class="mainLinks"/>    
                                        </li></ul></td>
                            </tr>

                            <tr>
                                <td class="navigationLink"><ul> <li>
                                            <h:link value="Allocate Work" outcome="/webpages/AllocateTask.xhtml" rendered="#{welcomeBean.allocateWork}" class="mainLinks"/>
                                        </li></ul></td>
                            </tr>

                            <tr>
                                <td class="navigationLink"><ul> <li>
                                            <h:outputLabel value="Report" rendered="#{welcomeBean.report}" class="reportMenu"/>

                                             </li></ul>
                                    <ul>
                                                <li><h:link value="Project Wise Report" outcome="/webpages/ProjectWiseReport.xhtml" rendered="true" class="reportItems"/></li>
                                                <li><h:link value="Employee Wise  Report" outcome="/webpages/EmployeeWiseReport.xhtml" rendered="true" class="reportItems"/></li>
                                            </ul>
                                       </td>
                            </tr>

                        </table>

                </div>

                <ui:insert name="infomationPartOfBody">

                </ui:insert>

            </div>

            <div class="footer"></div>
        </div>

    </h:body>

 </f:view>

</html>

最佳答案

由于 commandLink 启动一个 Action ,你必须添加一个 h:form

  <h:form>
 <h:commandLink action="#{welcomeBean.logOutSession}" class="subAnchor" value="Log Out"/>
 </h:form>

关于java - CommandLink 不在 jsf 表单中,因为我已将它添加到模板中。但是它被禁用了。有没有其他方法可以启用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23074113/

有关java - CommandLink 不在 jsf 表单中,因为我已将它添加到模板中。但是它被禁用了。有没有其他方法可以启用它?的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  5. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  6. Ruby 方法() 方法 - 2

    我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby​​-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco

  7. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  8. ruby - 将 Bootstrap Less 添加到 Sinatra - 2

    我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它

  9. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  10. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

随机推荐