You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by alex zaim <ic...@yahoo.com> on 2011/02/24 15:17:36 UTC

a field is not being initialized in my struts app

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;
    }
}



      

Re: Forum Advice

Posted by findbestopensource <fi...@gmail.com>.
Here are few open source forum software.
http://www.findbestopensource.com/tagged/forum-software

Also,  take a look at these products, If you want to build forum similar to
stackoverflow. (These are not Java products)
http://www.findbestopensource.com/tagged/stackoverflow-like

Regards
Aditya
www.findbestopensource.com



On Fri, Feb 25, 2011 at 9:17 AM, Jerson John <je...@cprvision.com> wrote:

> Hi all,
>    Thanks for all of your comments.Really appreciate....now I got some idea
> to start this....
>
> Many Thanks and Regards,
>
> Jerson
>
> Many Thanks and Regards,
>
> Jerson
>
>
>  -----Original Message-----
> From: Wendy Smoak [mailto:wsmoak@gmail.com]
> Sent: Friday, February 25, 2011 11:07 AM
> To: Struts Users Mailing List
> Subject: Re: Forum Advice
>
> On Thu, Feb 24, 2011 at 9:57 PM, Jerson John <je...@cprvision.com> wrote:
> >    How can i do forum in Struts 2...Is it has to custom build or is there
> > any api or opensource application or thirdpart thing...Beacuse now I am
> > heading towards building the forum for my application....Please help me
>
> I can't imagine anyone needing to write forum software from scratch at
> this point.  There are plenty of options out there -- I would
> evaluate several and see what fits your needs.
>
> --
> Wendy
>
> ---------------------------------------------------------------------
> 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: Forum Advice

Posted by Jerson John <je...@cprvision.com>.
Hi all,
    Thanks for all of your comments.Really appreciate....now I got some idea
to start this.... 

Many Thanks and Regards,

Jerson

Many Thanks and Regards,

Jerson


-----Original Message-----
From: Wendy Smoak [mailto:wsmoak@gmail.com] 
Sent: Friday, February 25, 2011 11:07 AM
To: Struts Users Mailing List
Subject: Re: Forum Advice

On Thu, Feb 24, 2011 at 9:57 PM, Jerson John <je...@cprvision.com> wrote:
>    How can i do forum in Struts 2...Is it has to custom build or is there
> any api or opensource application or thirdpart thing...Beacuse now I am
> heading towards building the forum for my application....Please help me

I can't imagine anyone needing to write forum software from scratch at
this point.  There are plenty of options out there -- I would
evaluate several and see what fits your needs.

-- 
Wendy

---------------------------------------------------------------------
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: Forum Advice

Posted by Wendy Smoak <ws...@gmail.com>.
On Thu, Feb 24, 2011 at 9:57 PM, Jerson John <je...@cprvision.com> wrote:
>    How can i do forum in Struts 2...Is it has to custom build or is there
> any api or opensource application or thirdpart thing...Beacuse now I am
> heading towards building the forum for my application....Please help me

I can't imagine anyone needing to write forum software from scratch at
this point.  There are plenty of options out there -- I would
evaluate several and see what fits your needs.

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Forum Advice

Posted by Brian Thompson <el...@gmail.com>.
You'll probably have to build it from scratch.  This Stackoverflow post [1]
might be of some help, but it's a bit more general than what you're looking
for (focused on Java rather than Struts-based forums).

-Brian

[1] -
http://stackoverflow.com/questions/235729/whats-the-best-java-based-forum-software



On Thu, Feb 24, 2011 at 8:57 PM, Jerson John <je...@cprvision.com> wrote:

> Hi,
>    How can i do forum in Struts 2...Is it has to custom build or is there
> any api or opensource application or thirdpart thing...Beacuse now I am
> heading towards building the forum for my application....Please help me
>
> Many Thanks and Regards,
>
> Jerson
>
>

Forum Advice

Posted by Jerson John <je...@cprvision.com>.
Hi,
    How can i do forum in Struts 2...Is it has to custom build or is there
any api or opensource application or thirdpart thing...Beacuse now I am
heading towards building the forum for my application....Please help me

Many Thanks and Regards,

Jerson 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: a field is not being initialized in my struts app

Posted by alex zaim <ic...@yahoo.com>.
I'm not sure too. :)
I've just discovered that the absence of getProject() was the cause of the problem. I still can't understand why it could populate project.user.name without it, but it couldn't poppulate project.name. Or why would it need it ANYWAY? anyway... i'm glad it's solved and i can continue with my project. Perhaps this mail can serve the developers as a bug description, instead. :)

Lesson to learn: Never make assumptions and act according to them, but, instead, research or do everything for "just in case". :) Though the later is not recommended.

--- On Thu, 2/24/11, Maurizio Cucchiara <ma...@gmail.com> wrote:

From: Maurizio Cucchiara <ma...@gmail.com>
Subject: Re: a field is not being initialized in my struts app
To: "Struts Users Mailing List" <us...@struts.apache.org>
Date: Thursday, February 24, 2011, 2:20 PM

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" <ic...@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;
>     }
> }
>
>
>
>



      

Re: a field is not being initialized in my struts app

Posted by Maurizio Cucchiara <ma...@gmail.com>.
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" <ic...@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;
>     }
> }
>
>
>
>