Search code examples
javajqueryjspstruts2ognl

How to get data from JSP to Action class by id instead of property in Struts 2?


I am doing on Java Struts 2 framework.

Normally, I can get data from my JSP through the get set method in Form.java (action class). Below is my example :

In main.jsp file:

<html:text property="campaignName" size="50" maxlength="50" />

thus, I can get this text box name by get set method in the action class, the below is code from

mainForm.java :

private String campaignName = null;

public String getCampaignName() {
    return campaignName;
}

public void setCampaignName(String campaignName) {
    this.campaignName = campaignName;
} 

However, because of I want to use jQuery to do something, I no longer use <html:text> as text box, but I use <input type="text" id="datepicker" />.

Because of without property attribute inside this text box, I cant get the value from this text box. I have tried to add property="something" inside the text box also, but get set method in mainForm.java is return null.

I would like to ask, how can I get the value by this text box?


Solution

  • <s:textfield name="campaignName" size="50" maxlength="50" />    
    

    or

    <input type="text" name="campaignName" size="50" maxlength="50" />
    

    The name need to be matched with the field name