开发者

How to disable a submit button until other button has been pressed?

开发者 https://www.devze.com 2023-04-06 12:58 出处:网络
I have a simple JSF form: <h:form> <h:inputText value=\"#{textBean.firstName}\"/> <h:inputText value=\"#{textBean.lastName}\"/>

I have a simple JSF form:

<h:form>
   <h:inputText value="#{textBean.firstName}"/>
   <h:inputText value="#{textBean.lastName}"/>
   <h:commandButton value="confirm" action="textBean.confirm"/>
   &l开发者_如何学运维t;h:commandButton value="submit" action="textBean.submit"/>
</h:form>

It is necessary that before you click "submit" user must press the button "confirm". Otherwise, next to the button "submit" display an error message. A user can not click the submit button, if not pre-pressed to confirm. It is very desirable to do it on a layer of the UI. Some might suggest something about this?


You might want to change the logic so that on click of the submit button a confirmation dialog box is presented to the user. Something simple like this:

<h:form>
   <h:inputText value="#{textBean.firstName}"/>
   <h:inputText value="#{textBean.lastName}"/>
   <h:commandButton value="submit" action="#{textBean.submit}" onclick="return confirm('Confirm form submit?');"/>
</h:form>

Otherwise if you want to get the behaviour mentioned above you could disable / hide the submit button until the user has clicked the confirm button, something like:

<h:form>
   <h:inputText value="#{textBean.firstName}"/>
   <h:inputText value="#{textBean.lastName}"/>
   <h:commandButton value="confirm" action="#{textBean.confirm}"/>
   <h:commandButton value="submit" action="#{textBean.submit}" disabled="#{textBean.btnDisabled}"/>
</h:form>

The disabled attribute can be replaced with the rendered attribute if you want to hide the button. It takes a boolean. This boolean variable can be set in your confirm method to true so that when the request comes back the button will be enabled.

0

精彩评论

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

关注公众号