Posted by Gökhan Şahin on Jul 19, 2012 in
JSF,
Java,
Web,
Yazılım
jsf ile programınızın birden fazla dil ile çalışmasını istiyorsanız.
kodların olduğu dosya yoluna message.properties, message_tr.properties ve message_en.properties dosyalarını
oluşturuyoruz.
Dosyaları açıp içine
default ve en için
user.name=Username
tr için
user.name=Kullanıcı adı
yazıyoruz.
Faceconfig.xml dosyasına aşağıdaki eklemeleri yapıyoruz.
<application>
<resource-bundle>
<base-name>messages</base-name>
<var>messages</var>
</resource-bundle>
..
..
<locale-config>
<default-locale>tr</default-locale>
<supported-locale>en</supported-locale>
</locale-config>
</application>
@Named
@SessionScoped
public class UserSessionMB implements Serializable {
private Locale userLocale;
public UserSessionMB(){
//Buraya login olan kullanıcının yada loginde sorduğunuz lokasyon bilgisini giriniz.
userLocale = new Locale('tr');
}
public Locale getUserLocale() {
return userLocale;
}
}
Kullandığınız template yada her safanın başına aşağıdaki komutu yazın
<f:view contentType="text/html" locale="#{userSessionMB.userLocale}">
<f:loadBundle basename="messages" var="msg" />
<body>
<h:outputLabel value="#{msg['user.userName']}" />
</body>
</f:view>
Tags: Java, JSF
Posted by Gökhan Şahin on Jun 26, 2012 in
JSF,
Java,
Web
private UIComponent findComponent(UIComponent c, String id) {
if (id.equals(c.getId())) {
return c;
}
Iterator kids = c.getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent found = findComponent(kids.next(), id);
if (found != null) {
return found;
}
}
return null;
}
Root ‘u bulup bulmak istediğmiz componentin idsini veriyoruz.
UIComponent root = facesContext.getViewRoot();
UIInput codeComponent = (UIInput)findComponent(root, "ComponentID");
Tags: Java, JSF
Posted by Gökhan Şahin on Jun 2, 2010 in
Java
Javada bu hatayı alırsanız. java -XX:MaxPermSize=128m şeklinde çalıştırabilirsiniz. Web serverlarda ise server start option kısmında bu ayarı yapmanız gerekmektedir.
Kaynak :http://www.freshblurbs.com/explaining-java-lang-outofmemoryerror-permgen-space
Tags: Java
Posted by Gökhan Şahin on Apr 8, 2010 in
Java,
Yazılım
Windows yada linux te görmüştürsünüz. Tarih saat yada bağlantı ayarlarını gösteren simler görev çubuğuna yerleşir. Burdan bu simgelere tıklayarak belli programlar çalıştırabilirsiniz. Java da böyle bir uygulama örneği ihtiyacınız olacaktır.
import java.awt.*;
import java.awt.event.*;
public class SystemTrayTest {
public SystemTray() throws AWTException {
final TrayIcon trayIcon;
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("unlem.gif");
MouseListener mouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
if (sistemUpTest()) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
kendiFormnuz t = new kendiFormnuz();
t.setVisible(true);
}
});
}
}
public void mouseEntered(MouseEvent e) {
System.out.println("Tray Icon - Mouse entered!");
}
public void mouseExited(MouseEvent e) {
System.out.println("Tray Icon - Mouse exited!");
}
public void mousePressed(MouseEvent e) {
System.out.println("Tray Icon - Mouse pressed!");
}
public void mouseReleased(MouseEvent e) {
System.out.println("Tray Icon - Mouse released!");
}
};
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Çıkış");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Program ismi", popup);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.displayMessage("Action Event",
"An Action Event Has Been Peformed!",
TrayIcon.MessageType.INFO);
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}
} else {
System.err.println("System tray is currently not supported.");
}
}
public static void main(String[] args) throws AWTException {
SystemTray main = new SystemTray();
}
}
}
Tags: Java