You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Frasso, Anthony" <AF...@emptoris.com> on 2005/07/05 23:34:11 UTC

Newbie Help

Hello, and thanks in advance for your help.

I am a newbie with respect to struts, and for that matter web development in general.  I am attempting to design a simple jsp page (using the struts framework) to print a table of values that are read from a bean.  For now, I'll stick to trying to generate the table, and worry about any additional response from the user later.

The following is code from my jsp, surrounded only by the opening <HTML> and <BODY> tags:

-- Start JSP Code

<%
    ProjectsBean projectsBean = new ProjectsBean();
    projectsBean.populate();
%>

<TABLE>
  <TR>
    <TH>Project</TH>
    <TH>Customer</TH>
    <TH>Software Version</TH>
  </TR>
  <logic:iterate id="project" name="projectsBean" property="projects">
  <TR>
    <TD><bean:write name="project" property="projectName" /></TD>
    <TD><bean:write name="project" property="customerName" /></TD>
    <TD><bean:write name="project" property="softwareVersionName" /></TD>
  </TR>
  </logic:iterate>
</TABLE>

-- End JSP Code

The ProjectsBean object contains a Set object that is populated from a database with the populate() method.  The Set object is populated with Project objects, each containing a projectId, projectName, customerName, and softwareVersionName.  I'd simply like to print out this information.  I'd like to use as much of the struts tag libraries as possible, without resorting to inline java code.  The code above does not work as I would expect it to.  Any tips on where I am going wrong?

Regards,
Anthony Frasso

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


Re: Newbie Help

Posted by Andrew Thorell <dr...@gmail.com>.
Anthony,

I'm still a newbie to struts myself, so take this email with a gain of
salt (or 2). I put in a suggestion down below that may make your life
easier if you have a lot of reports to deliver (or similiar items on
what you are displaying).

> -- Start JSP Code
> 
> <%
>     ProjectsBean projectsBean = new ProjectsBean();
>     projectsBean.populate();
> %>

My personal opinion is that using this code negates the functionality
of Struts (but I haven't seen any other part of your app or pretend to
be anything but a newbie to struts still). My guess is that this is
your problem, you might need to put inside the <% %> tags a
request.getSession().setAttribute(projectsBean, projectsBean); or
something to that effect. I could be wrong on this...

See below for a solution that is *possibly* more adaptable.

Suggestion:

 Anyhow, when I make reports for people to look at I give them 1 page
with a drop down box with all the report names on it. Have an 
Actionform collect the report name and any other information the
Struts Action then creates the object and puts it in the session and
then below the submit button I have

<logic:present name="reportInfo">
  <logic:iterate ..>
      Table Code goes here.
  </logic:iterate>
</logic:present>


This allows me to maintain a minimal set of code to display any and
all reports that the company ever wants. Add an item to the drop down
box, they hit the submit button, the action grabs the data they want
and I throw it into the session and redisplay the same page.

In some cases I have multiple sets of logic tags for  each report as
there may be a wide variation of fields which need to be displayed.
You could also use Tiles and design a jsp page for each individual
report and inside the logic:present tags just put <tiles:insert ..> as
well.

I'm sure there's a number of ways to do it. 

HtH

Andrew

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


Re: Newbie Help

Posted by Laurie Harper <la...@holoweb.net>.
> Frasso, Anthony wrote the following on 7/5/2005 5:34 PM:
> <%
>      ProjectsBean projectsBean = new ProjectsBean();
>      projectsBean.populate();
>      pageContext.setAttribute("pojectsBean", projectsBean);
> %>

Any scope should work. Also make sure the Project object includes the 
appropriate (JavaBeans compliant) getter methods for the properties you 
want to displey.

L.
-- 
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/~laurie/


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


Re: Newbie Help

Posted by Rick Reumann <st...@reumann.net>.
Frasso, Anthony wrote the following on 7/5/2005 5:34 PM:
> Hello, and thanks in advance for your help.
> 
> I am a newbie with respect to struts, and for that matter web development in general.  I am attempting to design a simple jsp page (using the struts framework) to print a table of values that are read from a bean.  For now, I'll stick to trying to generate the table, and worry about any additional response from the user later.
> 
> The following is code from my jsp, surrounded only by the opening <HTML> and <BODY> tags:
> 
> -- Start JSP Code
> 
> <%
>     ProjectsBean projectsBean = new ProjectsBean();
>     projectsBean.populate();
> %>

Typically you won't want to do any logic like the above in scriplets. In 
other words it's better to do the above in a Servlet (ie Strut's Action) 
and put your 'projects' list in scope there....

ProjectsBean projectsBean = new ProjectsBean();
projectsBean.populate();
request.setAttribute("projects", projects);

However, your code will probably work if you put your projectsBean in 
pageContext...

<%
      ProjectsBean projectsBean = new ProjectsBean();
      projectsBean.populate();
      pageContext.setAttribute("pojectsBean", projectsBean);
%>


-- 
Rick

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