标签: methodexpression

如何使用JSTL/EL从JSP调用参数化方法

如何使用JSTL/EL从JSP调用Java类中定义的参数的Java方法.该方法返回数组.可以使用任何返回值.

jsp jstl el parameter-passing methodexpression

44
推荐指数
2
解决办法
7万
查看次数

如何记录JSF ajax请求的方法表达式

我已经弄清楚如何在过滤器中记录请求是ajax请求以及它来自哪个页面.

我真正想做的是记录ajax请求实际上是什么.例如ajax调用的方法的名称(例如,此调用中的"findAddress" <p:ajax process="contactDetails" update="@form" listener="#{aboutYouController.findAddress}" ....):

我怎样才能做到这一点?我的应用程序有很多ajax请求,我想记录哪些是被触发的.

public class TrackingFilter implements Filter {

private static Logger LOG = Logger.getLogger(TrackingFilter.class);

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {    

    HttpServletRequest req = (HttpServletRequest) request;

    String pageHit = req.getRequestURI().substring(req.getContextPath().length()+1).replace(".xhtml", "");
    if(!pageHit.contains("javax.faces.resource")){ // if is a url we want to log
        if ("partial/ajax".equals(req.getHeader("Faces-Request"))) {
            LOG.trace("ajax on URI: " + req.getRequestURI());
        }
Run Code Online (Sandbox Code Playgroud)

ajax jsf logging methodexpression

8
推荐指数
1
解决办法
1059
查看次数

评估是否设置了MethodExpression属性(获取PropertyNotFoundException)

我有一个带有MethodExpression属性的UI组件changeListener:

<composite:interface>
  <composite:attribute name="changeListener" required="false" method-signature="void actionListener(javax.faces.event.ActionEvent)" />
  ..
</composite:interface>
<composite:implementation>

  <p:remoteCommand name="ajaxOnChange"
                             update="#{cc.attrs.onChangeUpdate}"
                             oncomplete="#{cc.attrs.onchange}"
                             actionListener="#{cc.attrs.changeListener}" />
  ..
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

changeListener属性是一个可选的方法表达式,在其中用作actionListenerremoteCommand,我想在<p:remoteCommand>changeListener设置属性的情况下呈现该属性.

我已经尝试了几种方法来检查属性是否设置,尤其是:

<c:if test="#{! empty cc.attrs.changeListener}">
Run Code Online (Sandbox Code Playgroud)

<p:remoteCommand rendered="#{cc.attrs.changeListener != null}" />
Run Code Online (Sandbox Code Playgroud)

但我得到一个javax.el.PropertyNotFoundException,因为它试图将属性评估为属性.

如何评估是否设置了可选方法属性?

谢谢

jsf conditional composite-component jsf-2 methodexpression

6
推荐指数
1
解决办法
1548
查看次数

如果JSF不支持,为什么我能够将<f:actionListener>绑定到任意方法?

我正在使用Glassfish 3.1.2.2和JSF Mojarra 2.1.6.

我有以下Facelets页面:

<h:form>
  <h:commandLink value="link">
    <f:actionListener binding="#{backingBean.someMethod(1)}"/>
  </h:commandLink>
</h:form>
Run Code Online (Sandbox Code Playgroud)

以下支持bean:

@RequestScoped
@ManagedBean
public class BackingBean {
  public void someMethod(int i) {
    System.out.println("It was called: " + i);
  }
}
Run Code Online (Sandbox Code Playgroud)

当我单击链接时,控制台中出现"Info:It called called:1".

binding读取文档:

图书馆:http://xmlns.jcp.org/jsf/core,http://java.sun.com/jsf/core(Jsf Core)

标签:actionListener

捆绑

值绑定表达式,其值为实现javax.faces.event.ActionListener 的对象.[强调我的]

此外,该问题的接受答案表明,f:actionListener调用任意方法是不可能的.

如果不支持,为什么调用backing bean方法?

jsf binding el actionlistener methodexpression

4
推荐指数
1
解决办法
2017
查看次数

在EL中动态调用方法,从String中计算

我有一个提交按钮.此提交按钮具有"操作"属性.但是这个action属性应该总是调用另一个函数(某种泛型).所以我想动态调用一个函数.这是因为我需要重用这个组件.我只是不知道action属性需要哪种Type(Method,String等?)以及如何正确引用想要的"BeanWithMethodToCall".

@Named
@SessionScoped
public class BeanWithMethodToCall{

   @Inject
   private BeanWhichIsCalledFromEL elBean;

   public void methodToCall(){
      //do something
   }

   public void someLogic(){
      // here the wanted method is set on the bean which is later on called from el
      elBean.setMethodToCall("methodToCall");
   }
}

@Named
@SessionScoped
public class BeanWhichIsCalledFromEL{

   // i don't know the correct type of this :S
   private String method;

   public void setMethodToCall(String method){
      this.method = method;
   }

   // i don't know the correct return type of this :S
   public String getMethodToExecute(){
      //this …
Run Code Online (Sandbox Code Playgroud)

jsf el dynamic commandbutton methodexpression

3
推荐指数
1
解决办法
994
查看次数

EL条件方法表达式

我想在EL中声明一个条件方法表达式,如下所示:

<p:dataTable id="#{cc.attrs.datatableId}" var="overview" 
    rowSelectListener="#{cc.attrs.detailsMode == 'single' ? cc.attrs.bean.onRowSelect : cc.attrs.bean.onRowUrlSelect}">
Run Code Online (Sandbox Code Playgroud)

但是,它抛出一个EL异常:

javax.el.E​​LException:不是有效的方法表达式:#{cc.attrs.detailsMode =='single'?cc.attrs.bean.onRowSelect:cc.attrs.bean.onRowUrlSelect}

我如何声明条件EL方法表达式?

jsf facelets el conditional-operator methodexpression

3
推荐指数
1
解决办法
5821
查看次数

org.apache.el.parser.ParseException:遇到"("在第X行,第Y列.期待其中一个[...]

以下JSF片段:

<p:dataTable value="#{userbean.getAll()}" var="user">
Run Code Online (Sandbox Code Playgroud)

引发此异常:

Encountered "(" at line 1, column 18. Was expecting one of: "}" ... "." ... "[" ... ">" ... "gt" ... "<" ... "lt" ... ">=" ... "ge" ... "<=" ... "le" ... "==" ... "eq" ... "!=" ... "ne" ... "&&" ... "and" ... "||" ... "or" ... "*" ... "+" ... "-" ... "/" ... "div" ... "%" ... "mod" ... 
org.apache.el.parser.ParseException: Encountered "(" at line 1, column 18. Was expecting one of: …
Run Code Online (Sandbox Code Playgroud)

jsf el parentheses parseexception methodexpression

3
推荐指数
1
解决办法
2万
查看次数

将EL方法表达式作为自定义Facelets标记文件的属性传递

我创建了一个自定义的JSF标记:

<ui:composition>
    <h:panelGroup>
        <rich:dataScroller id="#{id}" for="#{table}" execute="#{table}"
            page="#{scrollerPage}" render="#{table}-sc1" maxPages="5"
            fastControls="hide" oncomplete="#{onCompl}" scrollListener="#{scrollListenerBean[scrollListenerMethod]}" />
        <h:inputText value="#{scrollerPage}" id="#{table}-sc1" size="2">
            <f:convertNumber integerOnly="true" />
        </h:inputText>
        <h:outputText styleClass="outputText"
            value=" of #{scrollPagesCount}  " />
        <h:commandButton value="GO! " />
    </h:panelGroup>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

为了传递监听器方法,我使用了一个相当古老的博客中建议的解决方案:

<my:dataScroller id="idDS1" table="table1"
                    scrollerPage="#{bean.navigationHelper.scrollerPage}"
                    scrollPagesCount="#{bean.navigationHelper.scrollPagesCount}"
                    onCompl="initForm();" 
                    scrollListenerBean="#{bean}"
                    scrollListenerMethod="aMethod" />
Run Code Online (Sandbox Code Playgroud)

我的问题是:这是最好的方法吗?如何使方法可选?

非常感谢任何帮助!再见!

jsf facelets tagfile jsf-2 methodexpression

2
推荐指数
1
解决办法
1526
查看次数