Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean:message key="" problem

 
Raghava Chary
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to find out,In <bean:message key=" "/> ,Key is present or not

....
My problem is,

if message is present, i have to display that one
other wise default one

can any body suggest me

 
Bharat Kasodariya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<logic:present name="message">

<bean:write name="message" />

</logic:present>
 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<logic:present name="message">

<bean:write name="message" />

</logic:present>

@Bharat Kasodariya
Could you please explain what exactly the above code prints.
 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
 
Vidya Gupta
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The logic:present tag checks whether it contains any message or not.. And then if it contains the message then the bean:write will display the message..
 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<logic:present name="message">

<bean:write name="message" />

</logic:present>

@Vidya

As per my knowledge the 'name' attribute of the <logic:present> tag is the name of any bean in a particular scope.
So, according to the code 'message' is a bean which is stored in some scope.
Is the 'message' bean the message resource bundle bean.
If so then how can we check a particular message is present or not.
Please explain.
 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still waiting for reply from Bharat Kasodariya and Vidya Gupta
 
Vidya Gupta
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Sorry i was little bit busy and unable to visit the site..



As per my knowledge, here in logic:present tag the attribute "name" defines a scripting variable to be used as the variable being tested for existence.
Here we are testing that particular variable is present in the scope or not...? And then if it is present in a scope it will enter into the body of the tag and then bean:write attribute displays the values of the properties in the form.
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandy,
Have you looked into this messagesPresent tag provided by struts? I feel this is what you are looking for. Google for couple of examples as well.

 
Raghava Chary
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is not working
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chary,
Did you set the "message" attribute to true?
What have you tried?

 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shankar and Vidya for your reply.

I knew about <logic:messages> tag. But the thing which was bothering me was the post by Bharat Kasodariya

He has used something called message. That was really a new thing for me to learn.
Also Vidya wanted to explain which was not exactly clear to me.
I just wanted to know about the above code.

@Vidya

As per my knowledge, here in logic:present tag the attribute "name" defines a scripting variable to be used as the variable being tested for existence.
Here we are testing that particular variable is present in the scope or not...? And then if it is present in a scope it will enter into the body of the tag and then bean:write attribute displays the values of the properties in the form.

I understood what you want to mean but what Raghava Chary asked was that he wanted to check a value is present or not from the message ResourceBundle. Where is the Message here. Is that 'anyname'?
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned here, Logic present tag would not look for resource bundle. So the above two solutions should not work.

 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I knew it was wrong but I was confused when it was supported by a second user.
Anyways tell me one thing

In the above code is 'myproperties.configured.resources.key' a key in the Resource Bundle?
Because I don't think so.
It has to be initialized in the Action class' execute() method by the following way:

where 'error.name.required' is defined in Resource Bundle.

Correct me if I am wrong as the guy who has posted this question is being misguided by wrong answers.

Regards,
Sandy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic