*
The moose likes Struts and the fly likes Form Data not being populated in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form Data not being populated in Struts 2" Watch "Form Data not being populated in Struts 2" New topic
Author

Form Data not being populated in Struts 2

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 257
My Form data is not being populated in struts 2.
Following is the code.

struts.xml



Register.jsp



Please Help as I am unable to figure out why form data is not being populated.

Lakshmi Suguna
Greenhorn

Joined: Feb 20, 2008
Posts: 1
If you are using Struts 2.0 then your action class need not extend ActionSupport.

Second important thing is textfield name in JSP and String variable declaration in Action class must be the same since it is case sensitive. Unless these two are same form data won't be populated in Struts2.0.
So try renaming your jsp fields to firstname, lastname, etc instead of register.firstName. register.lastName.

Hope this works.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 257
I renamed the jsp fields to firstname instead of register.firstName and it worked. Thanks a lot. One Question if my class doesn't extend ActionSupport then will the execute method be called and will the form values be populated automatically.
breathtech learn
Greenhorn

Joined: Jun 19, 2008
Posts: 1
Originally posted by Siddharth Bhargava:
I renamed the jsp fields to firstname instead of register.firstName and it worked. Thanks a lot. One Question if my class doesn't extend ActionSupport then will the execute method be called and will the form values be populated automatically.


Indeed, the execute() method would be parameterless and void return
Tuni Singh
Greenhorn

Joined: Aug 14, 2008
Posts: 1
Hi,
I am having a similar problem and I changed the field of my jsp to be matched with the fields in my Action class.

Here is what I have..
Action class

public class ClientAction extends ActionSupport {
private static final long serialVersionUID = 5884818679807331052L;
private Long _clientId;
private String _name;
private List<Client> _clients;
private Client _client;
ClientSession _clSess = ServiceLocator.getLocal();
// public static final String CLIENT_JNDI_NAME = "web/ClientSessionBean/local";

public Long getClientId() {
return _clientId;
}
public void setClientId(Long clientId) {
_clientId = clientId;
}

public String getName() {
return _name;
}

public void setName(String name) {
_name = name;
}

@Override
public String execute() throws Exception {

_clients = _clSess.getAllClients();
return "success";
}


public String getAllClient(){
ClientSession cl = ServiceLocator.getLocal();
_clients = cl.getAllClients();
System.out.println("client list from Action.."+ _clients.size());
return "success";
}

public List<Client> getClients() {
return _clients;
}

public void setClients(List<Client> clients) {
_clients = clients;
}
}



------------------------------
My JSP

<s:form action="insertOrUpdate" method="post">
<s:hidden name="clientId"/>
<s:textfield name="name" size="30" value = "%{client.name}"/>
<s:submit key="button.submit" />
<s:reset key="button.cancel" />
</s:form>

-----------------------

but my text field is not getting populated.


Any suggestion...

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form Data not being populated in Struts 2
 
Similar Threads
Error while validating the input
Struts2 newB: some simple questions
No Getter method for LastName property of bean
Integrating Struts 2 with Hibernate.
Validation Issues