我已经开发了一个简单的登录表单,可以在我的JSF + PrimeFaces页面中使用:
<form action="j_security_check" method="post">
<p:dialog modal="true" header="Login" widgetVar="loginDlg">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="j_username">Username:</h:outputLabel>
<h:inputText id="j_username" required="true" />
<h:message for="j_username" />
<h:outputLabel for="j_password">Password:</h:outputLabel>
<h:inputSecret id="j_password" required="true" />
<h:message for="j_password" />
<br />
<h:commandButton value="Login" />
</h:panelGrid>
</p:dialog>
</form>
Run Code Online (Sandbox Code Playgroud)
尝试使用空密码,但缺少的密码(必需)不会被h:message组件捕获.我也转而p:commandButton认为问题可能出在按钮的Ajax行为中,但页面没有呈现,因为PrimeFaces抱怨CommandButton不在表单元素中.容器抛出的异常是:
com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Access denied on empty password for user pippo
Run Code Online (Sandbox Code Playgroud)
总结一下,我有两个问题:
在 Java EE 6 Web 应用程序中,我想从EJB.
我知道我可以在web.xml描述符中定义一个上下文参数,并且当我在一个bean 中时,我将能够通过javax.faces.context.ExternalContext#getInitParameterMap()访问它JSF,并通过getServletContext()从一个中访问它Servlet,但事实并非如此,因为我在EJB.
所以,问题是:是否有任何标准(并且可能是干净的)方法来实现这一目标?
我有三个表,其中一个是 ItemCategory、ItemMaster 和 Price。我在 ItemMaster 表中引用 itemaCategoryId,就像在价格中引用 itemmasterid 一样。现在我必须按 itemcategory id 显示价格订单的内容。这是我的标准查询。
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Price> cq = cb.createQuery(Price.class);
Root<Price> root = cq.from(Price.class);
Root<ItemMaster> itemMasterRoot = cq.from(ItemMaster.class);
Root<ItemCategory> itemCategoryRoot = cq.from(ItemCategory.class);
Join<ItemMaster, ItemCategory> s=itemMasterRoot.join(ItemMaster_.category);
Join<Price,ItemMaster> y=root.join(Price_.itemMaster);
Path<Long> itemMasterId=root.get(Price_.itemMasterId);
cq.select(root).where(cb.equal(root.get(Price_.priceMasterId), priceMasterId))
.orderBy(cb.asc(itemMasterId));
TypedQuery<Price> q = entityManager.createQuery(cq);
Run Code Online (Sandbox Code Playgroud)
高于我的标准查询
如果我想从JavaScript中评估一个JSF bean属性,我发现如果JavaScript代码片段在xhtml文件中,它可以工作,但是当JavaScript代码片段在一个单独的js文件中时,它不起作用.
所以,这有效:
的index.xhtml
...
<h:body>
<script type="text/javascript" src="resources/Javascript/jquery/jquery-1.7.2.js" />
<script type="text/javascript" >
$(document).ready(function() {
alert('#{myBean.myProperty}');
});
</script>
</h:body>
Run Code Online (Sandbox Code Playgroud)
但这不会评估ManagedBean的属性:
的index.xhtml
...
<h:body>
<script type="text/javascript" src="resources/Javascript/jquery/jquery-1.7.2.js" />
<script type="text/javascript" src="resources/Javascript/MyJS.js" />
</h:body>
Run Code Online (Sandbox Code Playgroud)
MyJS.js
$(document).ready(function() {
alert('#{myBean.myProperty}');
});
Run Code Online (Sandbox Code Playgroud)
在第二种情况下,警告框包含未评估的字符串 #{myBean.myProperty}
如何从外部js文件中使其工作?
下面的 EL 值表达式是否有效?
<p:selectBooleanCheckbox value="#{!bean.isCreateGroup}" id="checkBoxCreateSecurityGrpKey">
Run Code Online (Sandbox Code Playgroud)
我收到的错误是
javax.el.PropertyNotWritableException:/pages/popup.xhtml @503,170 value="#{!bean.isCreateGroup}": Illegal Syntax for Set Operation
Run Code Online (Sandbox Code Playgroud) jsf ×3
el ×2
primefaces ×2
criteria ×1
criteria-api ×1
deployment ×1
ejb ×1
jakarta-ee ×1
java-ee ×1
javascript ×1
jpa ×1
login ×1