首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >托管Bean作为Facelet参数允许组合组件阻止解析

托管Bean作为Facelet参数允许组合组件阻止解析
EN

Stack Overflow用户
提问于 2013-11-26 14:08:07
回答 2查看 1.8K关注 0票数 5

在给定的情况下,我希望使用具有不同ManagedBeans的facelet,因此可以将有关action-bean作为参数:

代码语言:javascript
复制
<?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>

我将create操作作为参数value="#{myOneCreateAction}"

在这个facelet中,还有一个组件也在其他页面上使用过几次--所以我尝试在复合组件中重构它。

代码语言:javascript
复制
<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}"提供给组件。该组件本身如下所示:

代码语言:javascript
复制
<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

代码语言:javascript
复制
Name("myOneCreateAction")
@Scope(ScopeType.CONVERSATION)
public class MyOneCreateAction {
   ...
   public void removeRating(ActionEvent ev) {
        // do something
   }
   ...
}

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

代码语言:javascript
复制
javax.faces.event.AbortProcessingException: Target Unreachable, 
      identifier 'createAction' resolved to null

而不是。我正在使用带有Seam 2.3.1.CR1的Mojarra JSF 2.1.26。没有嵌套的复合组件。当将复合组件参数替换为#{myOneCreateAction.removeRating}时,它的工作方式与预期的一样。

有人见过这个吗?我瞎了吗?任何已知的工作.?提前感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-16 14:33:36

作为一种解决方案,我重写了组件,将action bean和action方法作为两个单独的参数进行解析,如下所示

xhtml:

代码语言:javascript
复制
<io:removeButton
             id="removeButton"
             actionBean="#{createAction}"
             actionMethod="removeRating"
             immediate="true"
             render=":#{rich:clientId('ratingTblId')}" />

复合构件:

代码语言:javascript
复制
<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。那看起来不再那么性感了,但是很管用。*-/

票数 1
EN

Stack Overflow用户

发布于 2019-06-20 20:22:08

我也有同样的问题,发现它已经在版本2.2.15:https://github.com/javaserverfaces/mojarra/issues/4271上被修复了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20219326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档