我尝试生成动态gwt ui.结果我得到一个像这样的html片段:
<ol>
<li>MyLabel</li>
<li><input type="text"></li>
</ol>
Run Code Online (Sandbox Code Playgroud)
Label应该是GWT标签,输入应该是GWT TextBox.我怎样才能通过GWT实现这一目标?我试过使用HTMLPanel类,但是如何注入
<li>
Run Code Online (Sandbox Code Playgroud)
标签?
我不能使用UIBinder,因为我想动态创建如上所示的片段.
我想写一个CDI拦截器.如果我的注释仅包含1个参数,则截取效果很好,但如果使用2个参数则会中断.问题是为什么?
拦截器类:
@Monitored
@Interceptor
@Priority(APPLICATION)
public class MonitoringInterceptor {
@AroundInvoke
public Object logInvocation(InvocationContext ctx) throws Exception {
LOGGER.error("METHOD CALLED!!!"); //this is not called when annotation has 2 parameters
return ctx.proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
注释:
@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Inherited
public @interface Monitored {
public String layer() default "BUSINESS";
public String useCase() default "N/A";
}
Run Code Online (Sandbox Code Playgroud)
现在有趣的部分:
@Stateless
public class MyBean {
//this does not work, why?
@Monitored(layer = "BUSINESS", useCase = "test")
//if I use the following annotation it works well
//@Monitored(layer …Run Code Online (Sandbox Code Playgroud) 我有以下界面
public interface IMyMapper<T> {}
Run Code Online (Sandbox Code Playgroud)
和实施
public class MyMapper implements IMyMapper<MyClazz> {}
Run Code Online (Sandbox Code Playgroud)
现在我想将类MyMapper注入无状态bean:
@Stateless
public class MyService {
@Inject
MyMapper mapper; //<-- does not work
@Inject
IMyMapper<MyClazz> mapper; //<-- also does not work
}
Run Code Online (Sandbox Code Playgroud)
我的问题是注射不起作用.我得到一个例外:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type MyMapper with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject mypackage.MyService.mapper
at mypackage.MyService.mapper(MyService.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:370)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:291)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:165)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:529)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:515)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:490)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:419)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:225)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328)
at …Run Code Online (Sandbox Code Playgroud) 我开始学习Java并在java中编写我的第一个实用程序类,它们应该在生产中.当它处理异常时我有些迷茫.关于给定代码行中有多少个try语句,是否有一些大概的数字?
应该有多少代码处理异常.. Eclipse的任何插件?
最佳做法是在try块中包含3-4个语句并捕获异常或在try块中包含10-12行,然后包含2-3个catch语句,捕获不同类型的异常,例如由File相关或由我自己抛出课程或其他一些第三方课程..?前者对眼睛有点不悦,而且代码太膨胀了......
这种常见的做法是只围绕try块中的那个代码,它可以抛出异常,或者可以很好地标记周围的代码以及内部尝试说明如何使用文件句柄等.
任何指针..?
我有一些数据是从与我的图像文件对应的文本文件中加载的.此数据现在是2D数组.我想要显示这张图片.显然,图像显示的格式为bufferedimage.但我的只是简单的2D双格式.如何调整图像的大小,意味着使图像变大两倍(当然需要插值)
换句话说,我们怎样才能在java中实现"imshow"和"imresize"Matlab等价?
我想知道处理这样的数据模型的最佳实践是什么:

我们有 3 个实体:
请注意,实体表示为 java 类并将通过休眠映射到数据库,无论如何我认为可以在不了解这些技术的情况下回答这个问题。
Role&User和Role&之间存在多对多关系Permission。
这里可以有双向关系吗?所以,你可以要求Role给你他所有的成员,并要求User给你他所有的角色。
可以询问两个实体是非常舒服的,但是一个缺点是,无论何时删除关系,您都必须管理这两个实体。
例如,如果您Role从 a 中删除,User则还必须User从Role. 如果有很多这样的关系,这可能会很烦人。因此,我想知道最佳做法是什么。
我正在尝试用 java 实现一个简单的承诺系统。我这样做是为了特殊目的,所以请不要推荐任何库。
当我尝试实现一个thenApply()以 Function 作为参数的方法时遇到问题,类似于CompletableFuture所具有的方法,因此返回另一种类型的承诺。
承诺接口:
public interface Promise<T> {
Promise<T> then(Consumer<T> handler);
<U> Promise<U> thenApply(Function<T, U> handler);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我的实现:
public class PromiseImpl<T> implements Promise<T> {
private List<Consumer<T>> resultHandlers = new ArrayList<>();
public PromiseImpl(CompletableFuture<T> future) {
future.thenAccept(this::doWork);
}
@Override
public Promise<T> then(Consumer<T> handler) {
resultHandlers.add(handler);
return this;
}
@Override
public <U> Promise<U> thenApply(Function<T, U> handler) {
// How to implement here??? I don't have the result yet
handler.apply(?);
}
private void onResult(T result) {
for …Run Code Online (Sandbox Code Playgroud) 我想知道为什么我的 JDialog 将我的主应用程序推入后台。这意味着,如果显示 JDialog 并且用户单击“确定”或“取消”,则主应用程序将失去焦点并将被推入后台。
经过调查,我发现,只有当我在显示 JDialog 时禁用主框架时,才会发生这种行为。
可以使用以下代码重现此行为:
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class FocusTest {
private JFrame frame;
public FocusTest() {
frame = new JFrame();
frame.setSize(200,200);
JButton btn = new JButton("Open Dialog");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
callDialog(null, "title", "message");
}
});
frame.add(btn);
frame.setVisible(true);
}
private void callDialog(Component parent, String title, String message) {
frame.setEnabled(false);
Thread t1 = new Thread(new Runnable() {
public void run() …
Run Code Online (Sandbox Code Playgroud)Run Code Online (Sandbox Code Playgroud) 当您使用 JAXB 生成 java 类时,您将始终获得一个名为 ObjectFactory 的类。在此类中,有一个私有属性 QName,其中包含命名空间。
是否可以告诉生成器使该属性可以从外部访问。那么也许将其公开或为其创建一个吸气剂?
如何在运行方法时而不是在方法后强制在Spring Boot中使用Spring Data强制进行事务提交?
我在这里读到,@Transactional(propagation = Propagation.REQUIRES_NEW)在另一堂课上应该有可能,但对我不起作用。
有什么提示吗?我正在使用Spring Boot v1.5.2.RELEASE。
@RunWith(SpringRunner.class)
@SpringBootTest
public class CommitTest {
@Autowired
TestRepo repo;
@Transactional
@Commit
@Test
public void testCommit() {
repo.createPerson();
System.out.println("I want a commit here!");
// ...
System.out.println("Something after the commit...");
}
}
@Repository
public class TestRepo {
@Autowired
private PersonRepository personRepo;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createPerson() {
personRepo.save(new Person("test"));
}
}
Run Code Online (Sandbox Code Playgroud) 我想在有人编辑单元格时在JTable单元格上方显示文本.该文本与工具提示几乎相同,只有在编辑单元格时才会显示文本,文本应保持到编辑完成为止.
我怎么能实现这样的行为?
我到目前为止尝试的是覆盖getCellEditor方法,JTable但只设置标准工具提示,但我需要在编辑时永久显示文本.
@Override
public TableCellEditor getCellEditor(int row, int column) {
TableCellEditor editor = super.getCellEditor(row, column);
Component component = editor.getTableCellEditorComponent(this, getValueAt(row, column), isCellSelected(row, column), row, column);
if(component instanceof JTextField) {
JTextField textfield = (JTextField) component;
textfield.setToolTipText("tooltip");
}
return editor;
}
Run Code Online (Sandbox Code Playgroud) 因此,用户可以从2个日历中选择2个不同的日期,开始日期和结束日期,当他们点击add所选日期之间的日期时,将添加到数据库中,每个日期作为单独的记录.
这工作正常,但我不希望周末添加到数据库.
我已更新了datepicker的用户界面http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.html,
但如果用户选择fri-mon,fri,sat,sun and mon则会将其添加到数据库中.如果datyofweek不是星期六或星期日,我试图只运行代码
public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate)
{
DateTime startDates = Convert.ToDateTime(HolidayDate),
endDates = Convert.ToDateTime(endDate);
while (startDates <= endDates)
{
if (startDates.DayOfWeek != DayOfWeek.Saturday || startDates.DayOfWeek != DayOfWeek.Sunday)
{
Holiday holiday1 = new Holiday();
holiday1.PersonId = PersonId.Value;
holiday1.HolidayDate = startDates;
db.Holidays.AddObject(holiday1);
db.SaveChanges();
startDates = startDates.AddDays(1);
}
}
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
任何帮助?谢谢
java ×10
java-ee ×2
java-ee-7 ×2
swing ×2
arrays ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
cdi ×1
datamodel ×1
exception ×1
gwt ×1
interceptor ×1
jaxb ×1
jtable ×1
promise ×1
spring-boot ×1
spring-data ×1
transactions ×1
xjc ×1