0
votes

I need you to recommend me a JSF component that can help in the following scenario(I will first paste an image that will help me explain): enter image description here

This page that you see in the image is a registration page, each of the panels have different fields and gadgets, when the register button is clicked, a new user is saved into the database.

The problem i have is in the show buttons. The buttons on top of each panel when clicked should display one panel and hide the other, but they must not trigger the field validation.

I use field validation by the attribute "validator"(in combination with a backing bean method) that most of JSF input fields have. Currently everything that you see there is inside one h:form.

-what should i do to display a panel and hide the other without triggering the validation of the panel that is hiding?

-Is there another alternative to the h:commandLink or h:commandButton(they trigger the validation)?

-Putting each panel in a different h:form can do the trick?(Is that permited?)

-What do you think would be the best approach?

4
Are the form contents of both panels related to each other? I.e. a real submit must take the data of both panels into a single managed bean?BalusC
No they are different. One belongs to an entity called buyer and another to an entity called Seller. Also i have 2 different managed beans being called in that page. At the moment i managed to do what i want ussing different forms, and using an accordion primefaces.org/showcase/ui/accordionPanel.jsf i would like to replace this component with the idea above. The comment that nikki said is ok and it works but i dont want to have that javascript syntax visible in my page. Any ideas?javing
If they are different and independent from each other, each definitely needs to go in its own <h:form>. You should not put everything in single big form. I'm not posting this as an answer because that's already been answered.BalusC
Yes has different forms, as Jitesh said. That is correct now, validation from one panel don't disturb the other. The only thing missing is i don't know how to show and hide the panels when i click on the button. Is there other alternative than what Nikhil Patil said? Thanksjaving
I'm not sure if I understand you. The <p:tabView> in combination with (default) ajax magic already does that. Or are you actually not using <p:tabView>?BalusC

4 Answers

3
votes

Use p:tabView Of primefaces, then put your contents(registration panels) in separate tab, use separate form for both of the tab, it will solve your problem....

e.g.

 <p:tabView>
        <p:tab title="panel1">
            <h:form id="form1" prependId="false">
                <h:inputText label="Sample Label"/>
                <p:commandButton value="register"/>
            </h:form>
        </p:tab>
        <p:tab title="panel2">
            <h:form id="form2" prependId="false">
                <h:inputText label="Sample Label"/>
                <p:commandButton value="register"/>
            </h:form>
        </p:tab>
    </p:tabView>
1
votes

-what should i do to display a panel and hide the other without triggering the validation of the panel that is hiding?

Use two h:form

s there another alternative to the h:commandLink or h:commandButton(they trigger the validation)?

to make POST you must only use them

I would have used rich:modalpanel for this purpose

1
votes

For the panel's toggle, Why don't you use JavaScript?

<h:commandButton value="Show panel 1" onclick="$('#panel1').hide();$('#panel2').show();return false;"/>

The return false will restrict the page from submitting, hence page won't refresh and since no data is posted back to server, validation phase will never execute.

Bottom line : IMHO this can be handled at client side itself.

0
votes

You are aware of the immediate attribute, allowing to refresh without changing data.

Unfortunately it doesn't remember changes entered, so you might end up in the validation explicitly being done in your action instead of by JSF itself.