File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes form values not showing in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "form values not showing in jsp" Watch "form values not showing in jsp" New topic
Author

form values not showing in jsp

Pam Theod
Greenhorn

Joined: Apr 19, 2006
Posts: 14
Hi All,
I have a simple jsp where I am displaying 2 columns using html:text and c tag. When the jsp is displayed, the form values are not being populated.

I have a system.out.println() in action class and its not showing in the console. I don't know what I'm doing wrong.

I'm running this in tomcat

Here is the code snippet

jsp: aa.jsp - is in webapps\root folder

<html:form action="TestAction">
<c ut value="${role}"/>
<html:text property="jobMessage"/>
</html:form>

struts-config.xml - which is under WEB-INF

<form-beans>
<form-bean name="testForm" type="com.test.TestForm"/>
</form-beans>

<action path="/aa"
type="com.test.TestAction"
scope="request"
name="testForm">
<forward name="success" path="/aa.jsp"/>
</action>

TestAction.class and TestForm.class are under WEB-INF\classes\com\test

TestAction

public class TestAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

System.out.println("enter");

List jobList = new ArrayList();
RunJob job = new RunJob();
job.setJobId("1");

jobList.add(job);

String msg = null;

if(jobList.size() == 0) {
msg = "There are no runjobs";
} else {
msg = jobList.size() + " runjob(s) are in the queue";
}

// set form values
TestForm testForm = (TestForm) form;
String role = "admin";

testForm.setRole(role);
testForm.setMsg(msg);

return mapping.findForward("success");
}
}


Form

public class TestForm extends ActionForm {

private String role;
private String msg;

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}

Thanks in advance.
p pro
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Do you have an action definition in struts-config with a path of "/TestAction"? The html:text tag will use the form bean (name property) of the enclosing html:form tag.

Your cut tag probably needs to use "testForm.role". (I tend to use the bean:write tag just because I know it...<bean:write name="testForm" property="role" />).

- Brent
Pam Theod
Greenhorn

Joined: Apr 19, 2006
Posts: 14
I have this in struts-config.xml

<action path="/aa" type="com.test.TestAction" scope="request" name="testForm">
<forward name="success" path="/aa.jsp"/>
</action>

Should I define action class like I did with TestForm

How do I do that.

Also, I have a question. When the jsp opens, on load will it find the action from the action mapping defined in struts-config and run execute method. I want to know when will execute method get executed.

Thanks in advance.

P pro
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Do you have lines like this in your JSP?

<%@ taglib prefix="html" uri="/tags/struts-html" %>
<%@ taglib prefix="c" uri="/tags/jstl-core" %>

When you specify the <html:form> tag, you are specifying the action that will get called when you submit the form. It might be helpful to use realistic names for you action, forms and jsp pages. Like SaveUser, UserForm and UserDetails.jsp.

- Brent
Pam Theod
Greenhorn

Joined: Apr 19, 2006
Posts: 14
Brent,
I finally figured the problem .I was using Action instead of DispatchAction. Thanks for all your suggestions.

Thanks,
P pro
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: form values not showing in jsp