Announcement Announcement Module
Collapse
No announcement yet.
Problem with Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with

    Hi there.

    Here is my problem..

    Im having difficulty with setting the selected attribute for the option element in a <select> using jspx.

    2 ways I tried:

    1.
    <select name="customername">
    <c:forEach items="${customers}" var="cust">
    <option value="${cust.name}" ${cust.name == status.value ? ' selected' : ''}>${cust.name}</option>
    </c:forEach>
    </select>

    Error: Element type "option" must be followed by either attribute specifications, ">" or "/>".
    I cannot do it in this way because jspx is xml based.

    2.
    <select name="customername">
    <c:forEach items="${customers}" var="cust">

    <jsp:element name="option">
    <jsp:attribute name="value">${cust.name}</jsp:attribute>
    <c:if test="${cust.name == status.value}">
    <jsp:attribute name="selected">true</jsp:attribute>
    </c:if>
    ${cust.name}
    </jsp:element>

    </c:forEach>
    </select>

    Error: Attribute selected invalid for tag if according to TLD
    TLD does not allow this.

    If anyone could give me advise on how to fix this or have another way of doing this. Help will be appreciated.

    Gawie

  • #2
    Hi. Fixed my problem. If any one else working with jspx's have this problem, this is what I did in the end. I used the the jakarta-input-taglibs.

    My controller:
    java.util.HashMap a;
    java.util.Hashtable o;
    java.util.TreeMap map;
    // Pupulate Cutomer and set it according to the Order.Customer object //
    a = new java.util.HashMap();
    a.put("onchange", "submit();");
    List customers = custMan.getCustomers();
    o = new java.util.Hashtable();
    o.put("--Select--", "");
    for(int x = 0; x < customers.size(); x++){
    Customer cust = (Customer) customers.get(x);
    o.put(cust.getName(), cust.getId());
    }

    map = new java.util.TreeMap(o);

    model.put("CustNames",map);
    model.put("CustAttributes",a);

    My jspx:
    <td>Customer Name: </td><!-- Maak reg die goed -->
    <spring:bind path="Order.customer.id">
    <td>
    <input:select name="${status.expression}" default="${Order.customer.id}"
    attributes="${CustAttributes}" options="${CustNames}" />
    </td>
    <td>
    <font color="red"><c:out value="${status.errorMessage}"/></font>
    </td>
    </spring:bind>

    Comment

    Working...
    X