Conditional XHTML attribute in JSPX

Discussion in 'Java' started by 3W, Apr 8, 2004.

  1. 3W

    3W Guest

    Is there any way to have a conditional attribute on an XHTML element,
    using JSPX (JSP in XML syntax)? Or any taglibs that'll do it?
    More specifically, defining selected="selected" or checked="checked",
    etc.

    TIA,
     
    3W, Apr 8, 2004
    #1
    1. Advertisements

  2. 3W

    Enrique Guest

    Would you provide an example of the desired output, and the conditions
    that must be met for each?
     
    Enrique, Apr 9, 2004
    #2
    1. Advertisements

  3. 3W

    3W Guest

    public class SomeBean {
    boolean checked;
    public boolean isChecked() {
    return isChecked;
    }
    }

    Then in JSPX I would like the checkbox to be dependant on isChecked():

    <input type="checkbox" name="someCheckbox"/>
    or
    <input type="checkbox" name="someCheckbox" checked="checked"/>
     
    3W, Apr 10, 2004
    #3
  4. 3W

    Enrique Guest

    Would this do?

    <jsp:scriptlet>
    if (myBean.isChecked())
    {
    </jsp:scriptlet>
    <input type="checkbox" name="someCheckbox" checked="checked" />
    <jsp:scriptlet>
    }
    else
    {
    </jsp:scriptlet>
    <input type="checkbox" name="someCheckbox" />
    <jsp:scriptlet>
    }
    </jsp:scriptlet>
     
    Enrique, Apr 17, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.