Hibernate事件监听器 – 回滚

我实现了一个像这样的Hibernate事件监听器: public class AuditListener implements PostInsertEventListener { private static final long serialVersionUID = -966368101369878522L; @Override public void onPostInsert(PostInsertEvent event) { if (event.getEntity() instanceof Auditable) { StatelessSession session = null; try { session = event.getPersister().getFactory().openStatelessSession(); Auditable auditableEntity = (Auditable)event.getEntity(); session.beginTransaction(); session.insert(new AuditTrail(auditableEntity.getClass().getSimpleName(), auditableEntity.getId(), auditableEntity.getStatus(), auditableEntity.getLastModified())); session.getTransaction().commit(); } catch (HibernateException he) { System.out.println(“Horrible error: ” + he.getMessage()); […]

SharedPreferences无法跨活动工作

我正在尝试在一个活动中保存一些filter/状态,然后在下一个活动中使用该数据。 我正在使用SharedPreferences,但它没有像我预期的那样工作。 public class FilterActivity extends Activity { private static final String TAG = FilterActivity.class.getName(); EditText distanceEditor; @Override public void onPause() { super.onPause(); SharedPreferences preferences = getSharedPreferences(PreferenceKey.FILTER_PREFERENCES_NAME, MODE_WORLD_READABLE); String distance = distanceEditor.getText().toString(); preferences.edit().putString(PreferenceKey.DISTANCE, distance); preferences.edit().commit(); Log.i(TAG, “Wrote max-distance=” + distance); Log.i(TAG, “Preferences contains distance=” + preferences.getString(PreferenceKey.DISTANCE, “FAIL”)); } public static class PreferenceKey { public static […]

GWT:处理复合单元格中的事件

CompositeCell让我们使用Java自定义GWT中表格单元格的内容。 我们可以将几乎任何其他组的小部件放在表格的单元格中,并根据需要进行布局。 问题是如果我们使用html标签来定义CompositeCell的布局作为另一个表(参见下面的CompositeCell匿名类实现),我们将松开对单元组件的事件处理:(。 运行以下代码,当我们单击单元格的按钮时,将实现弹出响应事件处理IF WE COMMENT CompositeCell匿名实现。 我一直在调试CompositeCell.onBrowserEvent(Context,Element,C,NativeEvent,ValueUpdater),因为我认为使用HTML表标签定义单元格布局会破坏GWT小部件层次结构中的事件链,但到目前为止还没有成功。 备注:代码的注释和未注释版本实现相同的GUI布局。 这个例子只是为了表明我们在定制单元格内容时松散了事件处理。 public class ActionCellTest implements EntryPoint { private static final String SERVER_ERROR = “An error occurred while ” + “attempting to contact the server. Please check your network ” + “connection and try again.”; private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class); public void onModuleLoad() { CellTable table […]

在p:layout中hover后,JSF PrimeFaces MenuBar下拉子菜单消失

在JSF PrimeFaces 3.1.1中做一些应用程序(仍在学习),我实现了整页布局 – Sunny( 标签)。 Everytihng很好,除了我的菜单栏。 当hover在菜单中的子菜单按钮上时,下拉子菜单会显示,但是当我想通过鼠标进入子菜单时,它会消失。 唯一的选择是将鼠标位置更快地更改为子菜单 – 而不是保留。 这就是问题,需要它正常工作,而不是消失。 如果我把布局排除,菜单栏再次运行良好。 还试图从PF展示中复制和粘贴代码,问题是一样的。 在Tomcat 7.0.22.0上使用JSF 2。 这是我的代码…… 模板中的菜单栏: CSS解决溢出问题: .ui-layout-north .ui-layout-unit-content { overflow: visible !important; } .ui-layout-north { z-index: 30 !important; overflow: visible !important; } 感谢帮助!

Java 9 – 在运行时动态添加jar

我有Java 9的类加载器问题。 此代码适用于以前的Java版本: private static void addNewURL(URL u) throws IOException { final Class[] newParameters = new Class[]{URL.class}; URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class newClass = URLClassLoader.class; try { Method method = newClass.getDeclaredMethod(“addNewURL”, newParameters ); method.setAccessible(true); method.invoke(urlClassLoader, new Object[]{u}); } catch (Throwable t) { throw new IOException(“Error, could not add URL to system classloader”); } } […]

使用声明性服务在OSGi + Pax-Web中使用GWT的问题

我正在迁移在OSGi(Equinox)和Pax-web上运行的现有GWT应用程序,以使用Declarative Services而不是程序化Service Tracker。 我在Equinox中使用Pax-Web。 PAX-WEB War扩展器没有加载基于WAR的GWT应用程序,但是你不能在这种操作方法中使用声明式服务。 我成功地重构所有servlet退出战争并转换它们变成声明OSGi服务( 这样我就可以摆脱servlet中所有混乱的ServiceTracker代码和特定的OSGi依赖关系。 我进一步复制了所有其他web.xmlfunction,以使用[1]上的信息注册filter,提供静态内容和欢迎页面 此时,它通常应该可以工作,但我遇到了PAX-WEB的问题以及GWT尝试加载其资源的方式: 在加载序列化描述符时,GWT从本地上下文加载序列化策略文件。 在我的情况下,它试图解决这样的资源:/ctx/ctx/62394587E47773FB1594FF.gwt.rpc这个资源是由GWT编译器创建并划归:/战/ CTX / CTX /资源… 之前,使用标准的WAB映射( Webapp-Context: /ctx, Webapp-Root: /war )GWT将正确查找其资源。 现在我正在使用程序化资源映射: DefaultResourceMapping resourceMapping = new DefaultResourceMapping(); resourceMapping.setAlias( “/ctx” ); resourceMapping.setPath( “/war” ); GWT无法加载资源并产生以下错误: 2012-06-20 12:46:36.283:INFO:/:AbcProxy: ERROR: The serialization policy file ‘/ctx/ctx/600000000000000773FB1594FF.gwt.rpc’ was not found; did you forget to include it in this deployment? […]

测试使用PersistentEntityResourceAssembler的自定义RepositoryRestController

我有一个RepositoryRestController ,它为一些持久性实体公开资源。 我的控制器上有一个方法,它使用PersistentEntityResourceAssembler来帮助我自动生成资源。 @RepositoryRestController @ExposesResourceFor(Customer.class) @RequestMapping(“/api/customers”) public class CustomerController { @Autowired private CustomerService service; @RequestMapping(method = GET, value=”current”) public ResponseEntity getCurrent(Principal principal Long id, PersistentEntityResourceAssembler assembler) { return ResponseEntity.ok(assembler.toResource(service.getForPrincipal(principal))); } } (举例说明,但它可以节省关于我的用例的无关细节的太多细节) 我想为我的控制器编写测试(我的实际用例实际上值得测试),并且我正在计划使用@WebMvcTest。 所以我有以下测试类: @RunWith(SpringRunner.class) @WebMvcTest(CustomerController.class) @AutoConfigureMockMvc(secure=false) public class CustomerControllerTest { @Autowired private MockMvc client; @MockBean private CustomerService service; @Test public void testSomething() { // […]

使JsonNode可序列化

这似乎很简单,但我没有得到序列化的JsonNode反序列化。 这是我的测试课 import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Foo implements Serializable { private String string; private transient JsonNode jsonNode; public Foo(String string, JsonNode jsonNode) { this.string = string; this.jsonNode = jsonNode; } private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); if (this.jsonNode != null) out.writeObject((new ObjectMapper()).writeValueAsBytes(this.jsonNode)); // […]

使用Proguard导出已签名的Android apk

我想做什么: 从Eclipse中混淆并导出已签名的应用程序。 问题: 无论我在Project.properties和proguard-android.txt上写什么,我都会得到相同的控制台错误。 这让我不知道发生了什么,我开始感到痛苦。 我能做什么: 我可以在不使用Proguard的情况下导出项目。 我可以使用Proguard导出一个没有使用ABS(Action Bar Sherlock)的类似项目 我的问题: 是否有可能eclipse没有全部使用proguard-android.txt ? 当您包含ABS库时,您应该从项目中删除android-support-v4.jar ,因为该项目将使用库的一个。 我做了ABS网站的建议,但仍然无法正常工作。 我错过了什么吗? 代码: Project.properties: # This file is automatically generated by Android Tools. # Do not modify this file — YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize […]

如何更改json对象名称(键)?

只是一个简单的问题: 如果我有一个包含“key / value”的json对象,如下所示: “name”:”value” 我想将名称部分更改为其他内容,我该怎么办? 我不想删除并重新制作它。