Managed Bean as Facelet参数使复合组件无法解析 [英] Managed Bean as Facelet parameter lets composite component prevent resolving

查看:97
本文介绍了Managed Bean as Facelet参数使复合组件无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定的情况下,我想将Facelet与其他ManagedBeans配合使用,因此将action-bean作为参数给出:

In the given case, I want to use a facelet with different ManagedBeans, so the regarding action-bean is given as an parameter:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" >
<h:body>
    <ui:include src="ratings.xhtml" >
      <ui:param name="createAction" value="#{myOneCreateAction}" />
      <ui:param name="ratings" value="#{context.ratings}" />
    </ui:include>
</h:body>
</html>

我将创建动作作为参数value="#{myOneCreateAction}".

I'm giving the create action as parameter value="#{myOneCreateAction}".

在facelet中,该组件也是在其他页面上多次使用的组件-因此,我尝试在复合组件中对其进行重构.

Within that facelet is a component also being used several times on other pages - so I try to refactor it in a composite component.

<html 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:io="http://java.sun.com/jsf/composite/inoutComponents">
<ui:composition>
    <rich:dataTable id="ratingTblId" 
    value="#{ratings}" 
    var="rating">
        <rich:column>
             <io:removeButton
                 id="removeButton"
                 actionMethod="#{createAction.removeRating}"
                 immediate="true"
                 render=":#{rich:clientId('ratingTblId')}" />

             <h:commandButton
                 id="removeButton2"
                 actionListener="#{createAction.removeRating}"
                 immediate="true" >                    
                    <f:ajax render="ratingTblId" />
              </h:commandButton>
        </rich:column>
</rich:dataTable>
</ui:composition>
</html>

请参见,该方法如何作为actionMethod="#{createAction.removeRating}"给予组件.该组件本身如下所示:

See, how the method is given as actionMethod="#{createAction.removeRating}" to the component. This component itself looks like following:

<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:cc="http://java.sun.com/jsf/composite">
    <!-- INTERFACE -->
    <cc:interface>
        <cc:attribute 
            name="actionMethod" 
            targets="remove" 
            method-signature="void f(javax.faces.event.ActionEvent)"/>
        <cc:attribute name="render" required="false" />
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation> 
        <h:commandButton 
           id="remove"
           actionListener="#{cc.attrs.actionMethod}" 
           onclick="if (!confirm('Do you really?')) { return false; }">
           <f:ajax execute="@this" render="#{cc.attrs.render}" />
        </h:commandButton> 
    </cc:implementation>
</ui:composition>

最后但并非最不重要的是托管bean

and last but not least, the managed bean

Name("myOneCreateAction")
@Scope(ScopeType.CONVERSATION)
public class MyOneCreateAction {
   ...
   public void removeRating(ActionEvent ev) {
        // do something
   }
   ...
}

令人惊讶的是,当removeButton2正确跳转到正确的函数时,复合组件版本返回

Surprisingly, while the removeButton2 correctly jumps into the right function, the composite components version returns a

javax.faces.event.AbortProcessingException: Target Unreachable, 
      identifier 'createAction' resolved to null

相反.我正在将Mojarra JSF 2.1.26与Seam 2.3.1.CR1一起使用.没有嵌套的复合组件.将复合组件参数替换为#{myOneCreateAction.removeRating}时,它的工作原理与预期的一样.

instead. Am using Mojarra JSF 2.1.26 with Seam 2.3.1.CR1. There are no nested composite components. When replacing the composite component parameter to #{myOneCreateAction.removeRating}, it works like expected.

以前有人看过吗?我是盲人吗?任何已知的解决方法...?预先感谢!

Has anybody seen this before? Am I blind? Any work-arounds known... ? Thanks in advance!

推荐答案

作为一种变通办法,我重新编写了该组件,以将动作bean和动作方法作为两个单独的参数来解决,如下所示

As a work-around I rewrote the component to give action bean and action method as two separate parameters resolving them as following

xhtml:

<io:removeButton
             id="removeButton"
             actionBean="#{createAction}"
             actionMethod="removeRating"
             immediate="true"
             render=":#{rich:clientId('ratingTblId')}" />

复合成分:

<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:cc="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<cc:interface>
    <cc:attribute name="actionBean" />
    <cc:attribute name="actionMethod" />
    <cc:attribute name="render" required="false" />
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation> 
    <h:commandButton 
       id="remove"
       action="#{cc.attrs.actionBean[cc.attrs.actionMethod]}" 
       onclick="if (!confirm('Do you really?')) { return false; }">
       <f:ajax execute="@this" render="#{cc.attrs.render}" />
    </h:commandButton> 
</cc:implementation>
</ui:composition>

还更改了操作方法签名以返回String而不是void.那看起来不再那么性感了,但是行得通. :-/

also changing the action methods signature to return String instead of void. That does not look that super sexy anymore, but works. :-/

这篇关于Managed Bean as Facelet参数使复合组件无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆