开发者

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

开发者 https://www.devze.com 2023-02-22 07:27 出处:网络
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):

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):

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

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 datab开发者_如何学Goase.

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?


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>


-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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号