-
1. Re: EL-resolve bundle.getString for an object
danielc.roth Feb 6, 2008 2:55 PM (in response to danielc.roth)2nd try, not using hashguard(replaced by $ below) or equals-sign(repl. by -) (forum bug?)
I have a resource bundle with some properties like:
hello-Hi ${user.firstname}
On an xhtml page this resolves beautifully to 'Hi Daniel'.
Getting the string from the resource bundle 'bundle.getString(
hello
)', will not resolve for the '${user.firstname}', which is not surprising at all.Is there any way I can do something like
User user - getUser();
ELResolver.resolve(bundle.getString(hello
),user,anotherObject)which resolves the el expressions, given some objects, the same way the xhtml is resolved.
Thanks!
-
2. Re: EL-resolve bundle.getString for an object
msystems Feb 6, 2008 4:16 PM (in response to danielc.roth)Have you tried SeamResourceBundle.getBundle().getString(
hello
) ? -
3. Re: EL-resolve bundle.getString for an object
christian.bauer Feb 6, 2008 4:27 PM (in response to danielc.roth)
Daniel Roth wrote on Feb 06, 2008 02:55 PM:
2nd try, not using hashguard(replaced by $ below) or equals-sign(repl. by -) (forum bug?)I need to know why you did this - really, before we go live with the forum.
- Did you see the
Help
button? - Did you use the
Help
and then not understand it? - Did you see the preview of what you typed?
- Did you see the
stop typing and the preview updates automatically
message?
Basically, we really need to know if all of this will be enough of if people need a mandatory preview step, or a bigger red HELP ME WITH FORMATTING button.
Thanks
- Did you see the
-
4. Re: EL-resolve bundle.getString for an object
danielc.roth Feb 6, 2008 4:49 PM (in response to danielc.roth)Christian: I don't really think I looked for an 'help' button, rather I tried writing <code> and actually thought it was kind of strange there wasn't any 'insert-code'-buttons etc.
I saw the preview and the 'invalid markup' to the left but since this forum have an url like alpha....:9999 I just discarded that as a bug... sorry :-) Maybe some quick hints to the right of the textarea? 'Markup help' instead of 'Help'?
Kenneth: the 'bundle' object mentioned above is a SeamResourceBundle injected via
@In(value = "org.jboss.seam.core.resourceBundle") private SeamResourceBundle bundle;
-
5. Re: EL-resolve bundle.getString for an object
msystems Feb 6, 2008 6:30 PM (in response to danielc.roth)Okay... I can tell you it works for me - i.e. resolves the EL expressions.
-
6. Re: EL-resolve bundle.getString for an object
danielc.roth Feb 8, 2008 9:48 AM (in response to danielc.roth)Could you please elaborate on how you achieve this. It the target object Outjected? I have something like this:
messages.properties
hello=hi #{user.username}
SomeAction.java
@Out User user; @In(value = "org.jboss.seam.core.resourceBundle") private SeamResourceBundle bundle; private String email; public void sendForgotMyEmail() { user = someDao.getUserByEmail(email); String message = bundle.getString(hello)', }
I omitted get/set email/user. So the problem, just guessing, is that the user is not outjected until the end of the request and cannot be resolved for immediately after being fetched.
That's why I'd like to sort of force the bundle to use some specific objects, or rewrite the flow of this particular page.
-
7. Re: EL-resolve bundle.getString for an object
msystems Feb 8, 2008 11:45 AM (in response to danielc.roth)
Daniel Roth wrote on Feb 08, 2008 09:48 AM:
Could you please elaborate on how you achieve this. It the target object Outjected? I have something like this:
messages.propertieshello=hi #{user.username}
SomeAction.java@Out User user; @In(value = "org.jboss.seam.core.resourceBundle") private SeamResourceBundle bundle; private String email; public void sendForgotMyEmail() { user = someDao.getUserByEmail(email); String message = bundle.getString(hello)', }
I omitted get/set email/user. So the problem, just guessing, is that the user is not outjected until the end of the request and cannot be resolved for immediately after being fetched.
That's why I'd like to sort of force the bundle to use some specific objects, or rewrite the flow of this particular page.That's correctly - the object doesn't exist in the Context, because it's first outjected when sendForgotMyEmail() finish.
You must force an outjection:
public void sendForgotMyEmail() { user = someDao.getUserByEmail(email); Contexts.getConversationContext().set("user", user); String message = bundle.getString(hello)', }
BTW: getConversationContext() -> you can also use getEventContext(), getSessionContext() etc.
-
8. Re: EL-resolve bundle.getString for an object
danielc.roth Feb 8, 2008 12:00 PM (in response to danielc.roth)That's what I needed!
Thanks, Mange tak!
-
9. Re: EL-resolve bundle.getString for an object
danielc.roth Feb 18, 2008 3:32 PM (in response to danielc.roth)So now I'd really like to do this without Outjection, exactly the way it's done in the documentation for FacesMessages and Log:
@Logger private Log log; public void doThat() { String fname = "Daniel"; String lname = "Roth"; log.debug("Hello World, my name is #0 #1", fname, lname); FacesMessages.instance().add("Hello World, my name is #0 #1.", fname, lname); }
but instead of creating a log entry / faces message, get it back as a string
String resolved = someMethod("Hello World, my name is #0 #1.", fname, lname);
-
10. Re: EL-resolve bundle.getString for an object
gavin.king Feb 18, 2008 4:00 PM (in response to danielc.roth)You seem to be making this amazingly more complex than it should be. I don't precisely understand what you are trying to do, but I imagine something like:
@In("#{messages.hello}") String helloMessage;
would work.
Or at worst:
@In ResourceBundle resourceBundle; @In Interpolator interpolator; ...
-
11. Re: EL-resolve bundle.getString for an object
danielc.roth Feb 18, 2008 4:06 PM (in response to danielc.roth)Ah, the interpolator does the trick, thanks!
The example above is a dummy one. The actual system is a process system where you can do (just about) anything you can do with jBPM.
But in this system, any user can add/modify/etc flows and what should happen in any task etc. Often a mail (defined by an administrator) is sent with text containing info about the particular task. Thats where 'Hi #manager, ... your #task.info is ready...'