ajax - 在参数字段 (ajax) 上写入参数 'value' 空值失败

当我尝试更新已处理事件(选择框的 onValueChanged)中的组件区域时,我遇到了这个问题。

[ERROR] TapestryModule.RequestExceptionHandler Processing of request failed with uncaught exception: Failure writing parameter 'value' of component calendar/Stereotype:daycomponent.selectcategoryactivity: Property 'day' (within property expression 'day.category', of com.hb.craproject.web.components.calendar.stereotype.AddDayStereotypeComponent@3a6b9a8a) is null.
org.apache.tapestry5.ioc.internal.OperationException: Failure writing parameter 'value' of component calendar/Stereotype:daycomponent.selectcategoryactivity: Property 'day' (within property expression 'day.category', of com.hb.craproject.web.components.calendar.stereotype.AddDayStereotypeComponent@3a6b9a8a) is null. [at classpath:com/hb/craproject/web/components/calendar/stereotype/AddDayStereotypeComponent.tml, line 24]

“Day”是这样定义的参数:

@Parameter(required=true)
@Property
private DayStereotypeBean day

当组件第一次渲染时,一切正常。只有当我尝试更改所选值时,它才会崩溃并给出错误消息。

我的 DayComponents 在我的 tml 页面中是这样声明的:

<t:loop source="week" value="dayBean">
  <tr style="border :0.1em solid blue; border-radius : 0.5em">
    <t:day t:id="dayComponent" day="dayBean" /></tr></t:loop>

所以这是 Day bean 的列表。此列表提供给页面的 setuprender 事件处理程序。

我不明白为什么 Day 参数在选择组件的事件处理程序中丢失了他的引用:

public Object onValueChangedFromSelectDuree(String duree)
{    
//throwing exception, day.Day is a String, this line is just for showing you that the object doesn't exist anymore in the method, if this line is not here, the exception is throwed too because my select tml component use (like many oher components) that object
    day.getDay(); 
    return request.isXHR() ? zoneDuree.getBody() : null;
}

现在您可以看到选择的 tml 组件:

<t:zone t:id="zoneDuree">
        <t:select t:id="selectDuree"
            model="literal:journée,demi-journée,définir" value="day.duree"  zone="zoneDuree" /> <!-- here some fields depending of the select value --></t:zone>

任何想法都应该受到赞赏。

(抱歉我的英语不好;))

最佳答案

“setuprender”事件仅在您的页面最初呈现时触发。在 setupRender() 中初始化的任何内容在后续事件请求中都将为 null。

这里有几个选项:

  1. 使用事件的上下文来传递所有必需的上下文信息。在模板呈现之前,您需要在事件中初始化 ajax block 所需的任何 @Parameters。
  2. 在 onActivate() 而不是 setupRender() 中初始化您的字段,因为 onActivate() 在页面呈现之前和事件处理程序之前触发
  3. 使用@Persist 在请求之间将值保存在 HTTPSession 中。我个人讨厌这种方法,并且不惜一切代价避免使用 HTTPSession。

您可能会发现内置的 select/ajax 更新是不够的,因为您不能提供多个上下文值。看一下 onEvent 混入 here这允许您自定义在发生客户端事件(例如更改)时从客户端传递到服务器端事件的内容。

关于ajax - 在参数字段 (ajax) 上写入参数 'value' 空值失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19360824/

相关文章:

assembly - 在轮类除法组装后舍入 Int

regex - 是否可以在正则表达式中对变量值进行数学运算?

git - 将 git 提交与相同的消息结合起来?

sql - 留在Access中的 "SQL Mode"?

plot - 删除 gnuplot 自动标题键标签中的文件路径,只留下文件名

c# - .NET 中 SafeBuffer 和 SafeHandleZeroOrMinusOneI

git - 将多模块 Maven 项目放入 Jenkins

google-apps-script - Speadsheet.getRangeByName 未定义

recursion - 树的路径列表上的 F# 尾递归

intel - tboot 的文档?