javing
javing

Reputation: 12423

I need a button that performs an action but doesn't trigger validation or refreshes the page(JSF 2.0)

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?

Upvotes: 0

Views: 923

Answers (4)

Jitesh
Jitesh

Reputation: 1382

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>

Upvotes: 3

Niks
Niks

Reputation: 4842

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.

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240928

-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

Upvotes: 1

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.

Upvotes: 0

Related Questions