Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. <h:selecBooleanCheckbox id="box" value="#{mybean.selecteditem.booleanvalue}"......>
  2. <f:ajax execute="box" render="but" event="change" />
  3. </h:selectBooleanCheckbox>
  4.  
  5. <h:commandButton id="but" action="someAction" value="someValue" disabled="#{!mybean.selecteditem.booleanvalue}" />
  6.  
  7. <p:ajax event="change" process="box" update="but"/>
  8.  
  9. <f:ajax ......render="id1 id2 id3" />
  10.  
  11. public class TestBean {
  12.  
  13. private boolean chkBoxChecked;
  14.  
  15. public boolean isChkBoxChecked() {
  16. return chkBoxChecked;
  17. }
  18.  
  19. public boolean isBtnDisabled() {
  20. return !this.chkBoxChecked;
  21. }
  22.  
  23. public void setChkBoxChecked(boolean chkBoxChecked) {
  24. this.chkBoxChecked = chkBoxChecked;
  25. }
  26.  
  27. }
  28.  
  29. <ui:composition xmlns="http://www.w3.org/1999/xhtml"
  30. xmlns:ui="http://java.sun.com/jsf/facelets"
  31. xmlns:f="http://java.sun.com/jsf/core"
  32. xmlns:h="http://java.sun.com/jsf/html"
  33. xmlns:a4j="http://richfaces.org/a4j"
  34. xmlns:rich="http://richfaces.org/rich"
  35. template="/WEB-INF/template/default.xhtml">
  36.  
  37. <ui:define name="content">
  38. <h:form id="frmTest">
  39. <h:selectBooleanCheckbox id="chkBoolean" value="#{testBean.chkBoxChecked}">
  40. <a4j:support event="onclick" ajaxSingle="true" reRender="btnSubmit"/>
  41. </h:selectBooleanCheckbox>
  42. <h:commandButton id="btnSubmit" value="Submit" disabled="#{testBean.btnDisabled}"/>
  43. </h:form>
  44. </ui:define>
  45. </ui:composition>
  46.  
  47. <ui:composition xmlns="http://www.w3.org/1999/xhtml"
  48. xmlns:ui="http://java.sun.com/jsf/facelets"
  49. xmlns:f="http://java.sun.com/jsf/core"
  50. xmlns:h="http://java.sun.com/jsf/html"
  51. xmlns:a4j="http://richfaces.org/a4j"
  52. xmlns:rich="http://richfaces.org/rich"
  53. template="/WEB-INF/template/default.xhtml">
  54.  
  55. <ui:define name="head">
  56. <script type="text/javascript">
  57. window.onload = function() {
  58. btnSubmit = document.getElementById('btnSubmit');
  59. btnSubmit.disabled = #{testBean.btnDisabled};
  60. }
  61. </script>
  62. </ui:define>
  63.  
  64. <ui:define name="content">
  65. <h:form id="frmTest" prependId="false">
  66. <h:selectBooleanCheckbox id="chkBoolean"
  67. onclick="btnSubmit.disabled = !this.checked;"
  68. value="#{testBean.chkBoxChecked}"/>
  69. <h:commandButton id="btnSubmit" value="Submit"/>
  70. </h:form>
  71. </ui:define>
  72. </ui:composition>
  73.  
  74. <h:form id="myForm">
  75. <h:selectBooleanCheckbox id="check" onclick="document.getElementById('myForm:myButton').disable = !this.checked"/>
  76.  
  77. <h:commandButton id="myButton" .../>
  78. </h:form>
  79.  
  80. onclick="document.getElementById('myForm:myButton').disable = !document.getElementById('myForm:check').checked"
  81.  
  82. <script type="text/javascript">
  83. function checkClick(check) { document.getElementById('myForm:myButton').disable = check.checked; }
  84. </script>
  85. (...)
  86. <h:selectBooleanCheckbox id="check" onclick="checkClick(this)"/>
  87. (...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement