You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Patrick Refondini <pa...@jpnet.ch> on 2002/08/11 13:54:54 UTC

Accessing MessageResources From Runtime Expression

I try to refer to image paths stored in MessageResources from a Runtime 
Expression in order to dynamically define Javascripts.

I look for a mix of bean:message and bean:define tags that would let me do:

<bean:define-message
   id="closeActionActiveBtnMessage"
   key="close.action.active_button"
   toScope="page" />

<bean:define-message
   id="closeActionBtnMessage"
   key="close.action.button"
   toScope="page" />

In order to accomplish:

<nested:image  srcKey="close.action.button"
                property   ="setCloseAction"
                styleClass ="unSelMnuBtn"
                onmouseover='<%="this.src=\'" +
                                 closeActionActiveBtnMessage + "\'"%>'
                onmouseout ='<%="this.src=\'" + closeActionBtnMessage +
                                "\'"%>' />

I might not have understood that an already existing tags solves this !
Or should I create a custom "<bean:define-message>" tag ?


I'll be pleased of any direction you can point me to, thanks
Patrick



Here after a code sample of a working test I have closely based :) on 
the the <bean:message> source code
(org.apache.struts.taglib.bean.MessageTag.doStartTag() Author: Craig R. 
McClanahan, Version: $Revision: 1.4 $ $Date: 2001/02/20 01:48:45 $) :

      <%
	// Get the message
         String closeActionActiveBtnMessage = RequestUtils.message(
		pageContext, Action.MESSAGES_KEY, Action.LOCALE_KEY, 
"close.action.active_button");
	// Check if it was found
	if (closeActionActiveBtnMessage == null) {
	    JspException e = new JspException
		("Error: close.action.active_button message resource not found.");
             RequestUtils.saveException(pageContext, e);
             throw e;
         }

	// Build the Javascript given the message (image path).
         String closeActionActiveBtnScript  = "this.src=\'" + 
closeActionActiveBtnMessage + "\'";

         // Return the script as a bean to the pageContext at the given 
scope
         pageContext.setAttribute("closeActionActiveBtnScript", 
closeActionActiveBtnScript, PageContext.PAGE_SCOPE);

	(... idem for "closeActionBtnScript" ...)
       %>

       <nested:image  srcKey="com.extentis.webapp.adhoc.close.action.button"
                      property="setCloseAction"
                      styleClass="unSelMnuBtn"
                      onmouseover='<%=closeActionActiveBtnScript%>'
                      onmouseout='<%=closeActionBtnScript%>' />


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>