Solved

Struts bean:write tag

Posted on 2004-10-20
7
292 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 100 total points
ID: 12364752
<bean:write name="target" property="dataField.urpropertyname">
0
 

Author Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 101
servlet example issue 6 40
web application structure 18 77
pagenation logic how it is working in my code 1 30
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

810 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