You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ryan webb <we...@gmail.com> on 2008/03/06 06:12:22 UTC
I cannot transfer property to Form Bean
Dear fellow Struts users,
I am new in using Struts and I request your help.
Situation:
I am using Netbeans 6.0; Struts 1.2.9; Tomcat 6.0.14
I created an <html:select property="formatList"> in my jsp page, what is it
does is for sorting purposes.
here's the snippet:
<html:form action="sortList.do">
<html:select property="formatList">
<html:option value="format"/>
<html:option value="DVD+R"/>
<html:option value="DVD-R"/>
</html:select>
<html:submit value="Sort Now"/>
</html:form>
And for my SortListFormBean.java I have a property private String formatList
with Getter and Setter
Problem:
when I am debugging, I found out that formatList property
fromSortListFormBean.java is always equal to null.
I am doing something wrong?
Godbless,
Ryan Webb --Philippines
Re: I cannot transfer property to Form Bean
Posted by ryan webb <we...@gmail.com>.
Dear Antonio,
That is same in my source code..do you think that is the cause?
I will check that one..And send you informations soon!
God bless,
Ryan Webb -- Philippines
On Thu, Mar 6, 2008 at 5:03 PM, Antonio Petrelli <an...@gmail.com>
wrote:
> 2008/3/6, ryan webb <we...@gmail.com>:
> >
> > <form-bean name="SortListActionForm" type="
> > formbeans.SortListActionForm"/>
>
> <form-bean name="SortListActionForm" type="
> > formbeans.SortListActionForm"/>
>
>
>
> Why two form beans with the same name? Is it a typing mistake, or an error
> of your code?
>
> Antonio
>
Re: I cannot transfer property to Form Bean
Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/6, ryan webb <we...@gmail.com>:
>
> <form-bean name="SortListActionForm" type="
> formbeans.SortListActionForm"/>
<form-bean name="SortListActionForm" type="
> formbeans.SortListActionForm"/>
Why two form beans with the same name? Is it a typing mistake, or an error
of your code?
Antonio
Re: I cannot transfer property to Form Bean
Posted by ryan webb <we...@gmail.com>.
Yes I agree..I cannot find the problem, I think it is much better if there's
2 pairs of eyes looking.
Here is the Action code.
public class SortListAction extends org.apache.struts.action.Action {
/* forward name="success" path="" */
private final static String SORT_LIST = "sortList";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
SortListActionForm slaf = new SortListActionForm();
MediaDao mediaDao = new MediaDao();
ArrayList aList = mediaDao.sortMediaList(slaf.getFormatList());
request.setAttribute("medialist", aList.iterator());
return mapping.findForward(SORT_LIST);
}
}
And here I have the ActionForm (I commented validate method since user will
be selecting choices I defined):
package formbeans;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
/**
*
* @author wst_01
*/
public class SortListActionForm extends org.apache.struts.action.ActionForm{
private String formatList;
public SortListActionForm() {
super();
// TODO Auto-generated constructor stub
}
// public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
// ActionErrors errors = new ActionErrors();
// if (getName() == null || getName().length() < 1) {
// errors.add("name", new ActionMessage("error.name.required"));
// // TODO: add 'error.name.required' key to your resources
// }
// return errors;
// }
public String getFormatList() {
return formatList;
}
public void setFormatList(String formatList) {
this.formatList = formatList;
}
}
And lastly, I have here the Struts-config.xml
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean name="SortListActionForm" type="
formbeans.SortListActionForm"/>
<form-bean name="SortListActionForm" type="
formbeans.SortListActionForm"/>
<form-bean name="LoginForm" type="formbeans.LoginForm"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>
<action-mappings>
<action input="/administratorsLogin.jsp" name="LoginForm"
path="/login" scope="request" type="actions.LoginAction">
<forward name="loginSuccess" path="/adminPage.jsp"/>
<forward name="loginFail" path="/administratorsLogin.jsp"/>
</action>
<action path="/mediaList" scope="request" type="
actions.MediaListAction">
<forward name="mediaListView" path="/adminPage.jsp"/>
</action>
<action input="/adminPage.jsp" name="SortListActionForm"
path="/sortList" scope="request" type="actions.SortListAction"
validate="true">
<forward name="sortList" path="/adminPage.jsp"/>
</action>
I attached files you requested, I think it's much better to see them in
color..=) I also attached files related to databases..(just incase you might
need them).
God bless,
Ryan Webb -- Philippines
On Thu, Mar 6, 2008 at 4:42 PM, Antonio Petrelli <an...@gmail.com>
wrote:
> 2008/3/6, ryan webb <we...@gmail.com>:
> >
> > Yes I did select an element I choose DVD+R then when I click sort now
> > button
> > the WebPage exploded
> > containing Tomcat Error Message. (null pointer exception).
>
>
>
> Mmmm this is strange. Can I see your Action, ActionForm and
> struts-config.xml (related to this action) code?
>
> Antonio
>
Re: I cannot transfer property to Form Bean
Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/6, ryan webb <we...@gmail.com>:
>
> Yes I did select an element I choose DVD+R then when I click sort now
> button
> the WebPage exploded
> containing Tomcat Error Message. (null pointer exception).
Mmmm this is strange. Can I see your Action, ActionForm and
struts-config.xml (related to this action) code?
Antonio
Re: I cannot transfer property to Form Bean
Posted by ryan webb <we...@gmail.com>.
Dear Antonio,
Yes I did select an element I choose DVD+R then when I click sort now button
the WebPage exploded
containing Tomcat Error Message. (null pointer exception).
By the way, thank you very much for reading my email and for the reply..=)
God bless,
Ryan Webb --Philippines
On Thu, Mar 6, 2008 at 4:35 PM, Antonio Petrelli <an...@gmail.com>
wrote:
> 2008/3/6, ryan webb <we...@gmail.com>:
> > <html:form action="sortList.do">
> > <html:select property="formatList">
> > <html:option value="format"/>
> > <html:option value="DVD+R"/>
> > <html:option value="DVD-R"/>
> > </html:select>
> > <html:submit value="Sort Now"/>
> > </html:form>
> > when I am debugging, I found out that formatList property
> > fromSortListFormBean.java is always equal to null.
> >
> > I am doing something wrong?
>
> Do you select an element before submitting the form?
>
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: I cannot transfer property to Form Bean
Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/6, ryan webb <we...@gmail.com>:
> <html:form action="sortList.do">
> <html:select property="formatList">
> <html:option value="format"/>
> <html:option value="DVD+R"/>
> <html:option value="DVD-R"/>
> </html:select>
> <html:submit value="Sort Now"/>
> </html:form>
> when I am debugging, I found out that formatList property
> fromSortListFormBean.java is always equal to null.
>
> I am doing something wrong?
Do you select an element before submitting the form?
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org