aspose file tools*
The moose likes Struts and the fly likes Struts custom form question..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts custom form question....." Watch "Struts custom form question....." New topic
Author

Struts custom form question.....

Vladislav Semenov
Greenhorn

Joined: Mar 01, 2004
Posts: 5
In all Struts examples DynaActionForm links with the concrete Action in action-mappings, it looks something like:

<action name="UserForm" type="com.tbi.actions.UsersAction"
scope="session" path="/users">
</action>

where name is the <form-bean> name.

I want action to use different form beans depending on request parameters,
so I define action-mapping without name attribute:

<action type="com.tbi.actions.UsersAction" scope="session" path="/users" />

and in JSP I write something like

<html:form name="AbonentForm1" type="org.apache.struts.action.DynaActionForm" action="/users" >
<html:text property="name" size="16"/>
<html:form/>

in struts-config I define <form-bean>:

<form-bean
name="AbonentForm1"
type="org.apache.struts.action.DynaActionForm">
<form-property
name="name"
type="java.lang.String"/>
</form-bean>

and get this:

java.lang.NullPointerException
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:1162)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:772)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:952)
at org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:176)


What's wrong?

Can't I not define name attribute in action-mapping and use custom formBean?

[ August 31, 2004: Message edited by: Vladislav Semenov ]
[ August 31, 2004: Message edited by: Vladislav Semenov ]
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
No its not the problem with the attribute name but if u are planning to use a form bean attached with an action that should be mentioned in struts-config u cant neglect that there and even writing it in <html:form of jsp wont work ............
these attributes in jsp are only if u want to name the form as per ur wish if u dont give struts will defaultly name the form(i am taklking about <form name='")as the one in strust-condifg ............

that null pointer is bcoz its not able to find the inctance of ur form bean
Vladislav Semenov
Greenhorn

Joined: Mar 01, 2004
Posts: 5
Originally posted by sreenath reddy:
No its not the problem with the attribute name but if u are planning to use a form bean attached with an action that should be mentioned in struts-config


And if I want to use a form bean not attached with an action?

Can I use custom form with the custom action?

If I can't do it - I can't write complicated actions which can work with the set of forms.....

[ September 01, 2004: Message edited by: Vladislav Semenov ]
[ September 01, 2004: Message edited by: Vladislav Semenov ]
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
Here are the key considerations:

1 Action is associated with no more than 1 Form Bean.
1 Form Bean can be associated with any number of actions.

So if you want to dynamically switch forms, you need to dynamically forward to different actions.

Action 1/Form 1 -> Action 2/Form 2 or Action 3/Form 3 or...

This direction can be done many ways. Many people will call this action chaining and tell you that this is a bad idea, but in this case -- assuming that Action 1 does not do anything other than the redirect -- it should be perfectly fine.

BTW, DynaForms are handy for proofing out an app but they make complex [custom] validations very difficult as you have to treat them similar to a Map. I know a lot of people like them. It's simply my opinion that in a large app they are probably more work to maintain than the standard Java code base of a form bean.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts custom form question.....