unchecking a checkbox in a visual web jsf page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Silgd1
    New Member
    • Sep 2007
    • 25

    unchecking a checkbox in a visual web jsf page

    Hey All...

    I have visual web jsf page, developed in netbeans 6.0, and it has a layout panel which contains three(3) checkboxes of the woodstock component variety. If a user checks one of the checkboxes and then decides to check another, I want the previously checked checkbox to become unchecked. Is this possible?? Please provide some example code if it is.

    Thanks...

    Silgd
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    So, you have three JCheckBoxes and you only want one to be selected at any time? Why don't you use Radio buttons? Here's the Java API for the JRadioButton and here's a HowTo for the three main kinds of button ("normal" buttons, CheckBoxes and Radio buttons).

    Greetings,
    Nepomuk

    Comment

    • ajos
      Contributor
      • Aug 2007
      • 283

      #3
      Originally posted by Nepomuk
      So, you have three JCheckBoxes and you only want one to be selected at any time? Why don't you use Radio buttons? Here's the Java API for the JRadioButton and here's a HowTo for the three main kinds of button ("normal" buttons, CheckBoxes and Radio buttons).

      Greetings,
      Nepomuk
      Err..Nepo this is not related to Swings. Its regarding to jsf components ;)

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by ajos
        Err..Nepo this is not related to Swings. Its regarding to jsf components ;)
        Ah sorry, in that case no JCheckBoxes or JRadioButtons, but I'm sure there will be some kind of Radio buttons available in JSF.

        ...

        There, found something. Look at this code:
        Code:
        <f:use_faces>
            <h:form formName="pform">
                ..........
                <p><h:output_text value="Alignment:"/><br>
                <h:selectone_radio id="align" valueRef="pbean.align"
                        layout="LINE_DIRECTION">
                    <f:validate_required/>
                    <h:selectitem itemValue="left" itemLabel="Left"/>
                    <h:selectitem itemValue="center" itemLabel="Center"/>
                    <h:selectitem itemValue="right" itemLabel="Right"/>
                </h:selectone_radio>
                <br><h:output_errors for="align"/>
                ..........
            </h:form>
        </f:use_faces>
        It will generate this HTML code: [code=html]<form method="post" action="/usingjsf/faces/edit.jsp">
        ..........
        <p>Alignment:<b r>
        <table border="0">
        <tr>
        <td><input type="radio" checked
        name="align" value="left"> Left</td>
        <td><input type="radio"
        name="align" value="center"> Center</td>
        <td><input type="radio"
        name="align" value="right"> Right</td>
        </tr>
        </table>
        <br>
        ..........
        </form>[/code] There you go, radio buttons. They should work fine. :-)

        Greetings,
        Nepomuk <--- doesn't know much about JSF shamefully

        Comment

        Working...