gpt4 book ai didi

java - Wicket 和 Spring 集成

转载 作者:行者123 更新时间:2023-11-29 09:50:45 24 4
gpt4 key购买 nike

我有一个 wicket 联系表单,我收到了表单对象。现在我需要将这个对象传递给 Spring 服务。

package com.mysticcoders.mysticpaste.web.pages;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import com.mysticcoders.mysticpaste.model.Contact;
import org.apache.wicket.model.CompoundPropertyModel;

import com.mysticcoders.mysticpaste.services.IContact;


public class FormPage extends WebPage
{

private Contact contact;
private IContact icontact;

public FormPage()
{
// Add a FeedbackPanel for displaying our messages
FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
add(feedbackPanel);

Form<Object> form = new Form<Object>("contactForm",
new CompoundPropertyModel<Object>(contact))
{
private static final long serialVersionUID = 1L;

protected void onSubmit(Contact contact)
{
icontact.saveContact(contact);
}
};
form.add(new TextField<Object>("name"));
form.add(new TextField<Object>("email"));
form.add(new TextField<Object>("country"));
form.add(new TextField<Object>("age"));

add(form);
// add a simple text field that uses Input's 'text' property. Nothing
// can go wrong here

}


}

我非常确定我们需要对应用程序上下文 xml 做一些我可能需要连接的地方。

My Application-context.xml 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="WicketApplication" class="com.mysticcoders.mysticpaste.web.pages.WicketApplication" />

</beans>

My Question is simple.

  1. 我应该怎么做才能让我的onSubmit 方法调用 Spring服务?
  2. 有人可以告诉我需要什么吗在我的修改Application-context.xml 这样一次表单被提交,它联系Spring 服务类。

最佳答案

Wicket-Spring集成显示了如何将 Spring Beans(例如您的 IContactService bean)注入(inject) Wicket 页面的各种方法。

基本上,在配置组件注入(inject)器之后,您最终会得到以下代码:

public class FormPage extends WebPage
{
@SpringBean
private IContact icontact;
...
Form<Object> form = new Form<Object>("contactForm",
new CompoundPropertyModel<Object>(contact))
{
private static final long serialVersionUID = 1L;

protected void onSubmit(Contact contact)
{
icontact.saveContact(contact);
}
};

关于java - Wicket 和 Spring 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4550131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com