2

I'm implementing a custom component with composite. The source code of my composite compoment is only as follow:

<cc:interface componentType="selectOneRadio"
              xmlns="http://www.w3.org/1999/xhtml"   
              xmlns:cc="http://java.sun.com/jsf/composite">
    <cc:attribute name="direction" default="next" />
</cc:interface>

as you can see I don't use the implementation section, but it is no problem for me if I have to use it.

Then, I render it's content with Java as follows:

public void encodeChildren(FacesContext context) throws IOException {
   ...
}

This control will generate an integer value based on the value of the attribute with name: "direction". If it's value is "next" then the generated value is the current day of the month plus 1 and if it's value is "back" then the generated value is the current day of the month minus 1.

I would like to know how could I pass that generated value to the backing bean when the user clicks on a <h:commandButton /> I add after my custom component?

Do I need to use <f:ajax /> or something like that?

Other question by the way, could I render my composite component with Java and <cc:implementation /> at the same time (mixing)?

Thanks.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Angel
  • 155
  • 1
  • 1
  • 14

1 Answers1

0

You need to perform the form submit processing job in the decode() method.

@Override
public void decode(FacesContext context) {
    // ...
}

You could get an attribute as a ValueExpression by the inherited getValueExpression() method. You can perform a "set" operation using ValueExpression#setValue(). E.g.

<my:composite ... value="#{bean.foo}" />

with

ValueExpression value = getValueExpression("value");
value.setValue(context.getElContext(), newValue);

will set newValue accordingly on the property represented by #{bean.foo}.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi @BalusC, with your suggestions above I can pass the generated value to the backing controller, thank you. But with my question above I simplified my real situation too much and then I need a little complement to your answer. My real situation is [here](http://stackoverflow.com/questions/12526211/how-to-render-a-composite-component-using-a-custom-renderer) and I need to get (inside the decode method) the value of the selected: ``. Each `` is rendered as a radio button (` – Angel Oct 09 '12 at 00:52
  • Inside decode, you are supposed to grab the submitted value from the request parameter map. E.g. `externalContext.getRequestParameterMap().get(clientId)`. – BalusC Oct 09 '12 at 00:53
  • thank you very much @BalusC, now it is working pretty good ;) – Angel Oct 09 '12 at 01:08
  • You're welcome :) I forgot to add, model value actually needs to be updated in `processUpdates()` method override. This will only be invoked when the validation has passed. – BalusC Oct 09 '12 at 01:11
  • So, do I have to move: `ValueExpression value = getValueExpression("value"); value.setValue(context.getElContext(), newValue);` from `decode(...)` method to `processUpdates()` method?. As I have it right now it works, but I don't know if it is more advisable to move there? – Angel Oct 09 '12 at 01:43