Reputation: 1049
I created a minimalistic test to see if commandScript still passes the arguments to the bean but it does not seem to do so anymore. Am I reading them from the wrong place?
When I press the button in the example I created the backend is called but the requestParameterMap does not contain my submitted value.
The button calls the javascript function and that function calls the commandScript. Somhow I thought this was more clear :)
See https://github.com/MilovdZee/myfaces-minimal-test for the example. And down here the relevant snippets.
@Log4j2
@Named
@SessionScoped
public class CommandScriptBean implements Serializable {
public String getButtonName() {
log.info("getButtonName");
return "button";
}
public void commandScript() {
log.info("CommandScriptBean");
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
Map<String, String> requestParameterMap = ec.getRequestParameterMap();
log.info("Passed value: 'test'='{}'", requestParameterMap.get("test"));
}
}
and
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="jakarta.faces.html"
>
<h:head>
<title>Minimal test</title>
</h:head>
<h:body>
<h:form id="form1">
<h:commandScript id="jsFunction"
name="jsFunction"
actionListener="#{commandScriptBean.commandScript}"
/>
<script>
function testFunction() {
console.log("testFunction");
jsFunction({"test": "value"});
}
</script>
This is a form<br/>
<h:commandButton id="button" onclick="testFunction(); return false;" value="#{commandScriptBean.buttonName}"/>
</h:form>
</h:body>
</html>
Upvotes: 0
Views: 40
Reputation: 101
Hi I am the implementer of the myfaces ajax scripts, this could be related to a problem I am investigating atm https://issues.apache.org/jira/browse/MYFACES-4710 It looks closely like it, the parameters get lost along the way. I am looking into the issue, please also check the bug report for updates on this, it should be fixed the next few days!
Upvotes: 2