• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Form Data not being populated in Struts 2

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic