Maintain Separate Files For Different Types Of Messages
Sep 19, 2014
I am attempting to maintain separate files for different types of "messages" (user messages, field labels/buttons, data values). In this attempt I am trying to get the description of different data values. For example, a UserStatus "A" might be displayed as Active or Activo.
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8"/>
<property name="basenames">
<list>
<value>WEB-INF/locale/messages/messages</value>
<value>WEB-INF/locale/fields/fields</value>
<value>WEB-INF/locale/values/values</value>
</list>
</property>
</bean>
Here are the relevant entries in the values_en_us.properties file:
user.status.A = Active
user.status.I = Inactive
user.status.P = Pending
I would like to build an Enum for each type of value that I can get the localized value from. In the code below, I have hardcoded the values being passed to the get message to reduce the number of variables when trying to debug this.
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public enum UserStatusEnum {
[Code] ....
When this code runs, I get the following message:
org.springframework.context.NoSuchMessageException: No message found under code 'user.status.A' for locale 'en_us'.
On this line of code:
description = appCtx.getMessage("user.status.A", null, new Locale("en_us"));
The application is already showing my custom application error messages I have in the messages localized files, but in that case the ApplicationContext is already available. Because I can get to the contents of the messages_en_us.property files, I'm assuming me config is correct. However, the classes that get the messages content are instantiated by Spring.
The Enums are not created by Spring, so my assumption is that I am doing something wrong in how I am getting a handle on the ApplicationContext or how I am using it.
After looking at the appCtx values in debug mode, I can see that the messageSource > basenames does at least contain my configuration data.
[WEB-INF/locale/messages/messages, WEB-INF/locale/fields/fields, WEB-INF/locale/values/values]
Although I don't see the whole filenames with the file extension anywhere or the property file entries.
View Replies
ADVERTISEMENT
Jul 16, 2014
-I created the project with the checkbox "Create separate folder for sources and class files."
-I've tried running the program with the "mfq.txt" file in the root directory, the src directory, and the bin directory.
-I've even tried it in all three directories at once!
-I've also refreshed my project after each change in eclipse
-My error is the "FileNotFoundException" error
Here is the line giving me trouble
Scanner file = new Scanner(new File("mfq.txt") );
Where my code is wrong/where I should put my file? :tax:
View Replies
View Related
Oct 8, 2014
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.transform.sax.TemplatesHandler;
public class SingleLinkedList<E> implements Iterable<E> {
// Instance variables.
private Node<E> head = null;
private int size = 0;
[code]....
Iam unable to display the contents of list. Error in toString().
View Replies
View Related
Feb 26, 2015
I have a list of uninstanciated class types and I wanted to call a static function from these "Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance but it appears I cant do that in java so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance but this code dont compile:
Java Code:
public PropControl Create(Class<? extends PropControl> cls)
{
if(cls==HouseControl.class) <---- ERROR
{
here I create a new instance of HouseControl (that inherits PropControl)
}
} mh_sh_highlight_all('java');
I get this error :
incomparable types: Class<CAP#1> and Class<HouseControl>
where CAP#1 is a fresh type-variable:
CAP#1 extends PropControl from capture of ? extends PropControl
how do I achieve this ?
View Replies
View Related
Apr 1, 2014
How to maintain quotes in a text file? If no source files .
Новый точечный .jpg
Prompt in what direction to go .... maybe you can use other languages to do it?
Заранее СПасибо!!!
View Replies
View Related
Dec 6, 2014
I am stuck on what to put in my functions for this question: Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:
-initialiseHighScores () which sets all high scores to zero.
-printHighScores() which prints the high scores in the format: "The high scores are 345, 300, 234", for all exisiting high scores in the list (remember that sometimes it won't be full).
-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.
-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list
here are my functions the insertScore is missing because I am having troubles with it.
public static void initialiseHighScores (int[] scores, int size)
{
for (int i = 0; i < size; i++)
{
scores [i] = 0;
}
}
public static boolean higherThan (int[] scores, int size, int newScore)
{
[Code]...
View Replies
View Related
Sep 3, 2014
I currently use Eclipse to maintain our Java application. I recently upgraded from Java 6 to Java 7. I updated my Eclipse projects to use the Java 7 .jar files. I can run the application from Eclipse via the Run Configuration.
I can also run the Ant build and it completes successfully. When I install the application on my desktop, I receive the "Java Virtual Machine Launcher: Could not find main class..." error. My CLASSPATH is set to ".".
View Replies
View Related
Jun 11, 2014
I have a small problem with my code that I can't figure out how to make it work the way it is supposed to. The code is supposed to be a game where a user has to guess numbers between 1-1000. The program counts how many times the user tried to guess the number and it displays a certain message if the guess number is less than 10, more than 10 or 10. I was able to write the code using loops. However, the messages will not always get printed on to the screen. The code seems to work fine except for the last part where the messages, "Either you know the secret or you got lucky", "You should be able to do better", "Aha! you know the secret!" are not always displayed like they are supposed to.
import java.util.Scanner;
public class Guess1 {
public static void main(String[] args) {
int secretNumber;
secretNumber = (int) (Math.random() * 999 + 1);
Scanner input = new Scanner(System.in);
int guess;
int replay;
int test;
test=1;
replay=1;
int count=0;
[code]....
View Replies
View Related
Mar 4, 2014
I have the following code that comes directly from the book Core Java vol 1. The last two statements are mine but when I change the last statement's String the message being logged doesn't change. For that manner when I change the level of the last statement the file doesn't update to the correct log level. What am I doing wrong?
Java Code:
public class LogTester
{
public static void main(String[] args)
{
if (System.getProperty("java.util.logging.config.class") == null
&& System.getProperty("java.util.config.file") == null)
[code]....
Forgot to say the file also only logs the old message and level from a previous recompilation
View Replies
View Related
May 25, 2014
I am new to Java/OOP in general, and am trying to implement a multi-threaded system that contains a master thread, and a set of worker threads that are heterogeneous in the work they do. Once they complete the work, the workers indicate to the master by posting the result on to its queue. Here is the problem. The results of each type of work is different, and the master has to process each differently. In C (which I'm familiar with), this can be achieved by having a message type that is a union of all the expected messages, and by using a switch statement.
I thought of doing something similar in Java, by using instance of on each incoming message (each individual message class having been subclassed from a super message class) , and doing switch on that, but it doesn't seem to be the OO way to do things. The only other way I could think of was to implement an abstract method to get the type of each message, and then use the type in a switch statement, or if-then-else. Is there some other Java idiom to do this kind of processing? Also, if this is an acceptable method, why is it superior to using the reflection to find out the message type (instead of using the abstract getType())?
The message types look similar to the code below:
abstract class Message {
abstract String getType();
} class Result1 extends Message {
ResultType1 content;
String getType() {
[Code] ....
View Replies
View Related
Jun 13, 2014
I am using ActiveMq alongwith Spring in my project. I want my queue to be configured to reject the duplicate messages.I tried my level best to do so. I tried googling for the same. but could not get anything.
View Replies
View Related
Mar 1, 2015
I am having issues with a few lines of code and a java.util.UnkownFormaException. Here are the issues:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at Storm.toString(Storm.java:99)
at StormChaser.DisplayStorms(StormChaser.java:149)
at StormChaser.main(StormChaser.java:55)
I have tried a lot of different things but can't seem to figure it out.
import java.io.*;
import java.util.Scanner;
public class StormChaser {
public static void main(String[] args)
[code]....
View Replies
View Related
Apr 7, 2014
MQ Issue on the Websphere 7.0.0.25 server ..Same Message is getting redelivered again and again and below exception is coming in System out log. And secondly the messages are not getting processed completely.
[4/7/14 12:14:58:616 GMT+05:30] 0000001e LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[4/7/14 12:16:14:738 GMT+05:30] 00000062 LocalExceptio E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "onMessage" on bean "BeanId(myroj#myEJB.jar#MQMessageReceiverMDB, null)". Exception data: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor77.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java:47)
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:98)
[code]...
View Replies
View Related
Jan 18, 2012
I have some data in the database and values can be added on demand. so when ever the value added to the database i need to promt that message to all users which are accessing my website, so how can i acheive this....
View Replies
View Related
Apr 8, 2014
I'm working on a project that has two separate components. The first is a back end, that will do most of the heavy lifting, the other part is a front end GUI. The GUI will include the back end into it's project as an imported JAR file.
I need to be able to keep these two decoupled, as I might be writing different front ends using the same back end. The challenge in front of me (well one of many) is how to pass messages from the back end to the GUI so I can report things that are happening.
For example, if i call method FOO, FOO might do several different things; connect to a database, divide by zero, solve world hunger. I want to be able to either tie a JTextArea , or another component (or multiple components) to this stack of information, or at the very least, have something listening for this information, and when I see that my back end reports something, my front end is quickly aware of this information, and then I can process it and inform the user of the front end.
It would also be useful to be able to send a message from front end to back end , so perhaps the back end might learn that the front end user is unhappy and would like to stop running the current query.
View Replies
View Related
Jan 28, 2014
I have one row editable datatable.I have implemented email validation to one of the column where error message must display on blur of email field.This is working fine.I have a dialog with form to be displayed in the same page. Validation is implemented to this form also with on blur event. The dialog validation message gets displayed on blur but along with that the main form also displays the same validation message. This should not happen.
JSF page
<h:form id="lpcForm">
<div id="content">
<p:commandLink id="cmdLinkDelete" value="Delete"
style="font-size:15px;padding-left:15px;" ajax="true"
action="#{lpcBean.deleteRecords}" update=":lpcForm:lpcDataTable" />
[Code] ....
The message with id lpcErrMsg is the one that i am displaying on blur in the main page when email format is wrong.And this message gets displayed with dialog field validation also although i have never referred to this id to be rendered in the dialog.
The message with id lpcDlgMsg is the message that i am displaying inside the dialog with widgetvar dlg on blur.As of now i have implemented blur event validation for the first required field in the dialog.
View Replies
View Related
Oct 7, 2014
I have a simple method in Java through which I send commands to a machine over TCP. The problem is:
Machine can't accept more than two connections in 20 seconds.
I need to send 15-20 commands to the machine in 3 minutes.
This is my current method which is not working as it should, 2 commands get transmited but third command hangs because of the machine.
void sendCommand(String command) throws IOException {
String ipaddress = "192.168.0.2";
Socket commandSocket = null;
BufferedWriter out = null;
BufferedReader in = null;
BufferedWriter outToDetailFile = null;
[Code] .....
Basically what i need is:
1st: I need to open the connection by calling method
public void openConnection(String ipaddress, String port){
//Code to start the connection
}
2nd: I need to be able to send commands to the connection I have already opened (i will send multiple messages in time period of 5-10 minutes):
public void sendCommand(String message){
}
3rd: Close that connection
public void closeConnection(){
}
View Replies
View Related
Oct 26, 2014
What step to know to develop software..
View Replies
View Related
Mar 18, 2014
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*;
public class FileDisplay
{
private String filename;
public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead()
{FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
View Replies
View Related
Oct 14, 2014
in log4j,in a web aplication i need loging in separate file,logging for action package in one file and dao in another file in action package log a class if this is possible in a class then a level in a file another level in another file.
View Replies
View Related
Feb 26, 2014
Java Code:
setseatpos: function(previouspos, position) {
this.seatelement.removeclass("seat-empty").removeclass("seat-pos-" + previouspos).removeclass("seat-inactive").addclass("seat-pos-" + position);
},
renderseat: function() {
[Code] ....
View Replies
View Related
Apr 13, 2015
In a program I created, I'm using a text file that contains some texts needed for the program. The method relevant to this is something like the following.
private String wordgen(){
try {
BufferedReader reader = new BufferedReader(new FileReader("src/Resources/adjectives.txt"));
Random rand = new Random();
int low = rand.nextInt(400);
String fil="";
int i=0;
while(i!=low){
[Code]...
The program runs fine in netbeans project but once the jar is created it does not corporate with the text file. ("null" is returned) How can I attach text files to jar and exe?
View Replies
View Related
May 18, 2014
We have this website that is run on two web applications. The first web application hosts the home page and clicking certain links in the home page would forward it to pages of the second web application where certain functionalities can be done. Now, there has been an initiative to redesign the site to have a login page and only logged in users could browse it. This would mean a login page being created in the first app, and when links to the second application are clicked, the pages are supposed to forward to it with the same session of the user that logged in.
We have already creating handling to pass the session from the first app to the second. Logging out from the first application would also invalidate the same user session in the second application. My questions is, is this a bad idea? would it be better to combine the two apps even if it would mean a huge impact?
or is there are better way to do this? like set it in web.xml. I have read that you cannot use two context for it.
View Replies
View Related
Jan 12, 2014
my application shows a profile. The profile has various interactors. I'm trying to follow the MVC model, so I neeed to tell my controller that something was selected. But the profile has many elements that can be selected(mostly labels, so not setActionCommand), how do I tell it WHICH one was it?
how do I separate those interactors? I created a HashMap that maps from JLabels to Strings. When a mouse event occurs I loop trough it to search for the event source. If I find it I fire my custom event.
View Replies
View Related
Oct 21, 2014
I am working on an assignment that is to simulate the relationship between a cache and main memory. Basically it is supposed to be a 16 slot cache and we are to have 500 for main memory. I need it to compare the corresponding index for both arrays, then go through then repeat the cache array and compare it to the next 16 of main memory. It is to simulate an direct mapped cache. How to compare two arrays from separate loops.
public class MainMemory {
private short mainMem[] = new short[200];
public void assign(){
short i;
for ( i = 0; i < mainMem.length; i ++){
mainMem[i] = i;
[Code] .....
View Replies
View Related
Feb 25, 2014
I am implementing the hash join algorithm for a project with a hard coded hash function. I've hashed the first relation and I've hashed the second relation. The problem is when hashing the second relation I only know how to add the tuple from the second relation into a third relation and not also access the first relation tuple at that time
The "hashtable" structure contains the hashcode of my key as well as the tuple stored in a string. This code below is taking place in the hashing of the second table, my function determines that both these tuples share the same hash code based on the first element in the tuple (element 0) so I add the tuple from my second relation to the qRelation but I also want to add the tuple from the hashtable at that point and I don't know how to access that string
if(hashtable.containsKey(tuple/*(RELATIONA)*/.get(0).hashCode()))
{
//Add the tuple from relation A into qRelation wich matches the
//above condition
qRelation.addAll(tuple/*(RELATIONB)*/);
}
View Replies
View Related