struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Accessing a Bean from a bean using EL with STRUTS 2 - I really need help
Date Sat, 07 Apr 2007 18:58:16 GMT
mansour77@yahoo.com wrote:
> 
> All I am trying to do is to retrieve an account from A DB and using 
> taglib (data grid) to display the associated invoice with this account. 
> Should this be a two-days task.
> 
> Maybe something wrong with me.
> 
> here's my controller:
> 
> package billing;
> import com.opensymphony.xwork2.ActionSupport;
> public class AccountManager   extends ActionSupport{
> 
>    private Account account ;
>    private AccountBean accountBean ;
>      public String execute()
>    {
>        account = new Account(accountBean);
>        return "SUCCESS" ;
>    }
> 
>    public AccountBean getAccountBean() {
>        return accountBean;
>    }
> 
>    public void setAccountBean(AccountBean accountBean) {
>        this.accountBean = accountBean;
>    }
> }

Maybe this is an incomplete code sample, but you don't appear to be 
initializing accountBean, so getAccountBean() will always return null.

> and here's my jsp
> 
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <%@ taglib prefix="ui" uri="/taglibs-datagrid"%>
> <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
> 
> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c1" %>
> <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
> 
> <%@ page import="billing.*" %>
> <%@ page import="java.util.ArrayList"%>
> <%@page import="java.util.Collection"%>
> 
> <html>
> <head>
> </head>
> <body>
> 
> <div style="background-color:lightblue;"><s:label value="AccId:" />
> <s:property value="accountBean.accountNumber" /> <br>
> <s:label value="First Name:" />
> <s:property    value="accountBean.firstName" /><br>
> <s:label value="Last Name: " />
> <s:property    value="accountBean.lastName" />
> </div>
> <hr>
> 
> <jsp:useBean id="accountBean" type="billing.AccountBean" scope="request"
>        beanName="billing.AccountBean">
> </jsp:useBean>
> 
> <ui:dataGrid items="${accountBean.invoices}" var="i" name="datagrid1">
>              <columns>
>                <column width="100" order="true">
>                  <header value="ID" />
>                  <item   value="${i.id}"/>
>                </column>
>              <columns>
> </ui:dataGrid >
> </body>
> </html>
> 
> 
> 
> Now How can I set a bean called invoices to the value of  the bean 
> "account.invoices" ?

Maybe I don't understand your question; it sounds like you just need to 
set accountBean.invoices in your action's execute() method:

     public String execute()
     {
         accountBean = ... ;
         accountBean.setInvoices(...);
         return SUCCESS;
     }

L.


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


Mime
View raw message