[
https://issues.apache.org/jira/browse/MYFACES-4716?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17938312#comment-17938312
]
Werner Punz edited comment on MYFACES-4716 at 3/25/25 6:19 PM:
---------------------------------------------------------------
Good news is it seems to work in 5.0 so i doubt the the ts codebase is the
issue here because the ts code is shared among all 3 versions (4.0, 4.1 and
5.0):
Selected values: [3]
Selected values: [2]
Selected values: [2, 3]
Selected values: [2, 3, 4]
Selected values: [2, 3]
Selected values: [2]
Selected values: []
{code:java}
@Named
@RequestScoped
@Getter
@Setter
public class MyBackingBean {
private List<String> valueList = new ArrayList<>();
private List<SelectItem> valueSelectItems = List.of(
new SelectItem("1", "Option One"),
new SelectItem("2", "Option Two"),
new SelectItem("3", "Option Three"),
new SelectItem("4", "Option Four"),
new SelectItem("5", "Option Five")
);
public void valueChanged(AjaxBehaviorEvent event) {
// This method will be called when selection changes
System.out.println("Selected values: " + valueList);
}
}
{code}
was (Author: werpu):
Good news is it seems to work in 5.0 so i doubt the the ts codebase is the
issue here:
Selected values: [3]
Selected values: [2]
Selected values: [2, 3]
Selected values: [2, 3, 4]
Selected values: [2, 3]
Selected values: [2]
Selected values: []
{code:java}
@Named
@RequestScoped
@Getter
@Setter
public class MyBackingBean {
private List<String> valueList = new ArrayList<>();
private List<SelectItem> valueSelectItems = List.of(
new SelectItem("1", "Option One"),
new SelectItem("2", "Option Two"),
new SelectItem("3", "Option Three"),
new SelectItem("4", "Option Four"),
new SelectItem("5", "Option Five")
);
public void valueChanged(AjaxBehaviorEvent event) {
// This method will be called when selection changes
System.out.println("Selected values: " + valueList);
}
}
{code}
> Ajax is not working for empty selection for h:selectManyListbox
> ---------------------------------------------------------------
>
> Key: MYFACES-4716
> URL: https://issues.apache.org/jira/browse/MYFACES-4716
> Project: MyFaces Core
> Issue Type: Bug
> Affects Versions: 4.0.2
> Reporter: Gordon Freeman
> Assignee: Werner Punz
> Priority: Major
>
> I have multiselect on the form:
> {code}
> <h:selectManyListbox id="someId" value="#{myBackingBean.valueList}">
> <f:selectItems value="${myBackingBean.valueSelectItems}" />
> <f:ajax execute="@this" render="someOtherId" event="valueChange"
> listener="#{myBackingBean.valueChanged}"/>
> </h:selectManyListbox>
> {code}
> When I deselect the last option in the multiselect I expect the empty list to
> be setted to the backing bean _valueList_ and the _valueChanged_ method to be
> called.
> But the _valueChanged_ method is not called and a crash occurs at the
> validation stage due to NPE.
> {code}
> org.apache.myfaces.core.api.shared.SelectItemsUtil.matchValue(SelectItemsUtil.java:235)
> jakarta.faces.component.UISelectMany.validateValue(UISelectMany.java:332)
> jakarta.faces.component.UIInput.validate(UIInput.java:717)
> jakarta.faces.component.UIInput.processValidators(UIInput.java:297)
> org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:717)
> org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:226)
> jakarta.faces.component.UIComponent.visitTree(UIComponent.java:880)
> jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120)
> jakarta.faces.component.UIComponent.visitTree(UIComponent.java:908)
> jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120)
> jakarta.faces.component.UIComponent.visitTree(UIComponent.java:908)
> jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120)
> jakarta.faces.component.UIComponent.visitTree(UIComponent.java:908)
> jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120)
> jakarta.faces.component.UIComponent.visitTree(UIComponent.java:908)
> jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120)
> jakarta.faces.component.UIForm.visitTree(UIForm.java:343)
> jakarta.faces.component.UIComponent.visitTree(UIComponent.java:908)
> jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120)
> org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartialExecute(PartialViewContextImpl.java:407)
> org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:388)
> jakarta.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1857)
> jakarta.faces.component.UIViewRoot._process(UIViewRoot.java:1714)
> jakarta.faces.component.UIViewRoot.processValidators(UIViewRoot.java:972)
> org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:39)
>
> org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:172)
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:125)
> jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:223)
> {code}
> According to the _HtmlRendererUtils.decodeUISelectMany_ method, when posting
> an empty multiselect, no parameters for this multiselect should be sent to
> the server.
> But the parameter is sent - it is an empty string. It is filled in
> _XhrRequest.ts_ when calling _this.appendIssuingItem(formData);_
> I think this is a bug (probably introduced in MYFACES-4606) in js and with an
> empty multiselect the parameter should not be sent in the POST request.
> And the current behavior is as if an option with an empty value was selected
> in the multiselect, _submittedValue_ is an array of one element - an empty
> string, instead of empty array.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)