Passing Objects as Parameters

Is it possible to send an object as a paramater from one jsp page to another?

I would like to pass an object from a view page to a details page so that the details page can use the object to display all of its properties. I would accept as a solution passing each of the properties as their own parameters since I haven't yet figured out how to do this. I imagine though that if this is possible it would be possible to pass an object as well.

I've been using this page as a reference:

http://balusc.xs4all.nl/srv/dev-jep-com.html

It seems to be the most helpful page I've found on the internet so far for doing this, and is sadly not very well placed in any google searches I did.

I was going to follow through passing parameters the first way it suggested, but I notice that it uses non standard libraries. Are the first two ways possible to do under the JSF API?

I went on to using the managed properties tags in faces-config, but still can't get it to work.

faces-config.xml

<managed-bean>

<managed-bean-name>ProjectsManager</managed-bean-name>

<managed-bean-class>beans.ProjectsManager</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

<managed-property>

<property-name>projObj</property-name>

<value>#{ProjectsManager.projObj}</value>

</managed-property>

</managed-bean>

ProjectsManager.java: This file has the relevant object (projObj) and mutators for the object

Project.java:Project object encapsulating class

view page, projectAll: array with individual Project objects

<h:dataTable id="projectsTable" value="#{ProjectsManager.projectAll}" var="item">

<h:column>

<f:facet name="header">

<h:outputText value="Name"/>

</f:facet>

<h:outputLink value="project_edit.jsp">

<f:param name="projObj" value="#{item}"/>

<h:outputText value="#{item.name}"></h:outputText>

</h:outputLink>

</h:column>

I'm hoping the edit page can access the following like so, only one property shown

Name: <h:outputText id="name" value="#{ProjectsManager.projObj.name}"/>

I tried it by passing individual properties like I said. This required that I set the class encapsulating the project objects as a managed bean, and having each of its properties set as managed properties.

If you know of an entirely different approach I'm open to anything that solves the problem of passing a parameter from one jsp to another. There seems to be many ways to achieve the same thing, but I'm finding parameter passing in JSF to be a big headache.

Any help or suggestions would be greatly appreciated

[3203 byte] By [mon.goosea] at [2007-11-27 7:49:55]
# 1

The dataTable component knows which row was selected (although I think you will need to change your outputLink to a commandLink tag). What you need is a backing bean with a UIData property which you capture using the binding attribute on the dataTable tag. Then use the UIData.getRowData() to get the bean associated with the selected row of the table. Then you can put the bean in the request or session scope or wherever is appropriate and then your next JSP can access it.

See BalusC's page on dataTables: http://balusc.xs4all.nl/srv/dev-jep-dat.html

RaymondDeCampoa at 2007-7-12 19:30:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for the help. BalusC's page really helped me out, I'll have to refer to his site whenever I need help.

His is one of the only sites showing in-depth the workings of JSF that I've seen on the internet. I wish I knew of its existance from the beginning of my JSF march.

thanks again

mon.goosea at 2007-7-12 19:30:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...