Solved

Struts bean:write tag

Posted on 2004-10-20
7
287 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
countX 22 70
countAbc challenge 9 49
JDeveloper 12c for 32 bit 4 34
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 covers a step-by-step guide to install VisualVM launcher in eclipse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now