我正在尝试编写一个JS代码,如果数据库中已存在给定的数字,它将取消"btn_submit"按钮.onclick事件.我使用AJAX查询给定数字的数据库,并确定是否应该将数据发送到将上传问题的.php站点.为了确定这一点,我需要numOfRows变量的值,但因为我在AJAX中设置它将保持为0. validation()函数将在我的AJAX查询完成之前完成,这会导致问题始终表明给定的数字不是存在于DB中(numOfRows将始终保持为0).在我将validation()函数的结束行中的numOfRows与0进行比较之前,如何等待AJAX查询完成?如果数字中已存在该数字,我需要将false返回到此行:
document.getElementById("btn_submit").onclick = validation;
谢谢!
var textAreaList;
var numOfRows = 0;
var finished = false;
document.getElementById("btn_submit").onclick = validation;
textAreaList = document.getElementsByClassName("text_input");
function validation() {
loadNumRows();
try {
document.getElementById('failure').hidden = true;
}
catch(e) {
console.log(e.message);
}
textAreaList = document.getElementsByClassName("text_input");
var failValidation = false;
for (var i = 0; i < textAreaList.length; i++) {
console.log(textAreaList[i]);
if (textAreaList[i].value == "") {
textAreaList[i].style.border = "2px solid #ff0000";
failValidation = true;
} else {
textAreaList[i].style.border = "2px solid #286C2B";
}
}
return !(failValidation || …Run Code Online (Sandbox Code Playgroud) 我正在使用Wildfly 10.0.0 Final,Java EE7,Maven和JPA 2.1.当我查询我的数据库中的记录时,它工作正常并列出了员工,但是当我试图坚持一个新员工时,它给了我以下异常:
javax.servlet.ServletException: WFLYJPA0060: Transaction is required to perform this operation (either use a transaction or extended persistence context)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
...
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用JSF和CDI bean来实现它.我有一个JTA数据源,我在persistence.xml文件中配置了它:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="MyPersistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/EmployeesDS</jta-data-source>
<class>com.home.entity.Employee</class>
<properties>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
CDI bean可以在下面看到.它相对简单,有一种方法可以列出25名员工,另一种方法可以保留特定员工:
@Named
@RequestScoped
public class DataFetchBean {
@PersistenceContext
EntityManager em;
public List getEmployees() {
Query query = …Run Code Online (Sandbox Code Playgroud) 美好的一天!我试图使用lambda表达式编写一个匿名方法,该表达式将从异步任务返回一个对象.我想在构造函数中执行此操作,因此这是我无法使其父方法异步的原因.
ReadJsonAsync方法返回一个Session对象.我会告诉你相关的代码:
Session session;
fileService = new FileService();
session = async () => { return await fileService.ReadJsonAsync() };
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我有十六个图像按钮,所以我创建了一个图像按钮数组.我想用for循环初始化它们,我不想一个接一个地做,尽管我不知道是否可能.对于一个图像按钮,它会是这样的:
imgbtn[0] = (ImageButton)findViewById(R.id.imgButton1);
Run Code Online (Sandbox Code Playgroud)
我看到R.id.smth部分是一个整数.它是否说某处,imgButtons的整数值在哪里?所以我可以这样:
int value = R.id.imgButton1;
for(int i = 0; i < imgbtn.length; i++)
{
imgbtn[i] = (ImageButton)findViewById(value);
value++; //or something along these lines
}
Run Code Online (Sandbox Code Playgroud) .net ×1
ajax ×1
android ×1
async-await ×1
asynchronous ×1
c# ×1
cdi ×1
hibernate ×1
imagebutton ×1
java ×1
java-ee ×1
javascript ×1
jpa ×1
jquery ×1
lambda ×1
loops ×1
managed-bean ×1
php ×1