2

Possible Duplicate:
Primefaces commandButton in custom component action listener not called

I have created custom component which extends UIComponentBase. I am creating some component in encodeBegin (CommandButton from Primefaces), but when is decode triggered by user clicking button when I look for button it is not present in UIViewRoot and not in this.getChildren().

It seems that it is a new instance of component invoked when decode is trigered and components are not present. What is wrong?

Some code is in: code

If you want I can send whole code.


I found that this technique is used in PrimeFaces and other software, but can you explain why values retrieved from getStateHelper().eval("someKey"); are always null in decode?

Probably problem on my site, but I can not solve it?

This is link to thread I started:

problem description in more details

Community
  • 1
  • 1
user1638291
  • 49
  • 2
  • 8

1 Answers1

1

It seems that it is a new instance of component invoked when decode is trigered and components are not present.

That's correct. Component instances are not stored in the view state. Instead, the component's state is stored in the view state. The component's state can be managed by the helper class StateHelper which is available by UIComponent#getStateHelper().

So, during encode do:

// ...
getStateHelper().put("someKey", someKey);

And during decode do:

SomeKey someKey = (SomeKey) getStateHelper().eval("someKey");
// ...

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Can you explain why values retrieve from getStateHelper().eval("someKey"); are always null in decode? – user1638291 Jan 08 '13 at 08:05
  • This should not happen. Is the component declared in the view or are you manually creating it? The latter would explain it. – BalusC Jan 08 '13 at 10:50
  • I am creating it manually in my custom component. – user1638291 Jan 08 '13 at 11:02
  • You should not manually create the custom component. The custom component should be created by the view. – BalusC Jan 08 '13 at 11:10
  • I have it in my site: and inside of this component I am creating commandButton – user1638291 Jan 08 '13 at 11:32
  • Well, if you're using `StateHelper#put()` in encode, then it should definitely be able by `StateHelper#eval()` or `get()` in decode of the postback. If it isn't, then perhaps you're not performing a postback. – BalusC Jan 08 '13 at 11:34