Home > Articles

David's XMLC Tips

  • Print
  • + Share This

XMLC Tips

  1. XMLC supports two XML parsers for building a DOM template: the Xerces DOM and the LazyDOM, an XMLC enhancement subclass of the Xerces DOM. Although the LazyDOM usually delivers superior performance, thanks to its capability to instantiate only selected portions of the DOM, the Xerces DOM might perform better if your page is extensively dynamic.

  2. Sometimes you just cannot figure out why your resultant markup is coming out the way it is. Use the DOMInfo class as a runtime approach to dumping the current state of your page template at any point once it has been factory loaded. Here's an example of using DOMInfo to take a look at a portion of a page template dealing with a single row in an HTML table.

  3. import org.enhydra.xml.dom.DOMInfo;

    PrintWriter out = newPrinterWrite(new OutputStreamWriter(System.out, "UTF-8"));
    myPageHTML page = (myPageHTML) xmlc.getFactory().create(myPageHTML.class);
    Node subTemplate = myPage.getElementCustomerRow();
    DOMInof.printTree("Customer Row template", subTemplate,
       DOMInfo.PRINT_ATTR_DETAILS,out);
  4. A shortcoming of the DOM API is that it doesn't address JavaScript other than supporting the <script> element. So, how do you dynamically update a JavaScript without resorting to the ugly nature of shoving script into a CDATA section? One approach, among many, is to use hidden fields to set JavaScript variables later accessed by the JavaScript. This approach works great for JavaScript that performs client-side validation, such as checking a password for minimum length.

  5. For example, in your markup, you might have the following default value and associated message:

    <input type="hidden" name="passLen" value="8" id="passwordLength">
    <script language="javascript">
    document.write("Password length must be " + 
    document.loginForm.passwordLength.value);
    </script>

    In your Java code, the following will really let your users know you mean business.

    HTMLInputElement input = page.getElementPasswordLength();
    input.getAttribute("value").setValue("16");
  6. There's more than one way to reference XMLC's dynamic content labeling id attributes. If your table labeling id attribute is named "PartsTable," you can either use the hardwired named getElementPartsTable() or the more flexible getElementById method, as in "getElementById("PartsTable"). There is no performance penalty, and you can do robust coding with friendlier error checking. By checking the returned value of the getElementById() method, you can double check that the id attribute was not left out by the markup designer during a page maintenance revamp. Instead of dealing with a crash-and-burn situation when your code tries to invoke a nonexistent getElementPartsTable(), you instead alert the QA department that the expected PartsTable attribute is no longer there.

  7. Barracuda is the exciting new presentation framework for XMLC featuring client-type detection, forms handling and validation, and other common presentation-handling needs. But, with its comprehensiveness, it can be a little daunting. So, why not test the water by only using the portions of it that address immediate needs. For example, rather than mastering its hierarchical event handling or assortment of user interface components, why not just use the localization ant taskdef to better take advantage of its excellent automation of separating and organizing localized strings for markup pages?

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.