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 9206601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:12:37+00:00 2026-06-18T00:12:37+00:00

Hello I want to implement a CC similar which implements a selection attribute. This

  • 0

Hello I want to implement a CC similar which implements a selection attribute. This is similar to to Primefaces instant row selection <p:dataTable selection="#{bean.user}" .../>.

This are the relevant definitions in the composite:

<composite:interface componentType="my.CcSelection">
  <composite:attribute name="actionListener" required="true"
          method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)"/>
  <composite:attribute name="selection"/>
</composite:interface>

<composite:implementation>
  ...
  <ui:repeat var="item" value="#{cc.attrs.data}">
    <p:commandLink actionListener="#{cc.actionListener(item)}"/>
  </ui:repeat>
  ...
</composite:implementation>

The actionListener-method in the backing bean is the following:

public void actionListener(MyObject object)
{
  logger.info("ActionListener "+object); //Always the correct object
  FacesContext context = FacesContext.getCurrentInstance();

  Iterator<String> it = this.getAttributes().keySet().iterator();
  while(it.hasNext()) {   //Only for debugging ...
    logger.debug(it.next());
  }

  // I want the set the value here
  ValueExpression veSelection = (ValueExpression)getAttributes().get("selection");
  veSelection.setValue(context.getELContext(), object);

  // And then call a method in a `@ManagedBean` (this works fine)  
  MethodExpression al = (MethodExpression) getAttributes().get("actionListener");
  al.invoke(context.getELContext(), new Object[] {});
}

If I use my CC with a value-expression for selection (e.g. selection="#{testBean.user}", veSelection is null (and selection is not printed in the debug-iteration) and I get a NPE. If I pass a String (e.g. selection="test", the attribute selection is available in the debug-iteration, but (of course) I get a ClassCastException:

java.lang.String cannot be cast to javax.el.ValueExpression

How can I provide a actionListener and a selection attribute to my component, and set the selected value in the first step and then invoke the actionListener?

  • 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-06-18T00:12:38+00:00Added an answer on June 18, 2026 at 12:12 am

    As to the debug-iteration, you won’t see value expressions in keyset nor entryset of UIComponent#getAttributes(). This is also explicitly mentioned in javadoc. In other words, that map contains only entries having static values. Only if you explicitly call get() on the map, and the underlying attribute is a value expression, then it will actually invoke it and return the evaluated value.

    In order to get a value expression, use UIComponent#getValueExpression() instead.

    ValueExpression selection = getValueExpression("selection");
    

    As to the method expression, well, that’s the easiest if your composite extends from UICommand, but this is in your particular case plain clumsy. Just set the target of the listener method to the command link and use <f:setPropertyActionListener> to set the desired property in the bean. This way the backing component is unnecessary.

    <composite:interface>
      <composite:attribute name="actionListener" required="true" targets="link"
              method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)"/>
      <composite:attribute name="selection"/>
    </composite:interface>
    
    <composite:implementation>
      ...
      <ui:repeat var="item" value="#{cc.attrs.data}">
        <p:commandLink id="link">
          <f:setPropertyActionListener target="#{cc.attrs.selection}" value="#{item}" />
        </p:commandLink>
      </ui:repeat>
      ...
    </composite:implementation>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a simple button in PyQt which prints Hello world when
Hello I want to read output of command which gives progress bar like output
Hello i want to replace the text in div when user click on it
I have a onclick function like this onclick = function(){alert('hello')} I want to add
HellO, I want to write a binary file format viewer for windows which can
I was following this example: http://developer.android.com/resources/tutorials/views/hello-autocomplete.html And I want to know how I can
I am making simple browser. I want to implement a search box which will
hello i want i have function to get paragraph of selected text. this is
Hello, I'd like to implement a similar visual effects as iTunes plays music. I'm
I want to Implement this type of View in My Application. . . data1

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.