有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法从复合组件中找到匹配的导航案例

我有一个复合组件按钮,动作来自属性

<comp:interface>
    <comp:attribute name="buttonId" required="false"/>
    <comp:attribute name="action" required="false" method-signature="java.lang.String action()"/>
    <comp:attribute name="alt"/>
    <comp:attribute name="value" />
    <comp:attribute name="immediate"/>
</comp:interface>

<comp:implementation>
    <h:commandButton alt="#{cc.attrs.alt}" action="#{cc.attrs.action}"
                     value="#{cc.attrs.value}"  id="#{cc.attrs.buttonId}"
                     immediate="#{cc.attrs.immediate}"/>
</comp:implementation>

当我创建按钮时,操作来自我的控制器

<test:myButton value="Test" alt="test" action="{myController.doSomething}" immediate="true" buttonId="testId"/> 

然后我有一个查找myController.doSomething的导航规则

<navigation-case>
        <from-action>#{myController.doSomething}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/pages/test1.xhtml</to-view-id>
        <redirect />
 </navigation-case>

问题是,当我单击按钮时,操作来自#{cc.attrs.action},因此我得到以下错误

Unable to find matching navigation case with from-view-id '/pages/test.xhtml' for action '#{cc.attrs.action}' with outcome 'success'

我怎样才能避开这件事


共 (1) 个答案

  1. # 1 楼答案

    将targets属性添加到commandButton以重新确定action属性的目标,将解决此问题。因此,commandButton上不需要action属性

    <comp:interface>
        <comp:attribute name="buttonId"/>
        <comp:attribute name="action" targets="#{cc.attrs.buttonId}" method-signature="java.lang.String action()"/>
        <comp:attribute name="alt"/>
        <comp:attribute name="value" />
        <comp:attribute name="immediate"/>
    </comp:interface>
    
    <comp:implementation>
        <h:commandButton alt="#{cc.attrs.alt}" 
                         value="#{cc.attrs.value}"  id="#{cc.attrs.buttonId}"
                         immediate="#{cc.attrs.immediate}"/>
    </comp:implementation>
    

    http://www.devmanuals.com/tutorials/java/jsf/jsf2TagLibrary/composite/attribute.html

    targets : This is a required attribute that specifies the target to invoke the component client ids of by the 'method-signature' attribute (if present). Different target client ids can be separated by a space (not tab space) in target list but, if this attribute is not used with this tag and the attribute method-signature is used then only the value of 'name' attribute is targeted or can say the only value of 'name' attribute is targeted.

    您还可以使用下面链接中TargetAttribute属性文档中描述的方法。基本上,您将使cc:attribute的名称与commandButton id相同,然后使用targetAttributeName="action"表示您正在重新定位commandButton操作属性

    http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/composite/attribute.html