リフレクションを使用すべきではないことはわかっていますが、これは一時的な解決策です...
私は1を持っています:
@Named("PoiBean")
@SessionScoped
public class PoiBean implements ActionContext, Serializable {
private String name = "www";
@EJB
private NavigationServiceRemote nav;
@PostConstruct
private void testReflection() {
try {
nav.TestMe(this);
} catch (NoSuchMethodException ex) {
Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void prepareListAllForm() {
this.setName("test me");
}
}
私は2つ持っています:
@Stateless(mappedName="NavigationService")
public class NavigationServiceBean implements NavigationServiceRemote, NavigationContext {
@Override
public void TestMe(ActionContext ctx) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method method = ctx.getClass().getMethod("prepareListAllForm", new Class[] {});
method.invoke(ctx, new Object[] {});
}
説明: PoiBean が起動すると、EJB nav が注入され、その後 @PostConstruct でテスト メソッド TestMe を呼び出します。
デバッグすると、Test me name=www の前に、PoiBean::prepareListAllForm 内 (リフレクションによって呼び出されます) で、name 変数が変更されて = "test me" になり、return 後に名前が www に戻ります。
リフレクションが PoiBean のコピーで prepareListAllForm を呼び出すようなものです ...
私が今達成しようとしているのは、@EJB からのリフレクションを使用して呼び出される prepareListAllForm 関数を使用してその変数を変更することです。