小编gal*_*lao的帖子

使用实体管理器本机查询插入JPA

我试图在我的数据库中插入数据,我在我的项目中使用JPA.

这就是我的bean的样子.

@PersistenceContext
EntityManager em;

    em.createNativeQuery("INSERT INTO testtable ('column1','column2') VALUES ('test1','test2')").executeUpdate();
Run Code Online (Sandbox Code Playgroud)

myfacade:

@Stateless
public class TestFacade extends AbstractFacade<Test> {
    @PersistenceContext(unitName = "TEST2PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TestFacade() {
        super(Test.class);
    }
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

javax.persistence.TransactionRequiredException: executeUpdate is not supported for a Query object obtained through non-transactional access of a container-managed transactional EntityManager
Run Code Online (Sandbox Code Playgroud)

如果我不使用 @PersistenceContext for EntityManager

EntityManagerFactory emf = Persistence.createEntityManagerFactory("TEST2PU");
EntityManager em = emf.createEntityManager();
em.createNativeQuery("INSERT INTO testtable ('column1','column2') VALUES ('test1','test2')").executeUpdate();
Run Code Online (Sandbox Code Playgroud)

这是我的错误:

javax.persistence.TransactionRequiredException: 
Exception Description: No …
Run Code Online (Sandbox Code Playgroud)

jpa entitymanager

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

如何在filtermapping中排除网址

web.xml中

<filter>
    <filter-name>SessionCheckFilter</filter-name>
    <filter-class>filter.SessionCheckFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SessionCheckFilter</filter-name>
    <url-pattern>/faces/app/admin/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

我试图排除/faces/app/admin/index.xhtml唯一的,有没有办法做到这一点?

如果在web.xml中没有排除url patterin,也许我可以操纵该doFilter()方法来排除url?

java web.xml url-pattern servlet-filters

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

将jQuery添加到PrimeFaces导致所有地方都出现Uncaught TypeError

我正在使用PrimeFaces 3.5和JSF 2.0.我想使用jQuery插件,所以我在我的webapp中包含了jQuery.

<h:head>
    <h:outputScript name="js/jquery.min.js" />
    <h:outputScript name="js/jquery-ui.js" />
</h:head>
Run Code Online (Sandbox Code Playgroud)

但是,在使用PrimeFaces组件时,我会收到类似未捕获的类型错误:

未捕获的TypeError:无法读取未定义的属性"长度"

未捕获的TypeError:对象[object Object]没有方法'autocomplete'

未捕获的TypeError:无法读取未定义的属性'keyCode'

未捕获的TypeError:this.jq.draggable不是函数

未捕获的TypeError:无法读取未定义的属性"LinearAxisRenderer"

未捕获的TypeError:对象[object Object]没有方法'fileupload'

未捕获的TypeError:this.jqEl.datetimepicker不是函数

等等.

这是怎么造成的,我该如何解决?

jquery jsf typeerror primefaces

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

使用文本溢出:省略号; 只有在div中达到3行时

这是我的CSS代码段

.test{
    width:150px;
    height:60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}
Run Code Online (Sandbox Code Playgroud)

它的作用是......

the quick brown fo...
Run Code Online (Sandbox Code Playgroud)

我想要的是什么

the quick brown fox
jumps over the lazy
dog. the quick br...
Run Code Online (Sandbox Code Playgroud)

无论如何只用CSS做到这一点?或者我是否需要使用javascript.如果需要javascript,任何人都可以教我如何?谢谢!

UPDATE

我尝试删除white-space: nowrap;并添加overflow-y: hidden;它给我3线布局但没有省略号

.test{
    width:150px;
    height:60px;
    overflow-y: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}
Run Code Online (Sandbox Code Playgroud)

javascript css ellipsis css3

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

从数据库到元og的Blob图片:image

我的数据库中具有中等Blob数据类型,它存储的图片具有gif,jpg,png,bmp类型。

我正在开发一个JSF Web项目,并且可以毫无问题地检索到Blob。

我正在尝试从数据库中检索Blob数据,然后尝试将其插入到打开的图形图像中,这是针对我的Facebook共享功能。

<meta property="og:image" content="blob from db image here"/>
Run Code Online (Sandbox Code Playgroud)

但是我迷路了,我不确定该怎么办,我不认为也可以使用javascript将blob转换为base64数据。

任何人都可以指出我正确的方向吗?

更新

我想将blob转换为base64数据似乎是可能的。

这是我所做的:

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script>
        var base64;
        base64 = '#{testController.RenderLogo(item.logo)}';
        $('head').append('<meta property="og:image" content="data:image/png;base64,'+base64+'"/>');
    </script>
</h:head>
Run Code Online (Sandbox Code Playgroud)

RenderLogo方法:

public String RenderLogo(byte[] rawLogo) {
    String base64String = Base64.encodeBase64String(rawLogo);
    return base64String;
}
Run Code Online (Sandbox Code Playgroud)

它可以在某些共享网站(如ShareThis)上运行,但是通过Facebook或Twitter分享时, 414 Request-URI Too Large

有什么建议么?:C

顺便说一句,我正在通过Facebook / Twitter分享使用ShareThis

jsf facebook opengraph facebook-opengraph

5
推荐指数
0
解决办法
1376
查看次数

删除页面中显示的mysqli_connect警告

$mysqlServer = "***";
$mysqlDb = "***";
$mysqlUser = "***";
$mysqlPass = "***";

$conn = mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass) or die("failed to connect to db");
mysqli_select_db($conn, $mysqlDb) or die("failed to connect select db");
Run Code Online (Sandbox Code Playgroud)

我有这个代码,它的工作没有任何问题.但是,如果我尝试输入错误的SQL服务器或测试它来执行错误.这将显示:

Warning: mysqli_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
failed to connect select db
Run Code Online (Sandbox Code Playgroud)

如果连接sql server时出现问题,我不希望显示警告.我只想要显示自己的错误.

php

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

转换日期时间转换奇怪的时间

我在我的xhtml上有这个代码

<h:inputHidden id="startDate" value="#{testController.selected.startDate}">
       <f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
</h:inputHidden>
Run Code Online (Sandbox Code Playgroud)

如果我输入2013-02-26 17:15插入我的数据库的数据的结果是2013-02-27 01:15 或如果2013-02-26 05:15结果是2013-02-26 13:15

我已经在输入上输入了24小时的日期时间,但我真的很困惑为什么它会转换为其他东西.

*编辑

我的目标是......用户输入的时间是什么,它将在数据库中反映出来.我正在使用一个日期选择器作为输入,所以假设时间/日期输入已经正确并且是24小时格式

jsf

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

处理ui:重复返回empy值

我有一个ui:repeat返回一个实体列表.有没有办法知道返回的列表是空的?

<ui:repeat id="resulta" value="#{testController.testList}" var="list"> 
   <div>list.name</div>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)

像是ui:repeat是空的然后显示一个div说"List is empty"

我听说过varStatus - > Facelets重复Tag Index

但我不认为有空列表的东西.还是有吗?

更新

<ui:repeat id="resulta" value="#{testController.testList}" var="list"> 
   <div>list.name</div>
    <h:panelGroup rendered="#{empty list}">
        list is empty!
    </h:panelGroup>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)

我试图渲染"列表是空的!" 当列表为空但后面没有显示时.

jsf jsf-2 uirepeat

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