English 中文(简体)
Stripes: I can pre-populate a form, but after submit the formBean is null
原标题:
  • 时间:2009-12-06 18:05:37
  •  标签:
  • stripes

I can pre-populate my Stripes JSP form with an object, client in my case, but when I submit this form, my object is returning as null.

I have created a second "temp" object that is a parallel duplicate of client and this retains its values, so I can t see an issue passing an object in the request

My form is as follows :

<s:form beanclass="com.jameselsey.salestracker.action.ViewClientAction">
            <s:hidden name="clientA" value="${actionBean.clientA}"/>
            <s:hidden name="clientId" value="${actionBean.clientId}"/>

            <table>
                <tr>
                    <td>Name : </td>
                    <td><s:text name="client.name"/></td>
                </tr>
                <tr>
                    <td>Sector : </td>
                    <td><s:text name="client.sector"/></td>
                </tr>
              <!-- omitted some attirbutes, not needed here -->
            </table>
        </s:form>

My action looks like

public class ViewClientAction extends BaseAction
{

    @SpringBean
    ClientService clientService;// = new ClientService();
    private Integer clientId;
    private Client client;
    private Client clientA;

    public void setClient(Client client)
    {
        this.client = client;
    }
    public Integer getClientId()
    {
        return clientId;
    }

    public void setClientId(Integer clientId)
    {
        this.clientId = clientId;
    }

    public Client getClientA()
    {
        return clientA;
    }

    public void setClientA(Client clientA)
    {
        this.clientA = clientA;
    }



    public Client getClient()
    {
        return client;
    }

    @DefaultHandler
    public Resolution quickView()
    {
        clientA = clientService.getClientById(clientId);
        client = clientService.getClientById(clientId);
        return new ForwardResolution("/jsp/viewClientQuickView.jsp");
    }

    public Resolution save()
    {
        clientService.persistClient(client);
        return new ForwardResolution("/jsp/reports.jsp");
    }

    public Resolution viewClientInfo()
    {
        client = clientService.getClientById(clientId);
        return new ForwardResolution("/jsp/viewClientClientInfo.jsp");
    }
...

If I set a breakpoint at clientService.persistClient(client); I can see that ClientA has all of the original values of the object, yet client is nulled.

Have I missed something that binds the form bean to the client object in my action?

Thanks

最佳回答

Add this line in your JSP:

    <s:hidden name="client" value="${actionBean.client}"/>
问题回答

I got this scenario working by adding a @Before method to re-hydrate the nested object. After this, save works properly

@Before(stages = LifecycleStage.BindingAndValidation)
public void rehydrate() {
   if (context.getRequest().getParameter("save")!=null){
       this.domainObject = getHibernateSession().load(DomainObject.class, context.getRequest().getParameter("id"));
   }
}

public void save(){
    Session session=getHibernateSession();
    session.update(domainObject);
    session.commit();
    //...
}




相关问题
Mapping Relationships with Hibernate

I m still learning how to set up these mappings using the JPA annotations so this may be a beginner mistake. I have a User class and a Course class. In the database each Course has a User foreign key ...

Unit testing stripes validation annotations directly

Stripes allows you to validate your form input values using the @Validate annotation on your member variables. Does anyone have any experience testing these annotations directly. I could do this by ...

Setting createdBy and updatedBy in JPA entities automatically

I m working on a JPA (Hibernate implementation of), Spring and Stripes web app. I have a number of JPA entities that have the following fields in common for both audit and query purposes: createdBy - ...

Handling data in ActionBean

how do I save data between two events in ActionBean? In the following example I create contact in addContact(), preserve it and save it to attribute contact. When i try to access that contact after ...

Problem with Stripes submit

I m currently experiencing a problem with submit button in Stripes. It completely ignores event, that it should call. Actionbean is working on links with no problems... Im stuck on that for like 3 ...

热门标签