Link to home
Start Free TrialLog in
Avatar of Flavaflav
Flavaflav

asked on

Struts bean:write tag

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.
Avatar of kiranhk
kiranhk

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
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.
Avatar of Flavaflav

ASKER

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".
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
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?
ASKER CERTIFIED SOLUTION
Avatar of kiranhk
kiranhk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Simple enough :>. Thanks.