gpt4 book ai didi

javascript - jsf通过javascript从另一个表单按下一个隐藏的按钮

转载 作者:行者123 更新时间:2023-11-30 17:25:41 25 4
gpt4 key购买 nike

我有两种形式。表单“form2”有几个按钮。当按下其中一个按钮时,我想按下表单“form1”中的一个隐藏按钮来提交它并更新整个表单。

但是当我按下 form2 中的 Button 时,我仍然遇到问题,值没有提交。是 javascript 函数错误还是有 Primefaces/JSF 可以更好地做到这一点?

我正在使用 Primefaces 5。

我的看法:

<!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>

我的 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 );
}
}

最佳答案

基本上 javascript 不会工作,因为隐藏按钮的客户端 ID 不是 myHiddenButton 它应该是 form1:myHiddenButton

关于javascript - jsf通过javascript从另一个表单按下一个隐藏的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24328110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com