You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nitin Ahuja <ah...@gmail.com> on 2007/03/14 13:30:13 UTC

ResourceBundle in Javascript?

Hi,

Does anyone know how can I acces Message ResourceBundle key/values in
Javascript?



Thanks,
-Nitin

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Re: Html:Cancel and html:submit works only on new page

Posted by Am...@Dell.com.
Hi there,

Thanks for looking,
This is the page which doesnt execute if I goto it from a link.
It works if opened directly. (Apologize for the long pieces of code)

ChooseJournalType.jsp

<%@ page language="java" %>
<%@ include file="../pages/Includes/Validator.jsp" %> <!-- this
validates the user on each request //-->
<%
String tooltitle = application.getInitParameter("tooltitle"); <!-- this
is defined in web.xml and prints ok //-->
%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<jsp:useBean id="jvcoll" scope="request"
class="fpa.collections.JVTypes"> 
 <jsp:setProperty name="jvcoll" property = "con"
value="<%=cms.getCon()%>"/> 
 <jsp:setProperty name="jvcoll" property = "jvTypeTable"
value="<%=application.getInitParameter("jvtypes")%>"/>
</jsp:useBean>
<%
jvcoll.generateJVList(); <!-- this is to generate the collection for the
selectbox //-->
pageContext.setAttribute("myJvTypes", jvcoll.getJvType());
%>
<html:html>
 <head>
  <html:base />
  <title><%=tooltitle%></title>
   <link rel="stylesheet" type="text/css"
href="../pages/Includes/mystyle.css">
 </head>
<body>
<table width="750" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td colspan="2">
  <%@ include file="../pages/Includes/TopBar.jsp" %> <!-- this is a
banner - which contains the member login/welcome etc.. //-->
   </td>
  </tr>
  <tr>
    <td width="200" valign="top">
  <%@ include file="../pages/Includes/Navigation.jsp" %>  <!-- this is
the navigation bar which has all the links //-->
   </td>
    <td width="80%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>
    <html:errors/>
   </td>
        </tr>
        <tr>
          <td>
     <html:form action="/choosejvaction.do">
    <table width="100%" border="1" cellpadding="2" cellspacing="2"
bordercolor="#BBBBFF">
     <tr bgcolor="#BBBBFF">
      <td colspan="2" align="center"
class="forTexts"><strong><bean:message
key="prompt.choosejvpage.heading"/></strong></td>
     </tr>
     <tr class="forTexts">
      <td width="50%">&nbsp;<b><bean:message
key="prompt.choosejvpage.jvtype"/></b></td>
      <td width="50%">&nbsp;
       <html:select property="jvType" style="forForms" size="1">
        <html:options collection="myJvTypes" property="value"
labelProperty="label" /> <!--  this gets populated from the collection
initiated at the start of this page - no problem //-->
       </html:select>
       </td>
     </tr>
     <tr class="forTexts">
      <td align="center" colspan="2"> 
       <html:cancel styleClass="forButton"><bean:message
key="button.cancel"/></html:cancel>&nbsp;
       <html:submit styleClass="forButton"><bean:message
key="button.choosejvpage.gotonext"/></html:submit></td>
     </tr>
    </table>
   </html:form>
   </td>
        </tr>
      </table>
 </td>
  </tr>
</table>
</body>
</html:html>

My struts-config.xml contains the below code.

 <global-forwards>
        <forward name="choosejv" path="/ChooseJV.do" />
 </global-forwards>

<action-mappings>
  <action path="/choosejvaction" type = "fpa.jv.ChooseJVTypeAction"
name="ChooseJVTypeForm" input = "/index.jsp" cancellable = "true">
   <forward name="success" path="/results.jsp" />
   <forward name="cancelled" path="/cancelled.jsp" />
  </action>
  <action path="/ChooseJV" forward="/forms/ChooseJournalType.jsp"  />
</action-mappings> 

I have 2 classes - 1 is ChooseJVAction.java - which contains an execute
method, and println statements inside the isCancelled method - which
doesn't go through, and also println to getJvType() which returns null..
1 is ChooseJVForm which has a standard getter and setter for String
"jvType".
All in all, the page shows a blank page when submitted, no errors etc


Thanks in advance.

Regards,
Amit
-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: Thursday, March 15, 2007 12:08 PM
To: user@struts.apache.org
Subject: Re: Html:Cancel and html:submit works only on new page

Amit_Wadhwa@Dell.com wrote:
> Hi,
> 
> I have a navigation page which takes me to pageA.jsp throw an 
> <html:link> PageA.jsp has a textbox, a submit button and a cancel 
> button.
> If I navigate through the index.jsp navigation menu to goto PageA.jsp,

> the cancel and submit requests don't work - they both return a blank 
> page - no cancel is captured etc.
> 
> However, when I goto the PageA.jsp directly in a new browser window, 
> both buttons work ok - capturing data in the textbox, capturing the 
> cancel event.
> 
> Anyone has any pointers... ?

Not without seeing what you're doing. Please post your relevant JSP and
action code, and configuration snippets. I don't know what you mean by
'no cancel is captured' or 'capturing data in the textbox'; can you
explain more what behaviour you're seeing and how it differs from what
you're expecting?

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Html:Cancel and html:submit works only on new page

Posted by Laurie Harper <la...@holoweb.net>.
Amit_Wadhwa@Dell.com wrote:
> Hi,
> 
> I have a navigation page which takes me to pageA.jsp throw an
> <html:link>
> PageA.jsp has a textbox, a submit button and a cancel button.
> If I navigate through the index.jsp navigation menu to goto PageA.jsp,
> the cancel and submit requests don't work - they both return a blank
> page - no cancel is captured etc.
> 
> However, when I goto the PageA.jsp directly in a new browser window,
> both buttons work ok - capturing data in the textbox, capturing the
> cancel event.
> 
> Anyone has any pointers... ?

Not without seeing what you're doing. Please post your relevant JSP and 
action code, and configuration snippets. I don't know what you mean by 
'no cancel is captured' or 'capturing data in the textbox'; can you 
explain more what behaviour you're seeing and how it differs from what 
you're expecting?

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Html:Cancel and html:submit works only on new page

Posted by Am...@Dell.com.
Hi,

I have a navigation page which takes me to pageA.jsp throw an
<html:link>
PageA.jsp has a textbox, a submit button and a cancel button.
If I navigate through the index.jsp navigation menu to goto PageA.jsp,
the cancel and submit requests don't work - they both return a blank
page - no cancel is captured etc.

However, when I goto the PageA.jsp directly in a new browser window,
both buttons work ok - capturing data in the textbox, capturing the
cancel event.

Anyone has any pointers... ?

Thanks,
Amit

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ResourceBundle in Javascript?

Posted by Musachy Barroso <mu...@gmail.com>.
I think you are confusing client side and server side code.

musachy

On 3/14/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Nitin Ahuja <ah...@gmail.com> wrote:
> > Does anyone know how can I acces Message
> > ResourceBundle key/values in Javascript?
>
> ?!
>
> You'd have to pass in something that [had] rendered a
> JavaScript representation of the bundle.
>
> I haven't given it any thought, but you *might* be
> able to use DWR to do this in a relatively transparent
> way.
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

Re: ResourceBundle in Javascript?

Posted by Dave Newton <ne...@yahoo.com>.
--- Musachy Barroso wrote:
> <script>
>    var myMessage = '<bean:message key="form.select"
> />';
> 
>    function sayit() {
>       alert(myMessage);
>    }
> </script>

Or that ;)

d.



 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ResourceBundle in Javascript?

Posted by Musachy Barroso <mu...@gmail.com>.
<script>
   var myMessage = '<bean:message key="form.select" />';

   function sayit() {
      alert(myMessage);
   }
</script>

On 3/14/07, Nitin Ahuja <ah...@gmail.com> wrote:
>
> Hi Dave,
>
> What is DWR ?
>
> I found a simple wayout, but there is dependency i.e I have to assign
> the the value of message resource key to an html object in jsp. Here
> is what i did..
>
> in jsp
>
> <html:button  onclick="javascript:display(this);"  property="xyz"
> ><bean:message key="form.select" /></html:button>
>
> and in java script
>
> function display(button)
> {
>     alert(button.value);
> }
>
>
> this will display the value of key "form.select"
>
> thanks,
> -Nitin
>
> On 3/14/07, Dave Newton <ne...@yahoo.com> wrote:
> > --- Nitin Ahuja <ah...@gmail.com> wrote:
> > > Does anyone know how can I acces Message
> > > ResourceBundle key/values in Javascript?
> >
> > ?!
> >
> > You'd have to pass in something that [had] rendered a
> > JavaScript representation of the bundle.
> >
> > I haven't given it any thought, but you *might* be
> > able to use DWR to do this in a relatively transparent
> > way.
> >
> > d.
> >
> >
> >
> >
> >
> ____________________________________________________________________________________
> > Never miss an email again!
> > Yahoo! Toolbar alerts you the instant new Mail arrives.
> > http://tools.search.yahoo.com/toolbar/features/mail/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> ...........
> "Yesterday I dared to struggle, today I dare to win."
> --- Bernadette Devlin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

Re: ResourceBundle in Javascript?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nitin,

Dave Newton wrote:
> Message bundles are server-side. You want to access it on the client.

[snip]

> If you just need to access a single message out of a bundle, maybe 
> this is okay, although I'd probably just put the message into scope 
> via an Action then build your JavaScript using JSTL, which might be 
> enough for whatever it is you're trying to do.

This is what I do (albeit without JSTL) when I need to use a localized
string in javascript. It's also what velocity-tools does in order to
render client-side validation error messages.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF9/yr9CaO5/Lv0PARAo43AKCSt6AGuumgaFCqdGeNtkaN0KsYZACfR3yA
XeNvNT3i3MPasVFgbqLwuaI=
=rWgL
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ResourceBundle in Javascript?

Posted by Dave Newton <ne...@yahoo.com>.
--- Nitin Ahuja <ah...@gmail.com> wrote:
> What is DWR ?

http://getahead.org/dwr

> I have to assign the the value of message resource 
> key to an html object in jsp.

Message bundles are server-side. You want to access it
on the client.

So you need to build a representation of the message
bundle in JavaScript, which is what you did, in a
roundabout way. 

If you just need to access a single message out of a
bundle, maybe this is okay, although I'd probably just
put the message into scope via an Action then build
your JavaScript using JSTL, which might be enough for
whatever it is you're trying to do.

But without knowing what you're trying to accomplish,
it's hard to say.

d.



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ResourceBundle in Javascript?

Posted by Nitin Ahuja <ah...@gmail.com>.
Hi Dave,

What is DWR ?

I found a simple wayout, but there is dependency i.e I have to assign
the the value of message resource key to an html object in jsp. Here
is what i did..

in jsp

<html:button  onclick="javascript:display(this);"  property="xyz"
><bean:message key="form.select" /></html:button>

and in java script

function display(button)
{
    alert(button.value);
}


this will display the value of key "form.select"

thanks,
-Nitin

On 3/14/07, Dave Newton <ne...@yahoo.com> wrote:
> --- Nitin Ahuja <ah...@gmail.com> wrote:
> > Does anyone know how can I acces Message
> > ResourceBundle key/values in Javascript?
>
> ?!
>
> You'd have to pass in something that [had] rendered a
> JavaScript representation of the bundle.
>
> I haven't given it any thought, but you *might* be
> able to use DWR to do this in a relatively transparent
> way.
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
...........
"Yesterday I dared to struggle, today I dare to win."
--- Bernadette Devlin

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ResourceBundle in Javascript?

Posted by Dave Newton <ne...@yahoo.com>.
--- Nitin Ahuja <ah...@gmail.com> wrote:
> Does anyone know how can I acces Message
> ResourceBundle key/values in Javascript?

?!

You'd have to pass in something that [had] rendered a
JavaScript representation of the bundle.

I haven't given it any thought, but you *might* be
able to use DWR to do this in a relatively transparent
way.

d.



 
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org