小编Ulu*_*Biy的帖子

将变量传递给循环中的promise

我在循环中有一个promise,我不知道如何将一些范围变量传递给promise处理程序.

for(var i in superarray){
    MyService.get(superarray[i].externalID).then(function(r){
        console.debug(i);
});
Run Code Online (Sandbox Code Playgroud)

MyService是一个工作服务,带有一个返回promise的get方法.

app.factory('MyService', function($http,$q) {
  return {
     get : function(itemID){
        var deferred = $q.defer();
        $http.get('/someresturl/'+itemID).then(function(e) { 
                deferred.resolve(e.data);
        }, function(reason) {
                deferred.reject(reason);
        });
        return deferred.promise;
    }
});
Run Code Online (Sandbox Code Playgroud)

在我的控制台中,console.debug logicaly不显示1,2,3,4,5.但是5,5,5,5,5.(我的superarray中有5个元素).

如何在我的保证范围内传递'i'值,以便我可以在then()中使用它?

可能吗?

promise angularjs

35
推荐指数
3
解决办法
2万
查看次数

加载FXML时解析"onAction"时出错

我在运行一个简单的hello world应用程序时遇到了一些问题.它抛出以下错误:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
    at com.sun.javafx.application.LauncherImpl$$Lambda$2/1329552164.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: Error resolving onAction='#printHello', either the event handler is not in the Namespace or there is an error in the script.
/home/willi/java/IdeaProjects/JavaFXApp/out/production/JavaFXApp/sample/sample.fxml:23

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:104)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:606)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:766)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2827)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2536)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
    at sample.Main.start(Main.java:13)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863) …
Run Code Online (Sandbox Code Playgroud)

java javafx javafx-8

20
推荐指数
1
解决办法
2万
查看次数

JavaFX:以编程方式聚焦文本字段

我用JavaFX编写了一个应用程序,它只能用于键盘的箭头.所以我在Scene的舞台上阻止了MouseEvent,并且我"监听"了KeyEvents.我还关闭了所有节点的可聚焦性:

for(Node n : children) {
     n.setFocusTraversable(false);
Run Code Online (Sandbox Code Playgroud)

现在我有一些文本字段,复选框和按钮.我想以编程方式更改输入控件(textfield,checkbox,..)的状态:例如,我想进入文本字段以编程方式编辑内容.所以我的问题是:如何进入非焦点可遍历的文本字段?因为textfield.requestFocus(); 因为我将false设置为textfield的focustraversable属性,所以不再起作用了.

谢谢

events focus textfield javafx-2

15
推荐指数
1
解决办法
5万
查看次数

Textarea的透明背景在JavaFX 8

由于我使用的是JavaFX 8,所以我textarea的所有内容都不适用transparency于相应的css中定义的内容.它在Java 7中运行良好,但对于JavaFX 8的候选版本,我不能像以前那样表现.

编辑:这个问题是关于JavaFX TextArea,而不是JTextArea.
-fx-background-color: rgba(53,89,119,0.2);对textarea没有任何影响,虽然它应该有一个0.2的alpha值,但它是不相干的......

这是一个已知问题吗?

java javafx javafx-8

15
推荐指数
1
解决办法
2万
查看次数

如何为TableView/TreeTableView的focusLost启用提交?

是否有任何简单的方法让TreeTableView(或TableView)尝试在焦点丢失时提交值?

不幸的是,我没有成功使用javafx TableCellFactories的任何默认实现,这就是为什么我尝试了自己的TreeTableCell实现以及一些不同的tableCell实现,比如来自Graham Smith的实现,这似乎是最直接的,因为它已经实现了一个钩子焦点丢失,但仍然没有提交值,用户更改重置为原始值.

我的猜测是,每当焦点丢失时,受影响的Cell的editingProperty总是为false,这导致Cell永远不会在focusLost上提交值.这里是原始(oracle-)TreeTableCell实现(8u20ea)的相关部分,它导致我的方法失败:

 @Override public void commitEdit(T newValue) {
        if (! isEditing()) return; // <-- here my approaches are blocked, because on focus lost its not editing anymore.

        final TreeTableView<S> table = getTreeTableView();
        if (table != null) {
            @SuppressWarnings("unchecked")
            TreeTablePosition<S,T> editingCell = (TreeTablePosition<S,T>) table.getEditingCell();

            // Inform the TableView of the edit being ready to be committed.
            CellEditEvent<S,T> editEvent = new CellEditEvent<S,T>(
                table,
                editingCell,
                TreeTableColumn.<S,T>editCommitEvent(),
                newValue
            );

            Event.fireEvent(getTableColumn(), editEvent);
        }

        // inform parent classes of the commit, …
Run Code Online (Sandbox Code Playgroud)

java focus tableview javafx-8 treetableview

13
推荐指数
2
解决办法
8056
查看次数

JSF/PrimeFaces ajax更新破坏了jQuery事件监听器函数绑定

我正在使用jQuery为HTML中的change每一个注册一个事件监听器,input如下所示:

<h:head>
    <script type="text/javascript">
        //<![CDATA[
        $(document).ready(function(){
            $(':input').each(function() {
                $(this).change(function() {
                    console.log('From docReady: ' + this.id);
                });
            });
        });

        function changeHandler() {
            console.log("from changeHandler");
        }
        //]]>
    </script>
</h:head>
<h:body>
    <h:form id="topForm">
        <p:commandButton id="myButton" value="update"
                         action="#{testBean.submit}"
                         partialSubmit="true" process=":myForm:panel"
                         update=":myForm:panel" />
    </h:form>
    <h:form id="myForm">
        <p:panel id="panel">
            <p:inputTextarea id="myTextarea"
                             value="#{testBean.val}"
                             onchange="changeHandler();"/>
        </p:panel>
    </h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)

change如果用户更改了内容,则会触发这两个事件myTextarea.但是,在按下部分更新的更新按钮后myTextarea,只有changeHandler会在之后触发.绑定的事件$(document).ready()不再触发.

这是PrimeFaces相关和/或预期的行为?如果是,那么如何在不重新运行文档就绪脚本的情况下确保触发第二个事件.

javascript ajax jquery primefaces jsf-2

11
推荐指数
1
解决办法
1万
查看次数

如何从javafx.scene.web.WebEngine #loadContent加载的html页面获取css和图像文件?

我有一个String HTML内容,webEngineloadContent()方法加载.我还有一些在此页面中使用的CSS和图像文件.虽然我把这些文件放在java类的同一个包中,但是加载的页面找不到它们.寻找API文档和Web,但找不到任何适合的类似解决方案.我如何加载这些文件?

java webview javafx-2

10
推荐指数
3
解决办法
6594
查看次数

EntityListeners中的CDI注入

由于JPA 2.0不支持注入EntityListener(JPA 2.1将),因此决定使用JNDI查找来获取BeanManager并通过它获取登录用户.我定义了一个EntityListener类似的:

public class MyEntityListener {

    public static BeanManager getBeanManager() {
        try {
            InitialContext initialContext = new InitialContext();
            return (BeanManager) initialContext.lookup("java:comp/BeanManager");
        } catch (NamingException e) {
            e.printStackTrace();
            return null;
        }
    }

    public Object getBeanByName(String name) {
        BeanManager bm = getBeanManager();
        Bean bean = bm.getBeans(name).iterator().next();
        CreationalContext ctx = bm.createCreationalContext(bean);
        return bm.getReference(bean, bean.getClass(), ctx);
    }

    @PrePersist
    @PreUpdate
    public void onPreInsertOrUpdate(MyEntity entity) {
        User loggedInUser = (User) getBeanByName("loggedInUser");
        entity.setUpdatedUser(loggedInUser);
        entity.setUpdatedTimestamp(new Date());
    }
}
Run Code Online (Sandbox Code Playgroud)

用户在会话范围内管理为:

@SessionScoped
public class UserManager …
Run Code Online (Sandbox Code Playgroud)

hibernate cdi java-ee-6 jpa-2.0 jboss-weld

10
推荐指数
1
解决办法
6210
查看次数

9
推荐指数
1
解决办法
2万
查看次数

导入javafx无法解析

我今天在我的Ubuntu Linux上安装了Eclipse IDE,然后使用"安装新软件"安装了JavaFX,当我创建一个javafx项目时,我在Main.java中收到以下错误:

导入javafx无法解析.

所以,我列出了以下目录来搜索"jfxrt.jar":

ls -l /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext
Run Code Online (Sandbox Code Playgroud)

但我没找到"jfxrt.jar".

java -version
Run Code Online (Sandbox Code Playgroud)

输出:

openjdk版"1.8.0_45-internal"

OpenJDK运行时环境(build 1.8.0_45-internal-b14)

OpenJDK 64位服务器VM(内置25.45-b02,混合模式)

java eclipse javafx

9
推荐指数
1
解决办法
3万
查看次数