2016-08-10 21 views
0

我收到兩個名爲uId和oId(都是long)的上下文。Tapestry - 接收兩個上下文並在窗體中使用它們

使用onActivate我將userId上下文保存在變量userId中,與orderId相同。 當我在裏面onActivate我可以打印這兩個變量,但如果我使用(例如)一個窗體,userId爲空。

我怎樣才能訪問我的表單中的這些變量。

下面的代碼:

public class newMessage{ 

@Property 
private Long userId; 

@Property 
private Long orderId; 

@Component 
private Form newMessageForm; 


void onActivate(Long userId, Long orderId){ 
    this.userId = userId; 
    System.out.println("User Id: " + userId); 
    this.orderId = orderId; 
    System.out.println("Order Id: " + orderId); 
} 


@OnEvent(value = EventConstants.VALIDATE, component = "newMessageForm") 
public void checkForm() { 
    System.out.println("userId: " + userId); 
    System.out.println("orderId: " + orderId); 
} 

回答

0

你缺少onPassivate方法,增加了激活上下文鏈接和表格,以便在明年的請求這些值將再次可用。這個方法應該返回你在onActivate方法中所期望的。 一些更多的信息可以在這裏找到:

JumpStart onActivate/onPassivate

所以你的情況添加下面的方法應該這樣做:

Object[] onPassivate() { 
    return new Object[] { userId, orderId }; 
} 
+0

感謝您的幫助內森。我會試試看。 – eloygperez

+0

好的,如果這是您問題的解決方案,請將其設爲已接受的答案。 –

0

@PageActivationContext現在通過在5.4增加了新的index功能支持多個值。如果你使用這個,那麼你不需要明確的onActivateonPassivate聲明。

如:

public class NewMessage { 
    @Property 
    @PageActivationContext(index=0) 
    private Long userId; 

    @Property 
    @PageActivationContext(index=1) 
    private Long orderId; 

更多信息here

相關問題