Loop parameter becoming null

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Loop parameter becoming null

Tyler Wilcock
Hi all.  I have some components being rendered in a loop.  On initial
render, everything comes out fine.  However, when I try to click on an
eventlink within one of the rendered components, I get an application
exception.  What is going wrong here?

---
SearchFilterContainer.java
---

public class SearchFilterContainer
{
   @Inject
   private SearchFilterService searchFilterService;

   @Property
   private SearchFilter currentFilter;

   public List<SearchFilter> getChronologicalSearchFilters()
   {
      return searchFilterService.getChronologicalFilters();
   }

   public String getPreFiltersText()
   {
      return messages.get("pre-search-filters-text");
   }

   public boolean isAssetStatusFilter()
   {
      return currentFilter.getFilterType() == SearchFilterType.ASSET_STATUS;
   }


---
SearchFilterContainer.tml
---

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
             xmlns:p="tapestry:parameter"
             xmlns:sf="tapestry-library:dam/search/filters">

<t:loop source="chronologicalSearchFilters" value="currentFilter"
formState="ITERATION">
    <t:if test="assetStatusFilter">
        <sf:refineassetstatusfilter
assetStatusRefineOption="currentFilter.getFilterValue()" />
    </t:if>
</t:loop>

</t:container>

---
RefineAssetStatusFilter.java
---

public class RefineAssetStatusFilter extends SearchComponent
{
   @Parameter(required=true)
   private AssetStatusRefineOptions assetStatusRefineOption;

   public String getFilterText()
   {
      return assetStatusRefineOption.getDisplayName();
   }

   public void onRemove()
   {
      // do stuff
   }
}

---
RefineAssetStatusFilter.tml
---

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<div class="search-filter rectangular-pill">
    ${getFilterText()}
    <t:eventlink event="remove" class="remove-filter-icon">&times;</t:eventlink>
</div>

</t:container>

---
Exception information
---
An unexpected application exception has occurred.

   - org.apache.tapestry5.ioc.internal.OperationException
   Failure reading parameter 'assetStatusRefineOption' of component
   dam/SearchResults:instantsearch.searchfiltercontainer.refineassetstatusfilter:
   Property 'currentFilter' (within property expression
   'currentFilter.getFilterValue()', of
   collective.app.dam.components.search.filters.SearchFilterContainer@48e53372)
   is null.
   locationclasspath:collective/app/dam/components/search/filters/SearchFilterContainer.tml,
   line 8
   3 xmlns:p="tapestry:parameter"
   4 xmlns:sf="tapestry-library:dam/search/filters">
   5
   6 <t:loop source="chronologicalSearchFilters" value="currentFilter"
   formState="ITERATION">
   7 <t:if test="assetStatusFilter">
   8 <sf:refineassetstatusfilter
   assetStatusRefineOption="currentFilter.getFilterValue()" />
   9 </t:if>
   10

   trace
      - Triggering event 'remove' on
      dam/SearchResults:instantsearch.searchfiltercontainer.refineassetstatusfilter
   - org.apache.tapestry5.runtime.ComponentEventException
   Failure reading parameter 'assetStatusRefineOption' of component
   dam/SearchResults:instantsearch.searchfiltercontainer.refineassetstatusfilter:
   Property 'currentFilter' (within property expression
   'currentFilter.getFilterValue()', of
   collective.app.dam.components.search.filters.SearchFilterContainer@48e53372)
   is null.
   contexteventTyperemovelocationclasspath:collective/app/dam/components/search/filters/SearchFilterContainer.tml,
   line 8
   - org.apache.tapestry5.ioc.internal.util.TapestryException
   Failure reading parameter 'assetStatusRefineOption' of component
   dam/SearchResults:instantsearch.searchfiltercontainer.refineassetstatusfilter:
   Property 'currentFilter' (within property expression
   'currentFilter.getFilterValue()', of
   collective.app.dam.components.search.filters.SearchFilterContainer@48e53372)
   is null.
   locationclasspath:collective/app/dam/components/search/filters/SearchFilterContainer.tml,
   line 8
   - java.lang.NullPointerException
   Property 'currentFilter' (within property expression
   'currentFilter.getFilterValue()', of
   collective.app.dam.components.search.filters.SearchFilterContainer@48e53372)
   is null.
Reply | Threaded
Open this post in threaded view
|

Re: Loop parameter becoming null

Thiago H de Paula Figueiredo
On Mon, Jan 22, 2018 at 7:49 PM, Tyler Wilcock <[hidden email]> wrote:

> Hi all.


Hi!


>   I have some components being rendered in a loop.  On initial
> render, everything comes out fine.  However, when I try to click on an
> eventlink within one of the rendered components, I get an application
> exception.  What is going wrong here?
>

You're not passing any context to the remove EventLink. From your code:

<t:eventlink event="remove" class="remove-filter-icon">&times;</t:eventlink>

The request triggered by clicking the EventLink is different from the one
which rendered the HTML and Tapestry 5 doesn't keep the rendering state
between requests. You need to pass the needed information to the EventLink
so it can relay it to the corresponding event handler method.

You should add context="[reference to what you want to delete]" to your
EventLink and a corresponding parameter to onRemove().

--
Thiago