【问题标题】:Inner component not found when retargetMethodExpressionsretargetMethodExpressions 时找不到内部组件
【发布时间】:2012-04-29 22:17:09
【问题描述】:

我必须编写一个显示登录表单的复合组件,并且可以与以下代码sn-p一起使用:

<login:loginForm username="#{loginBean.username}" 
                 password="#{loginBean.password}" 
                 action="#{loginBean.login}"/>

我的 loginBean 只是一个简单的可序列化 @ViewScoped @ManagedBean,带有 getter、setter 和 public String login() 方法。

这是我的复合组件:

<body>
    <cc:interface>
        <cc:attribute name="username" required="true" type="java.lang.String" />
        <cc:attribute name="password" required="true" type="java.lang.String" />
        <cc:attribute name="action" targets="submit" required="true" method-signature="java.lang.String f()"/>
    </cc:interface>

    <cc:implementation>
        <h3><span xml:lang="en">Login</span> Daten </h3>
        <h:form>
            <div class="formblock">
                <fieldset>
                    <div>
                        <h:outputLabel value="Username" for="username"/>
                        <h:inputText id="username" value="#{cc.attrs.username}"/>
                    </div>

                    <div>
                        <h:outputLabel value="Passwort" for="password"/>
                        <h:inputSecret id="password" value="#{cc.attrs.password}"/>
                    </div>
                </fieldset>
            </div>
            <div class="buttons">
                <h:commandButton id="submit" value="Anmelden" accesskey="r" />
            </div>
        </h:form>
    </cc:implementation>
</body>

但是,当我在浏览器中打开 login.xhtml 页面(其中包含 login:loginForm-sn-p)时,我可以在码头日志中看到以下错误:

Apr 29, 2012 11:59:49 PM org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage retargetMethodExpressions
SEVERE: Inner component submit not found when retargetMethodExpress

但这意味着什么?我的代码中的错误在哪里?我已经尝试了一些其他解决方案来实现action 属性,但没有成功。

【问题讨论】:

  • 刚刚看到我使用的是 myfaces 版本 2.0.4 而不是当前的 2.1.7 版本。所以,升级了,现在错误消失了。但是单击命令按钮时仍然没有执行该操作。

标签: jsf jsf-2 composite-component


【解决方案1】:

好的。升级到 myfaces 2.1.7 版后,没有target-stuff 的直接解决方案可以工作:

<body>
    <cc:interface>
        <cc:attribute name="username" required="true" type="java.lang.String" />
        <cc:attribute name="password" required="true" type="java.lang.String" />
        <cc:attribute name="action" required="true" method-signature="java.lang.String f()"/>
    </cc:interface>

    <cc:implementation>
        <h3><span xml:lang="en">Login</span> Daten </h3>
        <h:form>
            <div class="formblock">
                <fieldset>
                    <div>
                        <h:outputLabel value="Username" for="username"/>
                        <h:inputText id="username" value="#{cc.attrs.username}"/>
                    </div>

                    <div>
                        <h:outputLabel value="Passwort" for="password"/>
                        <h:inputSecret id="password" value="#{cc.attrs.password}"/>
                    </div>
                </fieldset>
            </div>
            <div class="buttons">
                <h:commandButton action="#{cc.attrs.action}" value="Anmelden" accesskey="r" />
            </div>
        </h:form>
    </cc:implementation>
</body>

【讨论】:

    【解决方案2】:

    target="submit" 不正确,因为 h:form 是 NamingContainer,因此您需要为该组件分配和 id 并将目标更改为 "myForm:submit" 或类似的东西。

    【讨论】:

    • 你的意思是我应该用 targets="myForm:submit"&lt;h:form&gt; 替换 targets="submit"&lt;h:form id="myForm"&gt; 然后它应该工作?
    猜你喜欢
    • 1970-01-01
    • 2020-05-08
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    相关资源
    最近更新 更多