?
Solved

Struts bean:write tag

Posted on 2004-10-20
7
Medium Priority
?
324 Views
Last Modified: 2013-12-29
I have this tag: <bean:write name="result"/> in one of my JSPs that is being accessed from 2 or more Action objects. One of those Action objects sets the message like so:

String message = "Successful";
request.setAttribute("result", message);

but the other Action objects dont set that bean (ie I don't need any message if it's coming from them), so when the JSP is being called from any of those Action objects, I get a JSP exception that "result" has never been set.

Is there any way around this problem other than setting a blank "result" message in every other Action that forwards to that JSP? What is the proper way of doing this? I don't want to use scripting in my JSP to check if "result" is null.

Thanks.
0
Comment
Question by:Flavaflav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12363111
you can initialize ur bean variable to a default value so that in case it is not set by any action class it should display the default value
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12363132
sorry abt the above quote

you can wrap ur bean write tag with the <logic:present> so that it will check out whether it is present and then display it if is there.
0
 

Author Comment

by:Flavaflav
ID: 12363903
I tried doing this:

<logic:present><bean:write name="result"></logic:present>

but I get the following runtime exception: "No selector attribute (cookie/header/name/parameter) was specified".
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:kiranhk
ID: 12364039
try this out

<logic:present name="result">
<bean:write name="result"></
</logic:present>


also go thro this

http://struts.apache.org/api/org/apache/struts/taglib/logic/package-summary.html#package_description
0
 

Author Comment

by:Flavaflav
ID: 12364370
Great thanks that worked. While we're on this subject I have another question: Using the bean:write tag, how can I get the property of a property of a bean? For example, I have:

<bean:write name="target" property="dataField">

where dataField is a DataField object belonging to the Target object, but I need to display a certain field from that DataField obj (eg. "description"). Is there a way to do this just using Struts tags, and w/out overriding toString() in DataField to return the description property?
0
 
LVL 8

Accepted Solution

by:
kiranhk earned 400 total points
ID: 12364752
<bean:write name="target" property="dataField.urpropertyname">
0
 

Author Comment

by:Flavaflav
ID: 12364930
Simple enough :>. Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question