I'm not sure it will work, try to make an instance of te project field
instead of setting null value

Maurizio Cucchiara

Il giorno 24/feb/2011 15.18, "alex zaim" <icid...@yahoo.com> ha scritto:
> i have a Organization.java class that has a field named "name" and get and
set methods.
> Then i use a Project.java class that extends Organization.
Organization.java also has an User.java class that also has a "name" field.
I use the Project class as a bean that is populated after a form is being
submitted.  The problem is that ( Project) Organization.name is not being
initialized when (Project) Organization.User.name IS being initialized. Can
anyone help me telling me what i've done wrong? I've been checking my field
and method names for a long tine now and i'm stuck, though everything seems
to be in good shape.
> My classes and various files follow:
> // Organization.java
> public class Organization {
>     private int id;
>     private User[] users;
>     private String name="no name yet";
>     private User president;
>
>     public String toString(){
>         return "ID:"+id+"; Users:<not yet>"+"; Name:"+name+";
President:"+president.getName();
>     }
>     public void setName(String name) {
>         this.name = name;
>     }
>     public String getName() {
>         return name;
>     }
>     public void setPresident(User president) {
>         this.president = president;
>     }
>     public User getPresident() {
>         return president;
>     }
> }
>
> // Project.java
> public class Project extends Organization{
>     public Project(){
>         super();
>     }
> }
>
> // struts.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
>     "http://struts.apache.org/dtds/struts-2.0.dtd";>
>
> <struts>
>     <constant name="struts.devMode" value="true" />
>     <package name="translators" extends="struts-default">
>         <action name="test" class="net.translators.actions.TestAction"
method="execute">
>             <result name="success">/test.jsp</result>
>         </action>
>
>         <action name="createproject"
class="net.translators.actions.CreateProjectAction" method="execute">
>             <result name="success">/tests/message.jsp</result>
>             <result name="input">/tests/createproject.jsp</result>
>         </action>
>         <action name="create-a-project"
class="net.translators.actions.CreateProjectAction" method="dummy">
>             <result name ="success">/tests/createproject.jsp</result>
>         </action>
>     </package>
> </struts>
>
> // test.jsp has this line ("Point of entrance")
> <a href="<s:url action="tests/create-a-project"/>">Create a Project</a>
>
> // createproject.jsp has this form
> <s:form action="createproject">
>     <s:textfield key="project.name"/>
>     <s:textfield key="project.president.name"/>
>     <s:submit label="Submiter"/>
> </s:form>
>
> // the resource file that is named after the Action class:
> project.name=Projects name
> project.users=Multiple Users
> project.president.name=Presidents name
> project.id=DB ID
>
> // The action class
> public class CreateProjectAction extends ActionSupport{
>     private Project project =null;
>     private String message = "NULL";
>     public void setProject(Project pr){
>         this.project = pr;
>     }
>
>     public String execute(){
>
>         if (project !=null ){
>             message = "Execute: "+project.toString();
>         }
>
>         return SUCCESS;
>     }
>
>     @SkipValidation
>     public String dummy(){
>         return SUCCESS;
>     }
>     public void validate(){
>         if(project ==null || project.getName().length()==0){
>             addFieldError( "project.name", "Name is required." );
>         }
>         message = "Validate";
>     }
>
>     public void setMessage(String message) {
>         this.message = message;
>     }
>
>     public String getMessage() {
>         return message;
>     }
> }
>
>
>
>

Reply via email to