In my Jsp page I have the code like this
<html:select name="county" property="selectedCounty">
<html:option value="Alleghany" />
<html:option value="Ashe" />
<html:option value="Pasquotank" />
<html:option value="Peraquimmons" />
<html:option value="Wake" />
<html:option value="Wayne" /></html:select>
I need to setter and getter methods for this options
Use html:optionsCollection to retrieve the values from the backing bean.
<html:select property="selectedCounty">
<html:option value="" />
<html:optionsCollection property="countiesList" />
</html:select>
Where 'countiesList' is a collection type variable in the backing bean with getters and setters.
SirG
I made the changes to the jsp file ...but this time its throwing the following error.
help me ..
javax.servlet.jsp.JspException: No getter method available for property selectedCounty for bean under name org.apache.struts.taglib.html.BEAN
at org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:327)
at org.apache.struts.taglib.html.SelectTag.doStartTag(SelectTag.java:244)
at jsp_servlet.__contract._jspService(__contract.java:245)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:322)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6718)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
In your form object for the page add a
private List counties;
with a getter and setter.
Then, in your Action class create a Vector full of LabelValueBean objects (you should have them as part of your struts application) and set the Vector into you form.
Then, on you page do
<html:select name="country" property="selectedCounty">
<html:optionsCollection property="counties" />
</html:select>
javax.servlet.jsp.JspException: No getter method available for property selectedCounty for bean under name org.apache.struts.taglib.html.BEAN
That clearly implies that you don't have a form bean property for 'selectedCounty'. Define a variable 'selectedCounty' in your backing bean and generate getters and setters for the same and check it out.
private String selectedCounty;
//Getter and Setter
SirG
Thanks for responding.
Let me show you my code:
In Jsp :<html:select property="selectedCounty">
<html:option value="Alleghany" />
<html:option value="Ashe" />
<html:option value="Pasquotank" />
<html:option value="Peraquimmons" />
<html:option value="Wake" />
<html:option value="Wayne" />
<html:optionsCollection property="countiesList" />
</html:select>
In ActionForm:
public String[] getSelectedCounty() {
return selectedCounty;
}
/**
* @param selectedCounty The selectedCounty to set.
*/
public void setSelectedCounty(String[] selectedCounty) {
this.selectedCounty = selectedCounty;
}
/**
* @return Returns the county.
*/
public List getCountiesList() {
return countiesList;
}
/**
* @param county The county to set.
*/
public void setCountiesList(List countiesList) {
this.countiesList = countiesList;
}
I am new to struts. I dont know how to fix this. I have hardcoded the list in the jsp. and wanted to create a form bean.
I am getting the following exception.....
javax.servlet.jsp.JspException: Failed to obtain specified collection
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:222)
at jsp_servlet.__contract._jspService(__contract.java:361)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:322)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6718)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
private String selectedCounty;
public String getSelectedCounty() {
return selectedCounty;
}
public void setSelectedCounty(String selectedCounty) {
this.selectedCounty = selectedCounty;
}
Just define selectedCounty as a String. You need this variable, basically to fetch the value selected from the dropdown by the user. This will be populated only when the user selects a value and submits it to the action.
SirG
I made the changes ..
I have added
/**
* @return Returns the selectedCounty.
*/
public String getSelectedCounty() {
return selectedCounty;
}
/**
* @param selectedCounty The selectedCounty to set.
*/
public void setSelectedCounty(String selectedCounty) {
this.selectedCounty = selectedCounty;
}
but its throwing an exception
javax.servlet.jsp.JspException: Failed to obtain specified collection
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:222)
<html:select property="selectedCounty">
<html:option value="Alleghany" />
<html:option value="Ashe" />
<html:option value="Pasquotank" />
<html:option value="Peraquimmons" />
<html:option value="Wake" />
<html:option value="Wayne" />
<html:optionsCollection property="countiesList" />
</html:select>
public static Collection getCountiesList(){
ArrayList countiesList = new ArrayList();
Map option = new HashMap();
option.put("label", "Alleghany");
option.put("value", "Alleghany");
countiesList.add(option);
option = new HashMap();
option.put("label", "Ashe");
option.put("value", "Ashe");
countiesList.add(option);
option = new HashMap();
option.put("label", "Pasquotank");
option.put("value", "Pasquotank");
countiesList.add(option);
option = new HashMap();
option.put("label", "Peraquimmons");
option.put("value", "Peraquimmons");
countiesList.add(option);
option = new HashMap();
option.put("label", "Wake");
option.put("value", "Wake");
countiesList.add(option);
option = new HashMap();
option.put("label", "Wayne");
option.put("value", "Wayne");
options.add(option);
return options;
}
Replace your getCountiesList getter with the above code and check if you are still getting the same exception.
Also make the following changes to your jsp:
<html:select property="selectedCounty">
<html:optionsCollection property="countiesList" />
</html:select>
SirG
Code In Action form
/**
* @return Returns the county List.
*/
public static Collection getCountiesList(){
ArrayList countiesList = new ArrayList();
Map option = new HashMap();
option.put("label", "Alleghany");
option.put("value", "Alleghany");
countiesList.add(option);
option = new HashMap();
option.put("label", "Ashe");
option.put("value", "Ashe");
countiesList.add(option);
option = new HashMap();
option.put("label", "Pasquotank");
option.put("value", "Pasquotank");
countiesList.add(option);
option = new HashMap();
option.put("label", "Peraquimmons");
option.put("value", "Peraquimmons");
countiesList.add(option);
option = new HashMap();
option.put("label", "Wake");
option.put("value", "Wake");
countiesList.add(option);
option = new HashMap();
option.put("label", "Wayne");
option.put("value", "Wayne");
countiesList.add(option);
return countiesList;
}
/**
* @param county The county to set.
*/
public void setCountiesList(ArrayList countiesList) {
this.countiesList = countiesList;
}
/**
* @return Returns the selectedCounty.
*/
public String getSelectedCounty() {
return selectedCounty;
}
/**
* @param selectedCounty The selectedCounty to set.
*/
public void setSelectedCounty(String selectedCounty) {
this.selectedCounty = selectedCounty;
}
Code in Jsp :
<html:select property="selectedCounty">
<html:optionsCollection property="countiesList" />
</html:select>
But I am getting the following Exception:
;javax.servlet.jsp.JspException: No getter method for property countiesList of bean org.apache.struts.taglib.html.BEAN
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:219)
at jsp_servlet.__contract._jspService(__contract.java:265)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
--
I tried changing the return type of getCountiesList from Collection to ArrayList.
Nothing worked