0

I'm designing a custom component in JSF after I decided that the task to be solve is way too complicated for a composite component and started with the following approach:

@FacesComponent("offervaluescustom")
public class OfferValuesCustom extends UIComponentBase {

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.startElement("table", this);
        //a lof of code
        writer.endElement("table");
    }
}

I'm using PrimeFaces as JSF implementation and was wondering how I could write an element to the response writer programmatically instead of copying the generated HTML code which is a valid workaround, but not portable and an unnecessary repitition of work.

The reason I'm using a recursive component is conditional spanning of columns in some rows, but not in others, as well as difficult recursion which is trivial in encodeBegin, but complex in cc:implementation because of scope issues (render vs. view).

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • What is your exact goal? Whithin your "encodeBegin" Method, you should generate the HTML-Output required for YOUR component... and nothing more. The requirement to "include" other stuff is an indication, that a composite component might be the way to go! (They can have their own `BackingBean` and be referenced through their own `taglib` as well...) Your example doesn't outline any needs for a custom Component. – dognose May 03 '18 at 00:40
  • @dognose I added an explanation to the question. I started a composite component approach, but I don't make any progress because of a large amount of issues (variables disappearing, i.e. being set to `null` and `""` without any logical explanation and no idea how to handle the conditional column spanning). – Kalle Richter May 03 '18 at 07:23
  • You miss to point out the concrete problem. Try to focus on your main issue (could be conditional column spanning?) and write a custom component that tries to fulfill this requirement. Forget about the rest of the problem (`//a lot of code` is something that a person who answers your question needs to guess). If you have some issue with that, you can post it here, but with a working example. Once you've got a basic component to get started it shouldn't be as difficult to port it to your case. – Aritz May 03 '18 at 09:26
  • @dognose I get the point. It just seemed easier to implement a larger component as custom component, see https://stackoverflow.com/questions/50170881/stackoverflow-in-jsf-composite-component-recursion in case you're interested. – Kalle Richter May 04 '18 at 09:14

0 Answers0