4

I have a view-scoped bean that implements Serializable, and a UIComponent passed in via binding.

@ManagedBean
@ViewScoped
public class ViewScopedBean implements Serializable {
   UIComponent form;
   /// ... 
}

<h:form binding="#{viewScopedBean.form}"> ... 

The UIComponent is not serializable and thus breaking session restore.

What's the best practice here?

Should I just mark the UIComponents as transient? Or is it bad practice to use binding= to anything but a request-scoped bean?

I'm using Glassfish 3.1.1, Mojarra 2.1.3 and PrimeFaces 2.2.

wrschneider
  • 17,913
  • 16
  • 96
  • 176
  • Why do you need to bind the component to the bean? What's the functional requirement? There may be ways which allows you to achieve the functional requirement without the need to bind the component to the bean. – BalusC Dec 05 '11 at 21:47
  • So I can call component.resetValue() - opening a dialog and want to get rid of any state from prior invalid submissions. Another possibility I'd considered was getting a handle to the UIForm I want via the ActionEvent itself (`event.getComponent().getNamingContainer()`) which would eliminate the need for a binding. But that doesn't work when the link that opens my dialog is in a different form than the form I want to manipulate. – wrschneider Dec 05 '11 at 21:52
  • This reminds me of http://stackoverflow.com/questions/6642242/how-can-i-populate-a-text-field-using-primefaces-ajax-after-validation-errors-oc As to your concrete question, the answer would be "No, just don't bind components to the bean, unless really necessary.", but I don't really feel obligated to post that. – BalusC Dec 05 '11 at 22:05
  • I see that you asked a question about this before which explains why you're asking this question: http://stackoverflow.com/questions/8187306/how-can-i-reset-jsf-uiinput-components-to-their-managed-bean-values This can actually be solved in a simpler way, I posted an answer there. – BalusC Dec 05 '11 at 23:32
  • @BalusC - for this original question (binding UIComponents to form beans), I agree, even if I do need to call `component.resetValue`, your linked post using `PartialViewContext.getRenderIds` eliminates the need for the binding. – wrschneider Dec 07 '11 at 00:05

1 Answers1

1

Accepting @BalusC's suggestion to find another way to solve problem without binding.

wrschneider
  • 17,913
  • 16
  • 96
  • 176