Reputation: 458
I have two forms. Form "form2" have several buttons. When one of this buttons is pressed i want to press a hidden button in my form "form1" to submit it and update the whole form.
But i still having the problem when i press the Button in my form2 the values are not submitted. Is the javascript function wrong or have Primefaces/JSF something to do this better?
I'm using Primefaces 5.
My view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<div>
<h:form id="form1">
<p:inputText value="#{myBean.myTestInputText}" />
<!-- Some input elements -->
<p:commandButton id="myHiddenButton" style="display: none" />
</h:form>
</div>
<br/>
<div>
<h:form id="form2">
<p:commandButton value="Submit Form1"
onclick="document.getElementById('myHiddenButton').click();"
actionListener="#{myBean.doSomeBackendStuff()}"
update=":form1" />
</h:form>
</div>
</h:body>
</html>
My Bean:
package de.vwag.flucs.presentation.admin.boundary;
import java.io.Serializable;
import javax.inject.Named;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;
@ViewAccessScoped
@Named("myBean")
public class MyBean implements Serializable {
private static final long serialVersionUID = -8923580640140500834L;
private String myTestInputText = "";
public String getMyTestInputText() {
return myTestInputText;
}
public void setMyTestInputText(String myTestInputText) {
this.myTestInputText = myTestInputText;
}
public void doSomeBackendStuff() {
// Do Some Backendstuff!
System.out.println("He hit me! He entered: " + myTestInputText );
}
}
Upvotes: 1
Views: 5297
Reputation: 10048
Basically the javascript won't work because the client id of the hidden button is not myHiddenButton
it should be form1:myHiddenButton
Upvotes: 2