小编Gim*_*mby的帖子

带有自定义CellFactory的ListView修剪不可见节点

我的布局问题

我有一点问题,ListView我不确定是不是因为我遗漏了一些知识,或者我的方法存在缺陷.不得不承认我还不清楚JavaFX在很多可能情况下如何处理布局.

ListView修剪我的布局尝试

上面的屏幕截图显示了我使用完全相同的代码获得两次的结果,除了在第二个屏幕截图中,我用于连贯布局的不可见形状对于调试是可见的.

CellFactory扩展所涉及的各种类Group,Parent到目前为止我尝试了其他一些没有太大成功.


如何重现

而不是共享我的StarShape,StarRow和其他一些杂项类(我很乐意,如果需要)我写了一个样本复制的问题.该类扩展Application并覆盖该start(...)方法:

@Override
public void start(Stage primaryStage) throws Exception {
    final StackPane root = new StackPane();
    final Scene scene = new Scene(root, 400, 600);

    final ListView<Boolean> listView = new ListView<>();
    listView.setCellFactory(this::cellFactory);

    for (int i = 0; i < 5 ; i++) {
        listView.getItems().add(true);
        listView.getItems().add(false);
    }

    root.getChildren().add(listView);

    primaryStage.setScene(scene);
    primaryStage.setTitle("ListView trims the invisible");
    primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)

这里this::cellFactory是 …

java layout listview javafx

45
推荐指数
1
解决办法
1089
查看次数

正确的方式来调用电报api方法

我在我的java应用程序中处理Telegram api.我需要使用我的电报帐户进行身份验证和授权,并获取我的特定组的消息列表.为了这个目的,首先我得到了api_id,api_hash并且MTProto servers从电报的网站.其次,我尝试以auth.sendCode这种方式使用方法授权我的帐户:

...
String url = "https://149.154.167.40:443/auth.sendCode";
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
httpPost.addHeader("charset", "UTF-8");

List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair("phone_number", myPhoneNumber));
nameValuePairs.add(new BasicNameValuePair("sms_type", "5"));
nameValuePairs.add(new BasicNameValuePair("api_id", api_id));
nameValuePairs.add(new BasicNameValuePair("api_hash", api_hash));
nameValuePairs.add(new BasicNameValuePair("lang_code", "en"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

HttpResponse response = httpClient.execute(httpPost);
...
Run Code Online (Sandbox Code Playgroud)

但这会让我感到javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake异常.我测试了url http而不是https和这返回了404 Not Foundhtml内容.在java中调用telegram api方法的正确方法是什么?

更新:

我尝试使用 …

java telegram

13
推荐指数
1
解决办法
1685
查看次数

C#在注入第一个参数的给定方法上创建lambda

在 C# 中,我在给定的类(非静态)中定义了以下方法:

int MyMethod(ScriptEngine script, int a, int b) {
    return a + b;
}

void MyMethod2(ScriptEngine script, string c) {
    // do something with c
}
Run Code Online (Sandbox Code Playgroud)

我想创建包装 lambda / Action / Delegate / MethodInfo(所有这些都被脚本引擎接受),它会自动传递ScriptEnginethis从给定的预定义变量。

到目前为止,我已经尝试过:

// With overloads up to 16 template parameters
Action<T1> Wrap<T1>(Action<ScriptEngine, T1> func, ScriptEngine script) { 
     return (Action<T1>) ((t1) => func(script, t1));
}
Run Code Online (Sandbox Code Playgroud)

但是当调用 MyMethod2 时,我得到了The type arguments for method … cannot be inferred from the usage. Try specifying …

c# reflection lambda

13
推荐指数
1
解决办法
370
查看次数

structuremap - 同一接口的两个实现

我有一个服务类与以下ctor:

public class (IMessageService emailService, IMessageService smsService)
{ ... }
Run Code Online (Sandbox Code Playgroud)

IMessageService(电子邮件和短信)的两个实现.如何配置容器以正确解析此构造函数?这是命名实例进入的地方,还是另一种情况?

c# structuremap dependency-injection inversion-of-control

12
推荐指数
1
解决办法
6737
查看次数

IntelliJ社区版JSP语法高亮显示

我刚刚下载了IntelliJ 15.0.1社区版,因为我厌倦了Eclipse,它在我的笔记本电脑上看起来很糟糕(Ubuntu 14.04 LTS).在我看到JSP文件中的语法突出显示无效之前,一切都进展顺利.

我去了设置/编辑/文件类型

在识别文件类型中,除了其他选项之外,我还有这个:

JSP文件(仅限语法高亮显示)

当我选择它时,我可以在注册的模式中看到:*.jsp,*.tag这正是我想要的......但它不起作用......任何想法?

谢谢

java jsp intellij-idea

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

无法通过Glassfish 4.1 Web管理员创建任何JMS资源

我已经安装了Glassfish 4并尝试创建一些JMS资源来跟踪学习JMS的教程,但这是不可能的.在Web界面上,它始终显示文本"java.lang.RuntimeException",并在日志控制台上显示堆栈跟踪.抛出此异常总是我在"JMS目标资源"页面或连接工厂的页面中按下"新建..."链接.这是堆栈跟踪:

[#|2015-11-16T09:15:24.090+0100|INFO|glassfish 4.1|org.glassfish.admingui|_ThreadID=48;_ThreadName=admin-listener(5);_TimeMillis=1447661724090;_LevelValue=800;|

Exception Occurred :null|#]

[#|2015-11-16T09:15:24.097+0100|INFO|glassfish 4.1|org.glassfish.admingui|_ThreadID=48;_ThreadName=admin-listener(5);_TimeMillis=1447661724097;_LevelValue=800;|

Exception Occurred :null|#]

[#|2015-11-16T09:15:24.100+0100|SEVERE|glassfish 4.1|javax.enterprise.resource.webcontainer.jsf.context|_ThreadID=48;_ThreadName=admin-listener(5);_TimeMillis=1447661724100;_LevelValue=1000;|
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException while attempting to process a 'beforeCreate' event for 'event166'.
    at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:422)
    at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:394)
    at com.sun.jsftemplating.layout.descriptors.LayoutComponent.beforeCreate(LayoutComponent.java:348)
    at com.sun.jsftemplating.layout.descriptors.LayoutComponent.getChild(LayoutComponent.java:288)
    at com.sun.jsftemplating.layout.LayoutViewHandler.buildUIComponentTree(LayoutViewHandler.java:556)
    at com.sun.jsftemplating.layout.LayoutViewHandler.buildUIComponentTree(LayoutViewHandler.java:551)
    at com.sun.jsftemplating.layout.LayoutViewHandler.buildUIComponentTree(LayoutViewHandler.java:507)
    at com.sun.jsftemplating.layout.LayoutViewHandler.buildUIComponentTree(LayoutViewHandler.java:507)
    at com.sun.jsftemplating.layout.LayoutViewHandler.createView(LayoutViewHandler.java:255)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:256)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)

    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:233)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.doChainInvoke(StandardPipeline.java:678)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
    at …
Run Code Online (Sandbox Code Playgroud)

jms glassfish java-ee

8
推荐指数
2
解决办法
8424
查看次数

UItableView上的多个NsfetchedResultsController

我在执行2 nsfetchedresultsController中遇到困难tableView.我想在表的每个部分(2个部分)中使用fetchedresultsController,如下所示:

收藏

  • 产品
  • 产品2


  • 产品3

我知道对于这个例子我不需要2 nsfetchedResultsController但我稍后会需要它.

当我从一个nsfetchedResultsController删除一个产品,它传递给另一个,我得到这个错误:

无效更新:第0节中的行数无效.更新(0)后现有部分中包含的行数必须等于更新前的该部分中包含的行数(0),加上或减去数字从该部分插入或删除的行数(插入1个,删除0个).with userInfo(null)"

我认为这是因为当第一个fetchedRController检测到更改时,它会在第二个调用之前更新tableView,是吗?我应该使用NSMutableArrays并手动更新tableView吗?

代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
NSInteger numberOfRows = 0;

switch (section)
{
    case WISHLIST_SECTION:

    {
        numberOfRows =[[fetchedResultsControllerwish fetchedObjects]count];


    };
         break;

    case PURCHASED_SECTION:
    {   
        numberOfRows =[[fetchedResultsControllerPurchased fetchedObjects]count];

    };
        break;


    default:
        break;
}
return numberOfRows;
}

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
// The fetch controller is about to start sending change notifications, so prepare the table view for updates.
[self.tableView beginUpdates];
}


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller 
{ …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview nsmutablearray nsfetchedresultscontroller

7
推荐指数
1
解决办法
9085
查看次数

用于MSSQL 2014的错误的hibernate方言

我将使用序列的实体插入MSSQL 2014数据库时遇到问题.我使用Wildfly 10 CR4附带的hibernate(但在CR1和CR2中我遇到了同样的问题).

以下是有关webapp运行环境的一般信息:

  1. Wildfly 10(CR4)
  2. Java 8 u 51
  3. Windows 7专业版64位
  4. MSSQL Server 2014
  5. MSSQL驱动程序:sqljdbc42.jar部署在应用程序服务器上

我的persistence.xml文件如下所示:

<persistence-unit name="mb_managed_pu" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:/jdbc/datasource</jta-data-source>
    <properties>
        <property name="hibernate.archive.autodetection" value="class, hbm" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.jdbc.batch_size" value="0" />
        <property name="hibernate.default_schema_" value="openmap"/>
        <property name="hibernate.connection.useUnicode" value="yes"/>
        <property name="hibernate.connection.characterEncoding" value="UTF-8"/>
    </properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

现在这是我遇到错误时会发生什么.

首先,当Wildfly启动时,我可以看到这个警告:

WARN [org.hibernate.engine.jdbc.dialect.internal.StandardDialectResolver](ServerService线程池 - 68)HHH000385:使用SQL Server 2000方言的未知Microsoft SQL Server主要版本[12]

我浏览了网页,发现这个问题自2015年1月以来就已为人所知,但不幸的是,这仍然是一个悬而未决的问题.

当我尝试持久化具有配置为使用序列的ID的新实体时,会引发错误本身:

@Id
@Column(name = "MAP_BOOKMARK_ID")
@SequenceGenerator(name = "SEQ_MAP_BOOKMARKS", sequenceName = "SEQ_MAP_BOOKMARKS", allocationSize = 1)
@GeneratedValue(generator …
Run Code Online (Sandbox Code Playgroud)

java hibernate wildfly

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

如何在点击`li`元素时添加`active`类

我是AngularJS的新手.我需要知道如何使用它来处理这种情况.

我有一个包含值的数组.我正在使用ng-repeat迭代数组,它工作正常.我的要求是如何向用户点击的第一个子节点添加一个class(active),单击的元素应该获取类并从其余元素中删除该类.ulactive active li

我在JQuery中很容易就像这样:

$('li').addClass('active').siblings().removeClass('active')
Run Code Online (Sandbox Code Playgroud)

但是这里如何实现同样的目标呢?

我的代码:

JavaScript控制器

var myApp = angular.module("myApp", []);

myApp.controller("main", function ($scope) {

  $scope.items = [1,2,3,4,5];

  $scope.activate = function (item) {

    //how to active this item?

    //onload how to add class on first li?

  }

})
Run Code Online (Sandbox Code Playgroud)

HTML

 <ul>

    <li ng-click="activate(item)" ng-repeat="item in items">
        {{item}}
    </li>

  </ul>
Run Code Online (Sandbox Code Playgroud)

现场演示

jquery angularjs

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

Spring JPA规范不在查询中

这里使用Spring JPA规范的IN标准查询工作正常.但我不知道如何使用"NOT IN"..

那么我如何使用Spring JPA规范使用NOT IN条件查询.

SearchSpecification<User> spec = new CommonSpecification<Case>(new SearchCriteria("client.id", Operator.NOT_IN, clientIdList));

@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
    Predicate predicate = null;
    switch (searchCriteria.getOperator()) {

    case IN:
        if (searchCriteria.getValue() instanceof List<?>) {
            predicate = getFieldPath(searchCriteria.getKey(), root)
                    .in(((List<?>) searchCriteria.getValue()).toArray());
        }
        break;
    case NOT_IN:
        //What to do???
        break;
    default:
        break;

    }
    return predicate;
}


private Path<Object> getFieldPath(String key, Root<T> root) {
    Path<Object> fieldPath = null;
    if (key.contains(".")) {
        String[] fields = key.split("\\.");
        for (String field : …
Run Code Online (Sandbox Code Playgroud)

spring spring-data-jpa jpa-2.1

4
推荐指数
1
解决办法
5430
查看次数