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

  • Home
  • SEARCH
  • 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 8545437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:47:27+00:00 2026-06-11T12:47:27+00:00

I am developing a component containing an AJAX client behavior. The behavior depends on

  • 0

I am developing a component containing an AJAX client behavior. The behavior depends on the parameters provided to the component (e.g. render and execute targets). Due to performance reasons I do not want to realize the component using facelet based composite components.

My question is, when the client behavior shall be added to the component. If I call addClientBehavior() in the encodeBegin() method, I receive a NullPointerException in UIComponentBase.restoreBehaviorsState(). If I add the behavior at construction time, the ajax request works, however the parameters are not yet available. Is there a suitable method or event when to properly add the behavior?

I use mojarra 2.1.7. Below is a short example of my component without the dynamic ajax stuff:

@FacesComponent(value="simpleTestLink")
public class SimpleTestLink extends HtmlCommandLink{


    private Logger logger=LoggerFactory.getLogger(getClass());
    private AjaxBehavior ajax;

    enum PropertyKeys{aProp};

    public SimpleTestLink() {
        logger.debug("SimpleTestLink created");
        // adding ajax here works, but no parameters available yet
        ajax = new AjaxBehavior();
        ajax.setExecute(Arrays.asList(new String[]{"@this"}));
        ajax.setRender(Arrays.asList(new String[]{"@form"}));
        addClientBehavior(getDefaultEventName(), ajax);

    }

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        logger.debug("encodeBegin num: " + getAttr());
        // adding ajax here fails
        super.encodeBegin(context);
    }

    @Override
    public boolean getRendersChildren() {
        return true;
    }

    @Override
    public void encodeChildren(FacesContext context) throws IOException {
        Object attr = getAttr();
        HtmlOutputText outputText = new HtmlOutputText();
        outputText.setValue("testlink["+ attr+"]\n");
        outputText.encodeAll(context);
        super.encodeChildren(context);
    }

    private Object getAttr() {
        return getAttributes().get(PropertyKeys.aProp.name());
    }

}

Thanks for any help,
Jens

  • 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-11T12:47:28+00:00Added an answer on June 11, 2026 at 12:47 pm

    Yes, the ‘suitable method or event’ is called PreRenderViewEvent. I’ve blogged how to use it here: http://blog.kennardconsulting.com/2010/10/safely-manipulating-component-tree-with.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a server component that will serve requests for a embedded client, which
I am developing a Joomla component and one of the views needs to render
I am developing a component for Joomla website. This website has a sophisticated template
I am developing a component to create bespoke BulkImport functionality in ASP.NET. Underline this
I am developing a component in J! 2.5 and want to add a browse
I am developing a quiz component in Javascript and I have a startTimer() function
I'm developing a software component responsible for testing if a network interface has conectivity
Considering this article Developing a MVC component for Joomla , following is the code
I am evaluating raphaeljs (SVG/VML) for developing a similar component like Flicr Map or
I'm developing a XPCOM C++ component that have to use some RegExps functions Does

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.