Reputation: 57
my problem is, that I got two fields. Here is the definition:
<h:selectOneMenu id="selectSource" update=":relationTableForm:selectObject" value="#{tabDefineRelationTable.sourceId}" style="width: 100%;" required="true" requiredMessage="Source is required">
<p:ajax listener="#{tabDefineRelationTable.handleSourceChange}" />
<f:selectItem itemLabel="Select Source" itemValue="0" noSelectionOption="true" />
<f:selectItems value="#{tabDefineRelationTable.mySources}"
update=":createArtifactForm:selectObject"
var="source"
itemLabel="#{source.s_name}"
itemValue="#{source.s_id}" />
</h:selectOneMenu>
<h:selectOneMenu id="selectObject" value="#{tabDefineRelationTable.objectId}" style="width: 100%;" required="true" requiredMessage="Object is required" onchange="submit()">
<f:selectItem itemLabel="first select Source" itemValue="0" noSelectionOption="true" />
<f:selectItems value="#{tabDefineRelationTable.myObjects}"
var="object"
itemLabel="#{object.o_name}"
itemValue="#{object.o_id}" />
</h:selectOneMenu>
I want to implement, if I select in my selectSource
a field, I update the variable objectId
in the backend, and see it in my frontend.
Here is my first try to implement it: Variable definition
private List<Source> mySources;
private List<Objects> myObjects;
private Integer sourceId = 0;
private Integer objectId = 0;
Constructor:
public TabDefineRelationTable (TabLoader parent, List<Source> sources, List<Objects> objects) {
parentForm = parent;
mySources = sources;
myObjects = objects;
}
Listener:
public void handleSourceChange() {
this.objectId = 0;
if (sourceId != 0) {
for (Source curSource : mySources) {
if (curSource.getS_id() == sourceId) {
myObjects.clear();
myObjects.addAll(curSource.getObjects());
}
}
}
}
Thanks a lot.
Best regards Björn
Update 1:
After I tried the solution to use <p:ajax event="select" update="tabView:relationTableForm:selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
,
<p:ajax event="select" update=":relationTableForm:selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
or
<p:ajax event="select" update=":selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
.
I got this errormessage:Cannot find component with identifier "tabView:relationTableForm:selectObject" referenced from tabView:relationTableForm:selectSource".
Any other Ideas?
Update 2:
update="@([id$=output])"
testet this one. Didn't got an error, but the field is also not updated :/
Upvotes: 0
Views: 98
Reputation: 9
could you try this..
<p:ajax update="selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
Upvotes: 1
Reputation: 57
The solution was to change the ajax line into
<p:ajax update="selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
Big thanks to serdar for help!
Upvotes: 0