Saturday, 15 May 2010

jsf 2 - jsf Press a hidden Button by javascript from another form -



jsf 2 - jsf Press a hidden Button by javascript from another form -

i have 2 forms. form "form2" have several buttons. when 1 of buttons pressed want press hidden button in form "form1" submit , update whole form.

but still having problem when press button in form2 values not submitted. javascript function wrong or have primefaces/jsf 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}" /> <!-- 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() { homecoming mytestinputtext; } public void setmytestinputtext(string mytestinputtext) { this.mytestinputtext = mytestinputtext; } public void dosomebackendstuff() { // backendstuff! system.out.println("he nail me! entered: " + mytestinputtext ); } }

basically javascript won't work because client id of hidden button not myhiddenbutton should form1:myhiddenbutton

javascript jsf-2 primefaces

No comments:

Post a Comment