• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Help needed in resource file

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

In my Struts application the problem is like below

javax.servlet.ServletException: Missing message for key "userRegistration.firstName" in bundle "(default bundle)" for locale en_US
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:682)
org.apache.jsp.userRegistration_jsp._jspService(userRegistration_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:294)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

There id no method like firstName in my Action form java class . i got FirstName Getter method in Action form
The code is like this
<b>UserRegistrationForm .java </b>

package strutsTutorial;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import javax.servlet.http.HttpServletRequest;
public class UserRegistrationForm extends ActionForm {
private String firstName;
private String lastName;
private String userName;
private String password;
private String passwordCheck;
private String email;
private String phone;
private String fax;
private boolean registered;
public String getEmail() {
return email;
}
public void setEmail(String string) {
email = string;
}
public String getFirstname() {
return firstName;
}
public void setFirstname(String string) {
firstName = string;
}
public String getLastname() {
return lastName;
}
public void setLastname(String string) {
lastName = string;
}
public String getUsername() {
return userName;
}
public void setUsername(String string) {
userName = string;
}
public String getPassword() {
return password;
}
public void setPassword(String string) {
password = string;
}
public String getPasswordcheck() {
return passwordCheck;
}
public void setPasswordcheck(String string) {
passwordCheck = string;
}
public String getPhone() {
return phone;
}
public void setPhone(String string) {
phone = string;
}
public String getFax() {
return fax;
}
public void setFax(String string) {
fax = string;
}
public boolean getRegistered() {
return registered;
}
public void setRegistered(boolean string) {
registered = string;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
firstName=null;
lastName=null;
userName=null;
password=null;
passwordCheck=null;
email=null;
phone=null;
fax=null;
registered=false;
}
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (firstName==null|| firstName.trim().equals("")){
errors.add("Firstname",new ActionError("userRegistration.Firstname.problem"));
}
return errors;
}
}

<b>
Properties file</b>

userRegistration.Firstname=First Name
userRegistration.Lastname=Last Name
userRegistration.Username=User Name
userRegistration.Password=PassWord
userRegistration.Email=email
userRegistration.Phone=phone
userRegistration.Fax=fax
userRegistration.Firstname.problem=The first name was blank


i place this resource properties file in web.xml and struts-config.xml. can any one hel me

Thanks in advance
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.servlet.ServletException: Missing message for key "userRegistration.firstName" in bundle "(default bundle)" for locale en_US
Properties file</b>
userRegistration.Firstname=First Name

Hi
You should have an entry for userRegistration.firstName= First Name in your properties file.

Regards,
Roshani
[ October 16, 2006: Message edited by: RoshaniG Gopal ]
 
Ram Adsumalli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi rochani

Thanks for your reply. but my getter method in Action from is Fristname.so i use userRegistration.Firstname as key whats the need for userRegistration.fristname key . there is no such method in my action form.anyway i will use that key.
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raghuram,
The Action Form is not related to the entries in the properties file. The entries in the properties file is done for the i18n support.
so your JSP might have
<bean:message key="userRegistration.FirstName"/>[or anything]This entry should be in the properties file.
But for the Action Form, it will find the getXXX(), setXXX() for the property specified.
<html:text property="firstName"/>
It will search for a setFirstName in the Action Form.
Please map acc, in case things are not clear, post your JSP.

Regards,
Roshani
 
Ram Adsumalli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roshani,

Thanks a lot for helping me in this regard. As per your last reply, i Changed properties file with respect to key in the <bean:message>. when i am running the application it showing no getter method for my property.
In ActionForm my get method is getFirstname and the variable is firstName.
in the jsp page i mention my property as firstName. then it showing the error below

javax.servlet.ServletException: No getter method for property: "firstName" of bean: "strutsTutorial.UserRegistrationForm"
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:682)
org.apache.jsp.userRegistration_jsp._jspService(userRegistration_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:294)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

If i change my property to Firstname as the get method signature then it throwing the error like below

javax.servlet.ServletException: No getter method for property: "Firstname" of bean: "strutsTutorial.UserRegistrationForm"

UserRegistrationForm. java

package strutsTutorial;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import javax.servlet.http.HttpServletRequest;
public class UserRegistrationForm extends ActionForm {
private String firstName;
private String lastName;
private String userName;
private String password;
private String passwordCheck;
private String email;
private String phone;
private String fax;
private boolean registered;
public String getEmail() {
return email;
}
public void setEmail(String string) {
email = string;
}
public String getFirstname() {
return firstName;
}
public void setFirstname(String string) {
firstName = string;
}
public String getLastname() {
return lastName;
}
public void setLastname(String string) {
lastName = string;
}
public String getUsername() {
return userName;
}
public void setUsername(String string) {
userName = string;
}
public String getPassword() {
return password;
}
public void setPassword(String string) {
password = string;
}
public String getPasswordcheck() {
return passwordCheck;
}
public void setPasswordcheck(String string) {
passwordCheck = string;
}
public String getPhone() {
return phone;
}
public void setPhone(String string) {
phone = string;
}
public String getFax() {
return fax;
}
public void setFax(String string) {
fax = string;
}
public boolean getRegistered() {
return registered;
}
public void setRegistered(boolean string) {
registered = string;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
firstName=null;
lastName=null;
userName=null;
password=null;
passwordCheck=null;
email=null;
phone=null;
fax=null;
registered=false;
}
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (firstName==null|| firstName.trim().equals("")){
errors.add("firstName",new ActionError("userRegistration.firstName.problem"));
}
return errors;
}
}

ApplicationResources file :

userRegistration.firstName=First Name
userRegistration.lastName=Last Name
userRegistration.userName=User Name
userRegistration.password=Password
userRegistration.email=Email
userRegistration.phone=Phone
userRegistration.fax=Fax
userRegistration.firstName.problem=The first name was blank


My JSP page is

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h1>User Registration</h1>
<html:errors/>
<table>
<html:form action="userRegistration">
<tr>
<td>
<bean:message key="userRegistration.firstName" />*
</td>
<td>
<html:text property="firstName" />
</td>
</tr>
<td>
<bean:message key="userRegistration.lastName" />*
</td>
<td>
<html:text property="lastName" />
</td>
<tr>
<td>
<bean:message key="userRegistration.userName" />*
</td>
<td>
<html:text property="username" />
</td>
</tr>
<tr>
<td>
<bean:message key="userRegistration.email" />*
</td>
<td>
<html:text property="email" />
</td>
</tr>
<tr>
<td>
<bean:message key="userRegistration.phone" />
</td>
<td>
<html:text property="phone" />
</td>
</tr>
<tr>
<td>
<bean:message key="userRegistration.fax" />
</td>
<td>
<html:text property="fax" />
</td>
</tr>
<tr>
<td>
<bean:message key="userRegistration.password" />*
</td>
<td>
<html assword property="password" />
</td>
</tr>
<tr>
<td>
<bean:message key="userRegistration.password" />*
</td>
<td>
<html assword property="passwordcheck" />
</td>
</tr>
<tr>
<td>
<html:submit />
</td>
<td>
<html:cancel />
</td>
</tr>
</html:form>
</table>
</body>
</html>

May be i am pasting too much code on this page. Sorry for inconvenience .


Thanks in Advance
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raghuram,
You have different names (string variables)in your JSP and your form. That is the reason it cant find the getter.
JSP has:
<html:text property="firstName" />

But your ActionForm.java(UserRegistration.java) has

private String firstName;
the String here is firstName.. so get() and set() shd be correct.
public String getFirstname()
public String getFirstName()
{
return firstName;
}
Same goes for the setter also.

Hope it solves your problem.
Regards,
Roshani
[ October 16, 2006: Message edited by: RoshaniG Gopal ]
 
Ram Adsumalli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Roshani,

Thank you, its working fine . but i got one more prob,Can you help in this regard.In ActionForm i use validation only for Firstname. So if my first name is blank,then it has to show the error the first name is blank, as per i mentioned in the resource file.when i tried to submit the page by leaving the firstname empty, it is showing error like below

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoSuchMethodError: org.apache.struts.action.ActionErrors.add(Ljava/lang/String;Lorg/apache/struts/action/ActionError V
strutsTutorial.UserRegistrationForm.validate(userRegistrationForm.java:86)
org.apache.struts.chain.commands.servlet.ValidateActionForm.validate(ValidateActionForm.java:53)
org.apache.struts.chain.commands.AbstractValidateActionForm.execute(AbstractValidateActionForm.java:100)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you using validation.xml & validate-rule.xml? if so make sure that the signature for required validate method is correct in validate-rule.xml file. There are different vaersions available.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I have same problem as Ram(i.e first errir he posted)
I read whole conversation, but my error is not solved


Help me

index.jsp
<html:form action="UserAction.do">
<table>
<tr>
<td>
<bean:write name="UserForm" property="message"/>
</td>
</tr>
<tr>
<td>
<html:submit property="method"><bean:message key="Test.sum"/></html:submit>

<!--<html:link page="/CustomerAction.do?parameter=view">view</html:link>-->
</td>
</tr>
<tr>
<td>
<html:submit property="method"><bean:message key="UserForm.update"/></html:submit>

<!--<html:link page="/CustomerAction.do?parameter=create">create</html:link>-->
</td>
</tr>
<tr>
<td>
<html:submit property="method"><bean:message key="UserForm.delete"/></html:submit>

<!--<html:link page="/CustomerAction.do?parameter=delete">delete</html:link>-->
</td>
</tr>
</table>
</html:form>

UserForm
public class UserForm extends ActionForm{

private static final long serialVersionUID = 1L;
private String message;

public UserForm(){
super();
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}


ApplicationResource

UserForm.add = Add
UserForm.update = Update
UserForm.delete = Delete


I mentioned in struts-config.xml

Error:
javax.servlet.ServletException: Missing message for key "UserForm.add" in bundle "(default bundle)" for locale en_US

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic