Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3158

XSLT cannot render a collection that contains a null value.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.6
    • Fix Version/s: 2.1.8
    • Component/s: Other
    • Labels:
      None
    • Environment:

      NA

    • Flags:
      Patch

      Description

      For example a action class

      public class TestListNullEntry implements Action{

      private List testList = new ArrayList();

      public String execute() throws Exception

      { testList.add("entry1"); testList.add(null); testList.add("entry3"); return this.SUCCESS; }

      public List getTestList()

      { return testList; }

      }

      This action is unable to render a xslt result because of the null entry.

      Code changes to fix this problem.

      Index: C:/apache/struts/core/src/main/java/org/apache/struts2/views/xslt/AdapterFactory.java
      ===================================================================
      — AdapterFactory.java (revision 651946)
      +++ AdapterFactory.java (working copy)

      • public Node adaptNullValue(BeanAdapter parent, String propertyName) {
        + public Node adaptNullValue(AdapterNode parent, String propertyName) { return new StringAdapter(this, parent, propertyName, "null"); }

      Also changes needed in

      Index: C:/apache/struts/core/src/main/java/org/apache/struts2/views/xslt/CollectionAdapter.java
      ===================================================================
      — CollectionAdapter.java (revision 651946)
      +++ CollectionAdapter.java (working copy)

      for (Object value : values) {

      • Node childAdapter = getAdapterFactory().adaptNode(this, "item", value);
        + Node childAdapter;
        + if (value == null) { + childAdapter = getAdapterFactory().adaptNullValue(this, "item"); + }

        else

        { + childAdapter = getAdapterFactory().adaptNode(this, "item", value); + }

      if (childAdapter != null)
      children.add(childAdapter);

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              smwolke Steve Wolke
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: