我知道我必须在删除它之前合并该实体,但我从未想过我必须在EJB中执行它.首先我有这些:
e = (Event) scholarBean.merge(e);
scholarBean.remove(e);
Run Code Online (Sandbox Code Playgroud)
在我的托管bean中.它给了我这个错误
java.lang.IllegalArgumentException: Entity must be managed to call remove: com.scholar.entity.Event@998, try merging the detached and try the remove again.
Run Code Online (Sandbox Code Playgroud)
那么我将这两行放在我的会话bean中,它就可以了.知道为什么吗?
Managed Bean
myEJB.deleteEvent(e);
Run Code Online (Sandbox Code Playgroud)
和
myEJB.java
public void deleteEvent(Event e){
e = (Event) merge(e);
em.remove(e);
}
Run Code Online (Sandbox Code Playgroud) 我有使用Parse Rest推送utf8编码消息的问题,这是我的身体
{"where":{"$and":[{"email":{"$in":["phaxxx@gmail.com","nhungxxx@gmail.com"]}},{"deviceType":{"$in":["ios"]}}]},"data":{"alert":"TEST: Gi?m 40% Khi Mua Sách Harry Potter","sound":"default","page_type":"cms_key","page_value":"harry-potter"}}
Run Code Online (Sandbox Code Playgroud)
有谁知道如何编码utf8消息?
我在glassfish v3.0.1 b22中使用jdbcRealm来保证安全性.它被设置为使用我的数据库中的USER表进行身份验证,方法是访问以下博客:http://blogs.oracle.com/foo/entry/mort_learns_jdbc_realm_authentication.如果我将摘要算法保留为纯文本,我的工作正常.但是,当我尝试使用SHA-256进行摘要算法时,它会停止工作.我所做的是在Glassfish中指定 - 安全 - 领域 - jdbcRealm - 我想要SHA-256的摘要(我只是在摘要字段中键入SHA-256).然后我写了一个简单的Java程序,将密码文本转换为SHA-256哈希.然后我将该哈希粘贴到数据库中的密码字段中.顺便说一句,密码字段是类型varchar(30).我不能再登录了.有一点我注意到我的简单Java程序每次为同一文本字段生成不同的哈希值.
下面是我简单的java程序:
MessageDigest md = MessageDigest.getInstance("SHA-256");
String text = "admin";
md.update(text.getBytes("UTF-8"));
byte[] digest = md.digest();
System.out.println(digest.toString());
Run Code Online (Sandbox Code Playgroud) 这是我的commandLink工作方式
<p:dataTable value="#{myBean.users}" var="item">
<p:column>
<h:commandLink value="#{item.name}" action="#{myBean.setSelectedUser(item)}" />
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
然后在 myBean.java
public String setSelectedUser(User user){
this.selectedUser = user;
return "Profile";
}
Run Code Online (Sandbox Code Playgroud)
假设用户名是Peter.然后,如果我点击Peter,我将设置selectedUser为彼得的用户对象,然后重定向到配置文件页面,该页面现在呈现信息selectedUser.我想仅使用创建相同的效果<h:outputText>,因此我想到了GET请求.所以我这样做
<h:outputText value="{myBean.text(item.name,item.id)}" />
Run Code Online (Sandbox Code Playgroud)
那么text(String name, Long id)方法就回来了
"<a href=\"someURL?userId=\"" + id + ">" + name + "</a>"
Run Code Online (Sandbox Code Playgroud)
剩下的就是创建一个servlet,捕获它id,查询数据库以获取user对象,设置为selectedUser重定向.所以这是我的servlet
public class myServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Long userId …Run Code Online (Sandbox Code Playgroud) 当我使用此属性封送XML时
marshal.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshal.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Run Code Online (Sandbox Code Playgroud)
它会在最顶部产生一个空的换行符
//Generate empty line break here
<XX>
<YY>
<PDF>pdf name</PDF>
<ZIP>zip name</ZIP>
<RECEIVED_DT>received date time</RECEIVED_DT>
</YY>
</XX>
Run Code Online (Sandbox Code Playgroud)
我认为原因是因为marshal.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);删除<?xml version="1.0" encoding="UTF-8" standalone="yes"?>了输出xml在开头的一个换行符.有没有办法来解决这个问题?我使用JAXB自带JDK 6,Moxy会遇到这个问题吗?
这段代码对我有疑问,有什么想法吗?allButtons是a NSMutableArray,它包含3个对象a=0, b=1,a和b是int类型
if(a != -1 && b!= -1){
//Swap index in "allButtons"
id tempA = [allButtons objectAtIndex:a];
id tempB = [allButtons objectAtIndex:b];
[allButtons replaceObjectAtIndex:a withObject:tempB]; //Seg fault here?????
[allButtons replaceObjectAtIndex:b withObject:tempA];
needLoad = false;
[self setUpButtons];
}
Run Code Online (Sandbox Code Playgroud)
编辑:
NSMutableArray *allButtons = //fetch the array from Coredata. This work since I display the data onto the screen, plus, [allButtons count] return 3, and a=0, b=1
f(a != -1 && b!= -1){
//Swap index …Run Code Online (Sandbox Code Playgroud) 每当我通过fstream阅读时,我最后会得到1个额外的字符,我该如何避免这种情况?
编辑:
ifstream readfile(inputFile);
ofstream writefile(outputFile);
char c;
while(!readfile.eof()){
readfile >> c;
//c = shiftChar(c, RIGHT, shift);
writefile << c;
}
readfile.close();
writefile.close();
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我在表示层和持久层重复验证,希望提高安全性.所以我的问题是:标准JSF验证可以防止代码注入.
<h:inputText id="name" value="#{bean.customer.name}" required="true" requiredMessage="Validation Error: Value is required." title="Name" >
<f:validateLength maximum="40"/>
</h:inputText>
Run Code Online (Sandbox Code Playgroud)
在这里,我验证字段是否为空,并验证字段长度.我知道验证字段长度会使代码注入变得更难,但有时你需要一个很长的字段长度,比如textArea.如果这是脆弱的,我将如何解决它?非常感谢你提前.
这里说的是我的堆栈布局
View3 --> Top of the stack
View2
View1
HomeView --> Bottom of the stack
Run Code Online (Sandbox Code Playgroud)
所以,我在View3现在,如果我按一下Home按钮,我想要加载HomeView,这意味着我需要流行View3,View2和View1.但如果我弹出View3,View2将会显示.我不想那样.我想要View3,View2并被View1删除,并将HomeView显示.知道怎么样?
我会在这里有情侣情景.请帮我
以下是基本案例:http://jsfiddle.net/2zsLy/9/
当我点击时Click Me,两个警报框Another Paragraph都出来了.这是预期的,因为click事件会冒泡到父容器,即body.现在开始我的问题
1)http://jsfiddle.net/2zsLy/10/
如何添加return false到我live.click不会阻止点击事件冒泡.从示例中,live.click冒泡并触发警报框.我认为文档说返回false会阻止实时事件冒泡.
2)http://jsfiddle.net/2zsLy/11/
现在,我将click事件更改为bodyto live.click并修复了问题 - > click事件没有冒泡(因此没有显示警告框).为什么live.click工作而click不是.
3)http://jsfiddle.net/2zsLy/13/
我认为文件清楚地说,呼唤event.stopPropagation()不会阻止冒泡的发生,我刚刚做了.我用event.stopPropagation()它期望它仍会触发我的警报框,但事实并非如此.为什么?
注意:对于前两个问题的justkt答案,请参阅答案.关于最后一个问题的答案,请参阅Squeegy答案及其答复.