0

I am having trouble passing a parameter to a dialog that I can actually use.

I have a command button which is is set with an actionListener that calls an open dialog method in the backing bean

Map<String, Object> options = new HashMap<>();
options.put("modal", true);
//...
options.put("includeViewParams", true);

Map<String, List<String>> params = new HashMap<>();
List<String> values = new ArrayList<>();
values.add("My String");
params.put("myParam", values);

PrimeFaces.current().dialog().openDynamic("test", options, params);

then in my test page I gave

<f:metadata>
  <f:viewParam name="myParam" value="#{testBean.testVal}" />
</f:metadata>
...
<h:outputText value="#{testBean.testVal}" />

and the string is output fine.

But I want to use that value in to perform a database lookup and this just isn't working.

private String myParam;
private List<Object> myThings;

@PostConstruct
public void init() {
  myThings = service.lookup(myParam);
}

but in the PostConstruct call myParam is null.

I added some logging on init and the getter and setter and noticed I had

  • init --> myParam null
  • Getter --> myParam null
  • Setter --> myParam = passed value
  • Getter --> myParam = passed value
  • Getter --> myParam = passed value

So it appears that the value is getting passed but after the PostConstuct method has fired.

An I doing something wrong or should I be doing this another way? (I have seen reference of passing objects via the session map but is there a way of getting this working like this?)

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Jameson_uk
  • 432
  • 2
  • 12
  • Off topic; see https://stackoverflow.com/questions/16352816/what-is-the-diamond-operator-in-java – Jasper de Vries Jun 30 '21 at 15:13
  • Java is something I tend to not touch for ages and then have to get right into it again. Tidying up code usually comes later... Updated and will try and remember I can do that now. – Jameson_uk Jun 30 '21 at 15:25
  • Yes and in particular the linked https://stackoverflow.com/questions/4888942/viewparam-vs-managedpropertyvalue-param-id – Jameson_uk Jul 01 '21 at 11:14
  • Solution was to add `` to the dialog page and remove the `@PostConstruct` annotation from init. – Jameson_uk Jul 01 '21 at 11:26

0 Answers0