You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zsolt Koppany <zk...@intland.com> on 2004/12/23 13:12:03 UTC
Which setter do I need in the ActionForm for this example?
Hi,
I have tried several setters in the Form class but none of them are called
when the form is terminated. How should me setter look like to the property
"dropDownSelection". The getter method is:
public Map getDropDownSelection()
{
return dropDownSelection;
}
The setter "setDropDownSelection(String key, Object value)" is never called.
<html:select multiple="true" size="${selectionSize}"
styleClass="fixSelectWidth"
property="dropDownSelection(${tracker.id}_${label_id})">
<c:forEach items="${choiceValues}" var="cv">
<html:option value="${cv.value}">
<c:out value="${cv.label}"
/>
</html:option>
</c:forEach>
</html:select>
Zsolt Koppany
Phone: +49-711-722 1874
--
Intland Software GmbH, Schulze-Delitzsch-Strasse 16
D-70565 Stuttgart, Germany
Phone: +49-711-722 1873, e-mail:zsolt.koppany@intland.com
Fax: +49-711-722 1835
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Cannot find bean under name dbCategories
Posted by "uma.k" <um...@net-kraft.com>.
Hi,
I get this exception when I try to use html:options with
collection="dbCategories".
This is what I am doing
index.jsp
<html:link page="/articleForm.do">Article</html:link>
my struts-config.xml
<action path="/articleForm" forward="/articles/Template.jsp" />
<action
path="/PreviewArticle"
type="articles.ArticlePreviewAction"
name="articleForm"
scope="request"
validate="false"
input="/articles/Template.jsp">
<forward name="success" path="/articles/Preview.jsp"/>
<forward name="failure" path="/articles/Template.jsp"/>
</action>
Template.jsp
<html:form action="/PreviewArticle.do" focus="keywords"
enctype="multipart/form-data">
<html:select name="articleForm" property="category">
<html:options collection="dbCategories" property="id"
labelProperty="description"/>
</html:select>
...
...
</html:form>
My ArticlePreviewAction.java
dbCategories = dbBean.getCategoriesForArticle(myConnection);
request.setAttribute("dbCategories", dbCategories);
Please let me know where I have gone wrong. As I am unable to figure out the
problem.
Thanks
Uma
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Which setter do I need in the ActionForm for this example?
Posted by Jeff Beal <jb...@webmedx.com>.
I think this goes back to what Richard said a few posts back. The
collection used to populate a select list is distinct from what the
browser sends back. Let's say you have a map that looks something like
this:
{ [001,"Value 1"],[002,"Value 2"],[003,"Value 3"],[004,"Value 4"] }
(I just made that syntax up on the spot. The Map has four String values
with keys 001 to 004.) The <html:select/> with an
<html:optionsCollection/> will generate the following HTML:
<select name='dropDown' multiple='true'>
<option value='001'>Value 1</option>
<option value='002'>Value 2</option>
<option value='003'>Value 3</option>
<option value='004'>Value 4</option>
</select>
If the user selects 'Value 2' and 'Value 4', the browser will send back
the following to the server:
http://www.yourcompany.com/yourapp/youraction.do?dropDown=002&dropDown=004
Note that 'Value 2' and 'Value 4' do not get sent to the server. Only
the keys get sent.
On the server side, the two values for the dropDown parameter are
exposed as a String array ({"002","004"}). Read the documentation for
request.getParameter and request.getParameterValues for more information
on this. What you want in your ActionForm is (I think):
public void setDropDown(String[] selectedKeys)
public String[] getDropDown()
Forget that a Map was used to populate the select list. That's purely a
convenience provided by the <html:select/> and <html:optionsCollection/>
custom tags.
-- Jeff
Zsolt Koppany wrote:
> I think, I have found the reason of the problem but still don't understand
> it. If I use "getDropDownSelection()" instead of "getDropDownSelections()"
> to get the Map back the setter method "setDropDownSelection(String key,
> String[] v)" is not called.
>
> Do I misunderstand something?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Which setter do I need in the ActionForm for this example?
Posted by Zsolt Koppany <zk...@intland.com>.
I think, I have found the reason of the problem but still don't understand
it. If I use "getDropDownSelection()" instead of "getDropDownSelections()"
to get the Map back the setter method "setDropDownSelection(String key,
String[] v)" is not called.
Do I misunderstand something?
I use jdk-1.4.2-06 Win-Xp-sp2, Struts-1.1, tomcat-5.0.27.
// This method musn't be called as "getDropDownSelection".
public Map getDropDownSelections()
{
return dropDownSelection;
}
public String[] getDropDownSelection(String key)
{
return (String[])dropDownSelection.get(key);
}
public void setDropDownSelection(String key, String[] v)
{
log.debug("CALED ----------------");
dropDownSelection.put(key, v);
}
Zsolt
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Jeff Beal
> Sent: Thursday, December 23, 2004 6:47 PM
> To: user@struts.apache.org
> Subject: Re: Which setter do I need in the ActionForm for this example?
>
> With multiple="true", I think that you need a property of type String[]
> in your ActionForm.
>
> -- Jeff
>
> Zsolt Koppany wrote:
> > Richard,
> >
> > Thank you, but did you see that I have set multiple="true" ?
> >
> > Zsolt
> >
> >
> >>-----Original Message-----
> >>From: Richard Yee [mailto:ryee@cruzio.com]
> >>Sent: Thursday, December 23, 2004 4:01 PM
> >>To: Struts Users Mailing List
> >>Subject: Re: Which setter do I need in the ActionForm for this example?
> >>
> >>Zsolt,
> >>The selected item in a html:select input is typically a String property.
> >>It
> >>is separate from the collection that is used to populate a dropdown
> list.
> >>You should have a getter and setter for a string property and use that
> >>property as the value of the "property" attribute of the html:select
> tag.
> >>
> >>-Richard
> >>
> >>At 04:12 AM 12/23/2004, you wrote:
> >>
> >>>Hi,
> >>>
> >>>I have tried several setters in the Form class but none of them are
> >>
> >>called
> >>
> >>>when the form is terminated. How should me setter look like to the
> >>
> >>property
> >>
> >>>"dropDownSelection". The getter method is:
> >>>
> >>>public Map getDropDownSelection()
> >>>{
> >>> return dropDownSelection;
> >>>}
> >>>
> >>>The setter "setDropDownSelection(String key, Object value)" is never
> >>
> >>called.
> >>
> >>>
> >>>Zsolt Koppany Phone: +49-711-722 1874 -- Intland Software GmbH,
> >>>Schulze-Delitzsch-Strasse 16 D-70565 Stuttgart, Germany Phone: +49-711-
> >>
> >>722
> >>
> >>>1873, e-mail:zsolt.koppany@intland.com Fax: +49-711-722 1835
> >>>---------------------------------------------------------------------
> To
> >>>unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
> >>>commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Which setter do I need in the ActionForm for this example?
Posted by Jeff Beal <jb...@webmedx.com>.
With multiple="true", I think that you need a property of type String[]
in your ActionForm.
-- Jeff
Zsolt Koppany wrote:
> Richard,
>
> Thank you, but did you see that I have set multiple="true" ?
>
> Zsolt
>
>
>>-----Original Message-----
>>From: Richard Yee [mailto:ryee@cruzio.com]
>>Sent: Thursday, December 23, 2004 4:01 PM
>>To: Struts Users Mailing List
>>Subject: Re: Which setter do I need in the ActionForm for this example?
>>
>>Zsolt,
>>The selected item in a html:select input is typically a String property.
>>It
>>is separate from the collection that is used to populate a dropdown list.
>>You should have a getter and setter for a string property and use that
>>property as the value of the "property" attribute of the html:select tag.
>>
>>-Richard
>>
>>At 04:12 AM 12/23/2004, you wrote:
>>
>>>Hi,
>>>
>>>I have tried several setters in the Form class but none of them are
>>
>>called
>>
>>>when the form is terminated. How should me setter look like to the
>>
>>property
>>
>>>"dropDownSelection". The getter method is:
>>>
>>>public Map getDropDownSelection()
>>>{
>>> return dropDownSelection;
>>>}
>>>
>>>The setter "setDropDownSelection(String key, Object value)" is never
>>
>>called.
>>
>>>
>>>Zsolt Koppany Phone: +49-711-722 1874 -- Intland Software GmbH,
>>>Schulze-Delitzsch-Strasse 16 D-70565 Stuttgart, Germany Phone: +49-711-
>>
>>722
>>
>>>1873, e-mail:zsolt.koppany@intland.com Fax: +49-711-722 1835
>>>--------------------------------------------------------------------- To
>>>unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
>>>commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Which setter do I need in the ActionForm for this example?
Posted by Zsolt Koppany <zk...@intland.com>.
Richard,
Thank you, but did you see that I have set multiple="true" ?
Zsolt
> -----Original Message-----
> From: Richard Yee [mailto:ryee@cruzio.com]
> Sent: Thursday, December 23, 2004 4:01 PM
> To: Struts Users Mailing List
> Subject: Re: Which setter do I need in the ActionForm for this example?
>
> Zsolt,
> The selected item in a html:select input is typically a String property.
> It
> is separate from the collection that is used to populate a dropdown list.
> You should have a getter and setter for a string property and use that
> property as the value of the "property" attribute of the html:select tag.
>
> -Richard
>
> At 04:12 AM 12/23/2004, you wrote:
> >Hi,
> >
> >I have tried several setters in the Form class but none of them are
> called
> >when the form is terminated. How should me setter look like to the
> property
> >"dropDownSelection". The getter method is:
> >
> >public Map getDropDownSelection()
> >{
> > return dropDownSelection;
> >}
> >
> >The setter "setDropDownSelection(String key, Object value)" is never
> called.
> >
> >
> >Zsolt Koppany Phone: +49-711-722 1874 -- Intland Software GmbH,
> >Schulze-Delitzsch-Strasse 16 D-70565 Stuttgart, Germany Phone: +49-711-
> 722
> >1873, e-mail:zsolt.koppany@intland.com Fax: +49-711-722 1835
> >--------------------------------------------------------------------- To
> >unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
> >commands, e-mail: user-help@struts.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Which setter do I need in the ActionForm for this example?
Posted by Richard Yee <ry...@cruzio.com>.
Zsolt,
The selected item in a html:select input is typically a String property. It
is separate from the collection that is used to populate a dropdown list.
You should have a getter and setter for a string property and use that
property as the value of the "property" attribute of the html:select tag.
-Richard
At 04:12 AM 12/23/2004, you wrote:
>Hi,
>
>I have tried several setters in the Form class but none of them are called
>when the form is terminated. How should me setter look like to the property
>"dropDownSelection". The getter method is:
>
>public Map getDropDownSelection()
>{
> return dropDownSelection;
>}
>
>The setter "setDropDownSelection(String key, Object value)" is never called.
>
>
>Zsolt Koppany Phone: +49-711-722 1874 -- Intland Software GmbH,
>Schulze-Delitzsch-Strasse 16 D-70565 Stuttgart, Germany Phone: +49-711-722
>1873, e-mail:zsolt.koppany@intland.com Fax: +49-711-722 1835
>--------------------------------------------------------------------- To
>unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
>commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: DB Connection Best practice
Posted by "uma.k" <um...@net-kraft.com>.
Thanks Sunny,
I will do that.
Uma
-----Original Message-----
From: Sunny [mailto:suneel@collab.net]
Sent: Friday, December 24, 2004 10:27 AM
To: Struts Users Mailing List
Subject: Re: DB Connection Best practice
Better practice would be delegating to a "handler" (application layer)
class and let it return data in form of some bean and use that in action.
In this way you'll be isolating Controller from Business model.
uma.k wrote:
>Hi,
>I wanted to insert a record into the database or
>update a record in the database or
>get a record from the database.
>
>Where do I make my database connection? Is it in the Action class? Can I
>make a single java class handle all of that for me?
>
>If the above are wrong. Please let me know which is the best practice to do
>this.
>
>Thanks
>Uma
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: DB Connection Best practice
Posted by Sunny <su...@collab.net>.
Better practice would be delegating to a "handler" (application layer)
class and let it return data in form of some bean and use that in action.
In this way you'll be isolating Controller from Business model.
uma.k wrote:
>Hi,
>I wanted to insert a record into the database or
>update a record in the database or
>get a record from the database.
>
>Where do I make my database connection? Is it in the Action class? Can I
>make a single java class handle all of that for me?
>
>If the above are wrong. Please let me know which is the best practice to do
>this.
>
>Thanks
>Uma
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
DB Connection Best practice
Posted by "uma.k" <um...@net-kraft.com>.
Hi,
I wanted to insert a record into the database or
update a record in the database or
get a record from the database.
Where do I make my database connection? Is it in the Action class? Can I
make a single java class handle all of that for me?
If the above are wrong. Please let me know which is the best practice to do
this.
Thanks
Uma
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: NullPointerException
Posted by "uma.k" <um...@net-kraft.com>.
Hi Sunny,
Now I dont get any error also when I my form wont redirect to my original
page when I dont enter any value. Here is my validate()
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(getTheText().equals(""))
{
errors.add(ActionMessages.GLOBAL_MESSAGE, new
ActionMessage("error.text.required"));
}
return errors;
}
And this is my struts-config.xml file
<action
path="/upload-submit"
type="upload.UploadAction"
name="uploadForm"
scope="request"
validate="true"
input="/upload/upload.jsp">
<forward name="failure" path="/upload/upload.jsp" />
<forward name="display" path="/upload/display.jsp" />
</action>
Why do I get a blank page?
Uma
-----Original Message-----
From: Sunny [mailto:suneel@collab.net]
Sent: Friday, December 24, 2004 9:17 AM
To: Struts Users Mailing List
Subject: Re: NullPointerException
Hey Uma,
Kindly attach your logs when you face any exceptions. That'll really
help in debugging.
regards,
Sunny.
uma.k wrote:
>Hi,
>The solution is perfect. I forgot initialization. Now I dont get any error
>but nothing is displayed when the error is actually to be thrown. I get
>blank page and it doesn't go the actual page and show the error. Here is my
>struts-config.xml
>
> <action
> path="/upload-submit"
> type="upload.UploadAction"
> name="uploadForm"
> scope="request"
> validate="true"
> input="/upload/upload.jsp">
> <forward name="failure" path="/upload/upload.jsp" />
> <forward name="display" path="/upload/display.jsp" />
> </action>
>
>Any ideas?
>
>Uma
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: NullPointerException
Posted by Sunny <su...@collab.net>.
Hey Uma,
Kindly attach your logs when you face any exceptions. That'll really
help in debugging.
regards,
Sunny.
uma.k wrote:
>Hi,
>The solution is perfect. I forgot initialization. Now I dont get any error
>but nothing is displayed when the error is actually to be thrown. I get
>blank page and it doesn't go the actual page and show the error. Here is my
>struts-config.xml
>
> <action
> path="/upload-submit"
> type="upload.UploadAction"
> name="uploadForm"
> scope="request"
> validate="true"
> input="/upload/upload.jsp">
> <forward name="failure" path="/upload/upload.jsp" />
> <forward name="display" path="/upload/display.jsp" />
> </action>
>
>Any ideas?
>
>Uma
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE:NullPointerException
Posted by "uma.k" <um...@net-kraft.com>.
Hi,
The solution is perfect. I forgot initialization. Now I dont get any error
but nothing is displayed when the error is actually to be thrown. I get
blank page and it doesn't go the actual page and show the error. Here is my
struts-config.xml
<action
path="/upload-submit"
type="upload.UploadAction"
name="uploadForm"
scope="request"
validate="true"
input="/upload/upload.jsp">
<forward name="failure" path="/upload/upload.jsp" />
<forward name="display" path="/upload/display.jsp" />
</action>
Any ideas?
Uma
-----Original Message-----
From: DGraham@EvergreenInvestments.com
[mailto:DGraham@EvergreenInvestments.com]
Sent: Thursday, December 23, 2004 6:43 PM
To: Struts Users Mailing List
Subject: Re: NullPointerException
IF the exception is actually being thrown here, then I'm guessing that you
haven't instantiated a instance of ActionErrors e.g. ActionErrors errors =
new ActionErrors();
Dennis
"uma.k" <um...@net-kraft.com>
12/23/2004 07:40 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
"'Struts Users Mailing List'" <us...@struts.apache.org>
cc
Subject
NullPointerException
I get NullPointerException in validate() at this line
errors.add(ActionMessages.GLOBAL_MESSAGE, new
ActionMessage("error.text.required"));
This is my ApplicationResources.properties file with this line
error.text.required=Text is required
What could be the reason for NullPointerException?
Uma
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: NullPointerException
Posted by DG...@EvergreenInvestments.com.
IF the exception is actually being thrown here, then I'm guessing that you
haven't instantiated a instance of ActionErrors e.g. ActionErrors errors =
new ActionErrors();
Dennis
"uma.k" <um...@net-kraft.com>
12/23/2004 07:40 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
"'Struts Users Mailing List'" <us...@struts.apache.org>
cc
Subject
NullPointerException
I get NullPointerException in validate() at this line
errors.add(ActionMessages.GLOBAL_MESSAGE, new
ActionMessage("error.text.required"));
This is my ApplicationResources.properties file with this line
error.text.required=Text is required
What could be the reason for NullPointerException?
Uma
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
NullPointerException
Posted by "uma.k" <um...@net-kraft.com>.
I get NullPointerException in validate() at this line
errors.add(ActionMessages.GLOBAL_MESSAGE, new
ActionMessage("error.text.required"));
This is my ApplicationResources.properties file with this line
error.text.required=Text is required
What could be the reason for NullPointerException?
Uma
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org