English 中文(简体)
为什么会侵扰2 与一般人合作
原标题:Why does struts2 doesnt work with generics

I m struggling to make this work but with no luck.

Below is sample code and when I call edit method in the jsp all values are filled, but when I want to save changes then get an exception in OGNL. Maybe stuts2 doesn t work well with generics. Any suggestion would be more than appreciated.

public abstract class ActionHelper<T> extends ActionSupport{

    protected T entity;
    protected Integer id;

    public void setId(Integer id){
        this.id=id;
    }

    public void setEntity(T entity){
        this.entity=entity;
    }

    public void getEntity(T entity){
        this.entity=entity;
    }

    public String edit(){
        this.entity=fillEntity();
        return "edit";
    }
    public String save(){
        genericDao.save(entity);

    }
    protected abstract T fillEntity();
}

public class PersonAction extends ActionHelper<Person>{
    Person fillEntity(){
        return genericDao.find(id,Person.class);   
    }
}

<s:form action="person_save" method="post"> <s:hidden name="entity.id"> <s:textfield name="entity.name"> <s:textfield name="entity.surname"> </form>

最佳回答

表格的起始点是:格式,但最终标签只是一种......可能是一种打字?

您重新利用缺省准入信使来填补遗症,而不是按照 j命名公约,试图:

public Person getEntity(){
    return genericDao.find(id,Person.class);   
}

现在,OGNL将能够在个人行动中找到“实体”。

问题回答

暂无回答




相关问题
Generic constraint exclusion

Sorry for asking silly question Is it possible to enforce constraint on generic in such a way that the given T can be derived from any reference Type except some A,B,C (where A,B,C are reference ...

Can a Type Derive from Itself?

When enforcing a Generic constraint class GenericTest { public void Sample<T>(T someValue) where T:Racer,new() { Console.WriteLine(someValue.Car); } } The Type T should be ...

C# Deriving Generic Methods

When i need to pass a Generic Type I can use the Syntax (Example : Ofcourse it is not a Generic Method) public void Sample(T someValue) { ...... } What is the benefit of declaring Sample<T>...

What is the benefit to using List<T> over IEnumerable<T>?

or the other way around? I use generic lists all the time. But I hear occasionally about IEnumerables, too, and I honestly have no clue (today) what they are for and why I should use them. So, at ...

热门标签