下面的代码是从PrimeFaces的DataGrid + DataTable的教程启发和放入<p:tab>
一个的<p:tabView>
居住在<p:layoutUnit>
的<p:layout>
.这是代码的内部部分(从p:tab
组件开始); 外部是微不足道的.
<p:tabView id="tabs">
<p:tab id="search" title="Search">
<h:form id="insTable">
<p:dataTable id="table" var="lndInstrument" value="#{instrumentBean.instruments}">
<p:column>
<p:commandLink id="select" update="insTable:display" oncomplete="dlg.show()">
<f:setPropertyActionListener value="#{lndInstrument}"
target="#{instrumentBean.selectedInstrument}" />
<h:outputText value="#{lndInstrument.name}" />
</p:commandLink>
</p:column>
</p:dataTable>
<p:dialog id="dlg" modal="true" widgetVar="dlg">
<h:panelGrid id="display">
<h:outputText value="Name:" />
<h:outputText value="#{instrumentBean.selectedInstrument.name}" />
</h:panelGrid>
</p:dialog>
</h:form>
</p:tab>
</p:tabView>
Run Code Online (Sandbox Code Playgroud)
当我单击时<p:commandLink>
,代码停止工作并给出消息:
找不到表达式为"insTable:display"的组件,引用自"tabs:insTable:select".
当我尝试相同的使用时<f:ajax>
,它失败了,基本上告诉相同的不同消息:
<f:ajax>
包含一个未知的id"insTable:display"无法在组件"tabs:insTable:select"的上下文中找到它
这是怎么造成的,我该如何解决?
我正在寻找一种智能且易于阅读的方式来获取持久化实体的id JPA
.id是一个Integer
.
人们可以想到以下解决方案:
GeneratedValue
策略.这需要在持久化之前寻找一个免费的id,然后将它放入要保留的实体中:繁琐,但有效.GeneratedValue
策略.持久性提供程序将负责id生成.这看起来更聪明,但如何获得身份证?请参阅下面的解决方案2
MyEntity en = new MyEntity();
en.setName("My name");
em.persist(en);
System.out.println(en.getId());
Run Code Online (Sandbox Code Playgroud)
这打印出一个空id!
有什么建议?我正在使用MySql,EclipseLink,但需要一个可移植的解决方案.
我找不到icons
像PickList
组件中存在的那样选择箭头的方法,以便在其他方面使用它们CommandButtons
.
好吧,我知道为了在CommandButton中使用图标,必须遵循以下指示:
<p:commandButton outcome="target" icon="star" title="With Icon"/>
Run Code Online (Sandbox Code Playgroud)
已经在css文件中定义了星形图标:
.star {
background-image: url("images/star.png");
}
Run Code Online (Sandbox Code Playgroud)
但我更喜欢使用与PickList组件完全相同的箭头.
我正在尝试创建一个标准来从3个表中检索一些对象(关联,更新和详细信息).详细信息引用了"关联"和"更新","更新"引用了"详细信息"列表.我的目标是在给定Associate id的情况下检索在指定字段中至少具有null值的Detail的更新列表.在JPQL中很容易做到,但客户说这必须用标准编码.
我的JPQL是:
public List<Update> getUpdates(long associateId) {
TypedQuery<Update> query = em.createQuery("select distinct u from Update u, Detail dt, Associate a "
+ "where dt.update = u and dt.associate = a and a.associateId = :id and "
+ "dt.ack_date is null", Update.class);
query.setParameter("id", associateId);
return query.getResultList();
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下内容,但它只返回了数据库中的所有更新:
public List<Update> getUpdates(long associateId) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Update> query = builder.createQuery(Update.class);
Root<Update> fromUpdates = query.from(Update.class);
Root<Associate> fromAssociate = query.from(Associate.class);
Root<Detail> fromDetail = query.from(Detail.class);
Join<Detail, Associate> associateJoin = fromDetail.join("associate");
Join<Detail, Update> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改以下HQL以使用JPA Criteria:
select distinct d from Department d
left join fetch d.children c
where d.parent is null
and (
d.name like :term
or c.name like :term
)
order by d.name
Run Code Online (Sandbox Code Playgroud)
Department
有一个Set<Department>
孩子.
标准:
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Department> c = cb.createQuery(Department.class);
Root<Department> root = c.from(Department.class);
root.fetch("children", JoinType.LEFT);
Path<Department> children = root.join("children", JoinType.LEFT);
c.orderBy(cb.asc(root.get("name")));
c.distinct(true);
c.where(cb.isNull(root.get("parent")));
String param = "%" + "term" + "%";
cb.and(cb.like(root.<String> get("name"), param));
cb.or(cb.like(children.<String> get("name"), param));
TypedQuery<Department> tq = getEntityManager().createQuery(c);
departments = tq.getResultList();
Run Code Online (Sandbox Code Playgroud)
我知道它可能有点简洁,但是,HQL返回24和Criteria版本28.我想我不处理:
and …
Run Code Online (Sandbox Code Playgroud) 为了将二进制文件上传到URL,我建议使用本指南.但是,该文件不在目录中,而是存储在MySql db中的BLOB字段中.BLOB字段byte[]
在JPA中映射为属性:
byte[] binaryFile;
Run Code Online (Sandbox Code Playgroud)
我稍微修改了从指南中获取的代码,这样:
HttpURLConnection connection = (HttpURLConnection ) new URL(url).openConnection();
// set some connection properties
OutputStream output = connection.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, CHARSET), true);
// set some headers with writer
InputStream file = new ByteArrayInputStream(myEntity.getBinaryFile());
System.out.println("Size: " + file.available());
try {
byte[] buffer = new byte[4096];
int length;
while ((length = file.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
writer.append(CRLF).flush();
writer.append("--" + boundary + "--").append(CRLF).flush();
}
// catch and close …
Run Code Online (Sandbox Code Playgroud) 我有一个对象(BlogPost),它包含一个M:N元素集合(标签).
如何查询一个对象(BlogPost),其中至少有一个对象的标签与一组标签(由用户定义)中的元素与JPA2(Hibernate)匹配.
findBlogPostWithAtLeastOneMatchingTag(Collection<Tag> tags){ ???? }
Run Code Online (Sandbox Code Playgroud)
我的主要问题是,我实际上需要比较两个标签集合: - BlogPost的标签集合. - 我搜索的集合
我试过Select p from Post p where p.tags in(:tags)
但它不起作用,因为我的帖子实体不仅仅有一个标签.
那我该怎么做呢?
我的BlogPost实体看起来像这样.它有几个标签.
@Entity
public class BlogPost{
/** The tags. */
@ManyToMany()
@NotNull
private Set<Tag> tags;
@NotBlank
private String content;
...
}
Run Code Online (Sandbox Code Playgroud)
解决方案不能是JPQL,JPA-Criteria(不是Hibernate-Criteria)也可以.
我昨天开始学习JavaEE,我选择了Oracle官方指南FirstCup来开始
我正在使用带有GlassFish Server 3.1.2.2的Netbeans 7.2,我确信我已逐步遵循每条指令.但我有两个问题:
我最终得到了404错误.但是,如果我将网址更改为
http://localhost:8080/DukesAgeService/webresources/dukesAge
Run Code Online (Sandbox Code Playgroud)
有用!我通过扩展RESTful Web Services获得了这个URL->右键单击DUkesAgeResource [dukesAge] - > Test Resource Uri
我想知道:
在哪里可以找到这个REST资源配置拨号1.
如果2是Oracle文档中的打印错误.它说相对网址应该是/resources/dukesAge
为什么网址必须结束/webresources/dukesAge
,我可以更改吗?
如何调试使用JPA 2.0
CriteriaBuilder
?构建的查询?有没有办法打印出正在执行的查询?
我使用的开发Web应用程序NetBeans
,MySql
,GlassFish
.我会避免在调试模式下启动MySql,因为它也用于其他应用程序.JPA提供商是EclipseLink
.
在我之前的问题中, 我遇到了从登录表单显示验证消息的问题。该问题现已解决,但这次我无法显示带有FacesContex#addMessage
.
使用 JSF + PrimeFaces。
<p:dialog header="Login" widgetVar="loginDlg">
<h:form id="loginForm">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}" id="username" required="true" label="username" />
<p:message for="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}" id="password" required="true" label="password" />
<p:message for="password" />
<f:facet name="footer">
<p:commandButton value="Login" id="loginDlgButton" update=":loginForm,:welcomeMsg" actionListener="#{loginBean.login}"
oncomplete="handleLoginRequest(xhr, status, args)"/>
<p:message for="loginDlgButton" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
在LoginBean (a SessionScoped
ManagedBean
) 中:
public void login() {
FacesContext context = FacesContext.getCurrentInstance();
RequestContext rContext = RequestContext.getCurrentInstance();
HttpServletRequest …
Run Code Online (Sandbox Code Playgroud)