Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:42:22+00:00 2026-05-27T15:42:22+00:00

I am not sure about the correct way to deal with method expressions in

  • 0

I am not sure about the “correct” way to deal with method expressions in composite components.

My composite uses a backing class with action methods. Theses perform some default actions or delegate to an action method passed by the composite user as an attribute:

In using page:

<my:component action="#{myBean.actionMethod}" />

Composite:

<cc:interface componentType="mycomponentType">
  <cc:attribute name="action" method-signature="java.lang.String action()" required="false" />
</cc:interface>

<cc:implementation>
  <h:commandButton value="submit" action="#{cc.componentAction}" />
</cc:implementation>

Backing class:

@FacesComponent("mycomponentType")
public class UIMyComponent extends UINamingContainer {   

public String action() {
    String outcome = "";

    ValueExpression ve = getValueExpression("action");
    String expression = ve.getExpressionString();

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Application application = facesContext.getApplication();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory = application .getExpressionFactory();

    MethodExpression methodExpression = expressionFactory.createMethodExpression(elContext, expression, String.class, new Class[0]);

    outcome = (String) methodExpression.invoke(elContext, new Object[0]);

    if (outcome.equals("whatever")) {
        // set another outcome
    }


    return outcome;

}

}

The code above is working as expected, but I find it rather bulky and it creates a ValueExpression to retrieve the method-expression from the declared “action” attribute.

UIComponentBase offers getValueExpression("attributeName") but there is nothing similar for MethodExpressions.

So my Question is if there is a better way to evaluate MethodExpressions declared as attributes in composite components than the code above.

Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:42:22+00:00Added an answer on May 27, 2026 at 3:42 pm

    Get it as attribute instead of as value expression.

    So, instead of

    ValueExpression ve = getValueExpression("action");
    

    do

    MethodExpression me = (MethodExpression) getAttribute("action");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still not sure this is the correct way to go about this, maybe
I'm not sure about clarity of the STAR word. I'm implementing a search method
I'm new to MVC (MVC3) so not sure about the best way to implement
This can be a little tricky and I'm not sure if it's correct way.
I'm not so sure about correct casts, here especially from unsigned int and #defines
I am not sure about how NSSet's anyObject work. What does it mean that
I am not sure about the exact purpose of the following Rampion's code .
I am not sure about some things in OOP. If I have Class1 ,
I'm not sure about one thing. There are two things in object oriented programming.
I am relatively new to OOP so I am not sure about the terminology.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.