wood burning stoves 2.0*
The moose likes Struts and the fly likes Action Form Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action Form Problem" Watch "Action Form Problem" New topic
Author

Action Form Problem

Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Hi Guys,

Thanks for your continuous help for my questions.

I have another problem,
I have a form bean in session scope, While populating the form bean i am not taking from object from the execute method parameter. I am initializing myself in the progam becuase the form bean is in session scope.

My problem is if i initialize the form in the display action and populate it. All the variables in the form are not null, but i am not null pointer exception at the jsp saying that the same variable is null.

Thanks Any advance,
Any suggestions are welcome
Srilakshmi
candy tang
Greenhorn

Joined: May 16, 2005
Posts: 2
I am Chinese,so My English ability is not good,but I think I know your problem.
I think that maybe variables in your formbean and your parameter in form in JSP are not matching. Induce variables in your formbean is null.please check your JSP and formbean.


Beyond me if you can!
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
In my Display Action if i get form object from method parameter 'form', Then i am not getting null pointer exception.

If i get like that every time that form is displaying first retrieved values instead of taking dynamically passed values.

I dont know what is the problem here.

Help me
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
help me :-(
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I suppose the submitting action for that page does not use the same ActionForm as your Setup (or as you called it, Display) Action.

If I am not correct, please post your Setup Action's execute method, your <html:form> tag from the jsp, and your ActionMapping from struts-config that matches the action attribute from the html:form tag.


A good workman is known by his tools.
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Hello,

My Display Action Java is


import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class DisplayTrans extends Action {

int index = -1;
ArrayList callList = null;
TransForm transForm = null;
HttpSession session;
public DisplayTrans() {
}

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req,HttpServletResponse res)
throws Exception {
int index = -1;
session = req.getSession();
transForm = (TransForm)form;
// Doing all the code for populating transForm
form = (ActionForm)transForm;
TransForm tran = (TransForm)form;
System.out.println("From DISPLAY TRANS ==== "+tran.getParamedicIds());
// The above system out is retrieving values from the getter method
return mapping.findForward("success");
}
}

struts-config action mapping entry is

<form-bean name="transForm" type="org.xxxx.cts.actionforms.TransForm"/>

<action path="/DisplayTrans"
type="org.xxxx.cts.actions.DisplayTrans"
name="transForm"
scope="session" validate="false">
<forward name="success" path="/jsp/TRANS.jsp" />
</action>

HTML Form is

<html:form action="/SubmitTrans.do">
<html:select name="transForm" property="paramedicName" size="1">
<html ptions name="transForm" property="paramedicIds" labelName="transForm" labelProperty="paramedicNames"/>
</html:select>
</html:form>
Harinath Kuntamukkala
Ranch Hand

Joined: May 17, 2005
Posts: 37
Check your action-mapping PATH and <html:form action--both are not same in ur application...
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
i has another mapping to submit the form called submitTrans.do
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I asked for the ActionMapping of the submitting Action.

First, get rid of the instance variables in your Action class. Never, ever, ever use instance variables in an Action class.

There is a bunch of unnecessary casting in the Action as well.
form = (ActionForm)transForm;
TransForm tran = (TransForm)form;
There's no need for that.

What exactly is the error again? - copy/paste is good for communicating that.
Also, I recommend using html ptionsCollection over html ptions.
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Thanks for the correction marc!!!


What is my problem is i am not able to display a jsp with dynamic values with an action form which is in session scope.

The scenario is i have list and am calling same .do for the rows in the list

If i retrieve the jsp first time with a record, for all the rest of the records the jsp is displaying with the same first record values.
That means the action form bean is not refreshing for every jsp or DisplayAction.do call
I want to refresh the form bean for every DisplayAction.do for that i changed the DisplayAction and instantiated my form bean instead of taking it from the execute method parameter Then i am getting the following exception.

It worked perfect if i put the formbean scope to session
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
i am sorry for the mistake!!

The last line it worked good with request scope
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Two required mappings for the problem

<action path="/SubmitTrans"
type="org.fdny.cts.actions.SubmitTrans"
name="transForm"
scope="session"
validate="true"
input="/FailedTrans.do">
<forward name="success" path="/html/CloseWindow.htm"/>
<forward name="failure" path="/DisplayTrans.do"/>
</action>
<action path="/FailedTrans"
type="org.fdny.cts.actions.FailedTrans"
name="transForm"
scope="session" validate="false">
<forward name="success" path="/jsp/TRANS.jsp" />
</action>
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Srilakshmi Vara:
Two required mappings for the problem

<action path="/SubmitTrans"
type="org.xxxxx.cts.actions.SubmitTrans"
name="transForm"
scope="session"
validate="true"
input="/FailedTrans.do">
<forward name="success" path="/html/CloseWindow.htm"/>
<forward name="failure" path="/DisplayTrans.do"/>
</action>
<action path="/FailedTrans"
type="org.xxxxx.cts.actions.FailedTrans"
name="transForm"
scope="session" validate="false">
<forward name="success" path="/jsp/TRANS.jsp" />
</action>


Why have FailedTrans? Doesn't it make sense to make the input value for SubmitTrans be the same as the failure forward (DisplayTrans.do)?

What is my problem is i am not able to display a jsp with dynamic values with an action form which is in session scope.
What does "not able to display" LOOK like? If you get a message, please copy it here. If you get a completely blank screen, please say so.
 
 
subject: Action Form Problem