0

I'm having some trouble for a couple days, and we can't find on the web a good way of solving it. So i I'll put here and hope anyone can help me and others with same problem.

We have a big form with some p:selectOneMenu components on it. When the user wants an extra option he can click on the plus button on the side of a component, to be redirected to a new page to create and save on db the new option.

We made it work very well using a keepAlive function that holds a desired object through the screens. But we have some required fields that are blocking the plus button when blank.

Switching the button to immediate="true" doesn't really helped because then the fields are not being passed to the attributes.


So what we need is a way of passing the fields to the attributes so we can keep across screens even when some required fields are blank! Does anyone have an idea that might work?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Thpramos
  • 441
  • 4
  • 15
  • "keepAlive function"? How exactly? This term is typically used in JSF 1.x + RichFaces context, not in JSF 2.x + PrimeFaces context. – BalusC Nov 06 '12 at 17:12
  • It's basically a function to hold an object in the session while going to a new form and coming back later. Then we allow the user to create a new option for the combo box and return without loosing the filled fields. Is there any better solution on JSF 2.x ? – Thpramos Nov 13 '12 at 17:42
  • Yes. Just put the bean in the view scope using `@ViewScoped`. See also http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope/7031941#7031941 – BalusC Nov 13 '12 at 21:50

1 Answers1

2

Just let the required attribute evaluate true only when the save button is really pressed.

<c:set var="saveButtonPressed" value="#{not empty param['form:save']}" />

<h:form id="form">
    <p:selectOneMenu ... required="#{saveButtonPressed}" />
    <p:inputText ... required="#{saveButtonPressed}" />
    ...
    <p:commandButton id="save" ... />
</h:form>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Maan that's simple! I'm impressed how it's simple. I spent so much time finding a workaround by putting ajax change listeners inside every single component. This will make the page much more stable. Thank you very muuch! – Thpramos Nov 13 '12 at 17:33