soumya kalla

Greenhorn
+ Follow
since Jun 05, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by soumya kalla

Hello,

Could somebody please help me with this problem,i've been waiting for a reply for a long time.

Thanks,
Soumya
18 years ago
JSF
Hello,

In my dataTable I am trying to do a column sort on each column, I got some examples off of the net, and tried, but when i click on the column header link nothing is happening. Could somebody please help. Please let me know if I am missing something.

Here is the code.

The jsf is as follows:

<h:panelGrid columns="1" styleClass="tableHeaderAction">
<t:dataTable id="fooS" value="#{supervisorsDto.tableRows}"
var="tableRow" rows"30" styleClass="dataTable"
headerClass="tableHeader" first="0"
columnClasses="string,string,string,string"
rowClasses="odd,even"
sortAscending="#{supervisorsDto.ascending}"
sortColumn="#{supervisorsDto.sort}"
preserveSort="true" >
<t:column>
<f:facet name="header">
<t:commandSortHeader columnName="lastName" arrow="false">
<t:outputText value="#{screen.lastName}" />
</t:commandSortHeader>
</f:facet>
<t:outputText value="#{tableRow.lastName}" />
</t:column>
<t:column>
<f:facet name="header">
<t:commandSortHeader columnName="firstName" arrow="false">
<t:outputText value="#{screen.firstName}" />
</t:commandSortHeader>
</f:facet>
<t:outputText value="#{tableRow.firstName}" />
</t:column>
<t:column>
<f:facet name="header">
<t:commandSortHeader columnName="loginName" arrow="false">
<t:outputText value="#{screen.loginName}" />
</t:commandSortHeader>
</f:facet>
<t:outputText value="#{tableRow.loginName}" />
</t:column>

<t:column>
<f:facet name="header">
<t:commandSortHeader columnName="team" arrow="false">
<t:outputText value="#{screen.team}" />
</t:commandSortHeader>
</f:facet>
<t:outputText value="#{tableRow.team}" />
<h:inputHidden id="key" value="#{tableRow.empID}" />
</t:column>
</t:dataTable>
</h:panelGrid>


The sort method in SupervisorsDto is as follows:

public class SupervisorsDto implements Serializable {

private String sort="lastName";
private boolean ascending= true;


@SuppressWarnings("unchecked")
public void sort(final String column,final boolean ascending)
{
Comparator comparator = new Comparator()
{
public int compare(Object o1, Object o2)
{
Supervisors c1 = (Supervisors)o1;
Supervisors c2 = (Supervisors)o2;
if (column == null)
{
return 0;
}
if (column.equals("lastName"))
{
return ascending ? c1.getLastName().compareTo(c2.getLastName()) : c2.getLastName().compareTo(c1.getLastName());
}
else if (column.equals("firstName"))
{
return ascending ? c1.getFirstName().compareTo(c2.getFirstName()) : c2.getFirstName().compareTo(c1.getFirstName());
}
else if (column.equals("loginName"))
{
return ascending ? c1.getLoginName().compareTo(c2.getLoginName()) : c2.getLoginName().compareTo(c1.getLoginName());
}
else if (column.equals("team"))
{
return ascending ? c1.getTeam().compareTo(c2.getTeam()) : c2.getTeam().compareTo(c1.getTeam());
}
else return 0;
}
};
Collections.sort(tableRows, comparator);
}

public void sort(String sortColumn)
{
if (sortColumn == null)
{
throw new IllegalArgumentException("Argument sortColumn must not be null.");
}

if (sort.equals(sortColumn))
{
//current sort equals new sortColumn -> reverse sort order
ascending = !ascending;
}
else
{
//sort new column in default direction
sort = sortColumn;
ascending = isDefaultAscending(sort);
}

sort(sort, ascending);
}

protected boolean isDefaultAscending(String sortColumn)
{
return true;
}

public String getSort() {
return sort;
}

public void setSort(String sort) {
this.sort = sort;
}

public boolean isAscending() {
return ascending;
}

public void setAscending(boolean ascending) {
if(ascending != this.ascending)
this.ascending = ascending;
}

Thanks,
Soumya
18 years ago
JSF
Bauke,

Thankyou so much for the code. I tried it using the rowIndex just like you suggested and it worked.
I also thank the others for their help.

Soumya
18 years ago
JSF
Hello,

I am using myFaces for my dataTable. The first cloumn in my table has checkboxes and the other columns have data.
In the first row I want to add a button instead of a checkbox.


<t:dataTable id="fooPB" value="#{phoneBooksTableDataBeanDto.tableRows}"
var="tableRow" rows="5" styleClass="dataTable"
headerClass="tableHeader" first="0"
columnClasses="checkbox, string, string, string, string"
rowClasses="odd, even">

<t:column>
<f:facet name="header">
</f:facet>
<h:selectBooleanCheckbox value="#{tableRow.selected}" />
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="#{screen.lastName}" />
</f:facet>
<t:inputText value="#{tableRow.lastName}" />
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="#{screen.firstName}" />
</f:facet>
<t:inputText value="#{tableRow.firstName}" />
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="#{screen.phoneNumber}" />
</f:facet>
<t:inputText value="#{tableRow.phoneNumber}" />
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="#{screen.notes}" />
</f:facet>
<t:inputText value="#{tableRow.notes}" />
</t:column>
</t:dataTable>
</h:panelGrid>


i tried adding another set of <f:facet></f:facet> in each column below the header, but the row itself did not show up. Could somebody please tell me how I can add a button to the first row.

I hope my question is clear enough.
18 years ago
JSF
I used setPreferredSize(with,height) but it did not work. The whole image is not being displayed using it. Here is my code

JPanel backpanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel picture1 = new JLabel();
picture1.setIcon(new ImageIcon(bulkLoadGUI.getClass().getClassLoader().getResource(
RESPATH + "image1.jpg")));
picture1.setPreferredSize(new Dimension(100,100));
// g.drawImage(img, 0, 0, this);

backpanel1.add(picture1);

I would really appreciate if you could suggest something.

Soumya
18 years ago
I just realized that the whole image is not being displayed using setPreferredSize(width,height). Please suggest something.

Soumya
18 years ago
I am sorry i got the answer from somebody else's postings.

Thanks,
Soumya
18 years ago
Hai,

I want to add a background image to my login panel. So i used a JLabel to do that, but I am not able to reduce the size of the image. Can anyone please suggest something. Here is my code

JPanel backpanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel picture1 = new JLabel();
picture1.setIcon(new ImageIcon(bulkLoadGUI.getClass().getClassLoader().getResource(
RESPATH + "image1.jpg")));
// picture1.setBounds(2,2,2,2);

// picture1.setsize(20,20);
backpanel1.add(picture1);


Please reply ASAP.

Thanks,
Soumya
18 years ago
Thankyou! I used the lengths and tried the application. It worked.
18 years ago
In a login screen, when a user submits a blank page without entering a username and password, it should show an error message. What methods should I use to check that the fields are blank when submitted?

Soumya
18 years ago
Hi,
In my login screen, when I enter the username and password I have to press Tab and space to Submit. As the submit button is not set default. The problem is when I use getRootPane I am getting an exception in thread main when i run the application. I am sure there is something wrong with my code. Can somebody please suggest something.



package com.spanlink.cc.bulk;

import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.RootPaneContainer;

import java.util.*;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import com.spanlink.cc.bulk.common.BulkUtil;
import com.spanlink.cc.bulk.common.BulkConstant.BulkMessage;
import com.spanlink.cc.bulk.common.BulkConstant.LoginElem;
import com.spanlink.cc.bulk.model.UserApi;
import com.spanlink.cc.domain.misc.UserCredentials;

public class LoginDialog {

private JDialog loginDialog;
private static final String SUBMIT = "SUBMIT";
private static final String CANCEL = "CANCEL";
private static final String LOGIN = "login";
private static final String PASSWORD = "password";
private static final String TITLE = "title";
// private static final String INVALIDMESSAGE = BulkUtil.getLocalMsg(BulkMessage.BLEC1014.getText());

private BulkLoadGUI bulkLoadGUI;

public LoginDialog(BulkLoadGUI bulkLoadGUI){
this.bulkLoadGUI = bulkLoadGUI;

Object [] objects = { buildLoginPanel() };
String message = BulkUtil.getLocalText(TITLE);
JOptionPane pane = new JOptionPane(
message,
JOptionPane.INFORMATION_MESSAGE,
JOptionPane.OK_OPTION,
null,
objects);
loginDialog = pane.createDialog(loginDialog, message);
loginDialog.setVisible(true);
}

private Component buildLoginPanel() {
JPanel Msgpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
final JLabel Msglabel = new JLabel("");

/* public void paint(Graphics g){
super.paint(g);
g.setColor(Color.RED);
g.drawString(Msglabel + g.getColor(), 130, 40);
}*/
// Msglabel.paintComponent(g);
// Msgpanel.setColor(Color.red);
Msglabel.repaint();



Msgpanel.add(Msglabel);

JPanel userpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JLabel Loginlabel = new JLabel(BulkUtil.getLocalText(LOGIN));
final JTextField Login = new JTextField(20);
Loginlabel.setLabelFor(Login);
userpanel.add(Loginlabel);
userpanel.add(Login);

JPanel pwdPanel = new JPanel(new FlowLayout());
JLabel passwordLabel = new JLabel(BulkUtil.getLocalText(PASSWORD));
final JPasswordField pwdField = new JPasswordField(20);
passwordLabel.setLabelFor(pwdField);
pwdPanel.add(passwordLabel);
pwdPanel.add(pwdField);

final JButton submit = new JButton(BulkUtil.getLocalText(SUBMIT));
// getRootPane().setDefaultButton(submit);
// ((Object) getRootPane()).setDefaultButton(submit);
// submit.requestFocus();
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

String login = Login.getText();
String passWord = new String(pwdField.getPassword());

boolean submit = validatePassword(login, passWord);
if(submit==true){
loginDialog.dispose();
}
else if(submit==false) {
Msglabel.setText(BulkMessage.BLEC1014.getText());
Login.setText("");
pwdField.setText("");
Login.requestFocus();
}
}
});

// loginDialog.getRootPane().setDefaultButton(submit);
// submit.setVisible(true);


submit.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER){
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

String login = Login.getText();
String passWord = new String(pwdField.getPassword());

boolean submit = validatePassword(login, passWord);
if(submit==true){
loginDialog.dispose();
}
else if(submit==false) {
Msglabel.setText(BulkUtil.getLocalMsg(BulkMessage.BLEC1014.getText()));
Login.setText("");
pwdField.setText("");
Login.requestFocus();
}
}
});
}
}
});


final JButton cancel = new JButton(BulkUtil.getLocalText(CANCEL));
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
cancel.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ESCAPE){
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
}
}
});

JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(Msgpanel);
panel.add(userpanel);
panel.add(pwdPanel);

JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(submit);

buttonPanel.add(cancel);
panel.add(buttonPanel);

return panel;

}

private boolean validatePassword(String username, String password) {
try{
UserApi user = new UserApi();
bulkLoadGUI.setUserCredentials(user.authenticateUser(username, password));
return true;
}catch(Exception exc){
bulkLoadGUI.setUserCredentials(null);
return false;
}

}
}
18 years ago