2013-10-14 29 views
2

我试图更新处理事件(选择框的onValueChanged)中的组件区域时遇到此问题。在参数字段(ajax)上写入参数'值'空值失败

[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.craproje[email protected]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.craproje[email protected]3a6b9a8a) is null. [at classpath:com/hb/craproject/web/components/calendar/stereotype/AddDayStereotypeComponent.tml, line 24] 

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

@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> 

因此,这是日Bean的列表。该列表在页面的setuprender事件处理程序中进行传递。

我不理解为什么日参数失去了他在选择组件的事件处理程序参考:

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> 

任何应该赞赏的想法。

(对不起我的英文不好;))仅

回答

2

的“setuprender”事件时,你的页面最初呈现的火灾。在setupRender()中初始化的任何内容在随后的事件请求中都将为null。

这里有几个选项:

  1. 使用事件的背景下,通过所有必要的上下文信息。您需要在模板呈现之前初始化事件中ajax块所需的任何@Parameters。
  2. 初始化,而不是setupRender()作为onActivate()页面之前触发渲染和事件处理程序之前
  3. 使用@Persist在请求之间HttpSession中坚持值onActivate(您的域)。我个人讨厌这种方法,不惜一切代价避免使用HTTPSession。

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

+0

谢谢你的回答!我见过你的onEvent混搭。这是清楚而棘手的,但它将是很重要的,以设置我在我的豆豆获得的所有价值。我想我必须使用持久的方法。你能告诉我为什么你讨厌和避免这种做法? 我认为参数注释做了一个含有Persist注解的事情吗?这就是为什么我不知道为什么每次请求后参数都会丢失的原因。 否则,我可以使用一个bean对象作为上下文发送到onEvent混合? – Gadou

+0

只要你有一个ValueEncoder注册到你的bean的类中,你就可以用它作为上下文。使用HTTPSession不能很好地扩展,因为您需要为每个客户端维护服务器端状态。当用户打开两个浏览器窗口获取不同的值时,您也会遇到问题。会话使用有时需要“杂乱”的代码来清除会话(即,当用户返回两次页面时)。使用URL(即事件上下文)意味着您的应用程序可以是无状态的,并且可以轻松支持多个浏览器窗口。它使您的应用程序简单且可扩展。 –

+0

坚持不懈的方法运作良好,但我会用一个ValueEncoder,并尝试用你的更好的方式。 谢谢你的回答,我会在这里发布你的解决方案,当它将完成;-)(今天晚上或明天) – Gadou