この例h:datatable
では、JSFページで編集可能なものを作成する方法を見つけました。
似たようなものを作りたいのですが、h:panelGrid
:
<h:panelGrid columns="2">
<h:panelGroup>User ID</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{AccountProfileController.settings['USERID']}"/>
<h:inputText value="#{AccountProfileController.settings['USERID']}"/>
</h:panelGroup>
<h:panelGroup>Group ID</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{AccountProfileController.settings['GROUPID']}"/>
<h:inputText value="#{AccountProfileController.settings['GROUPID']}"/>
</h:panelGroup>
<h:panelGroup>Special Number</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{AccountProfileController.settings['SPECIALNUMBER']}"/>
<h:inputText value="#{AccountProfileController.settings['SPECIALNUMBER']}"/>
</h:panelGroup>
<h:panelGroup>Username</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{AccountProfileController.settings['USERNAME']}"/>
<h:inputText value="#{AccountProfileController.settings['USERNAME']}"/>
</h:panelGroup>
</h:panelGrid>
管理対象Bean:
import javax.sql.DataSource;
import javax.annotation.Resource;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.glassfish.osgicdi.OSGiService;
@Named("AccountProfileController")
@ViewScoped
public class AccountProfile implements Serializable {
@Resource(name = "jdbc/Oracle")
private DataSource ds;
private int id;
// This Hash Map will be used to store setting and value
private HashMap<String, String> settingsMap = new HashMap<>();
public HashMap<String, String> getsettings()
{
return settingsMap;
}
public AccountProfile()
{
// get the ID value
try
{
this.id = Integer.parseInt((String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"));
}
catch (Exception e)
{
this.id = 0;
}
}
@PostConstruct
public void initData() throws SQLException
{
// settingsMap = new HashMap<String, String>();
if (ds == null)
{
throw new SQLException("Can't get data source");
}
// Initialize a connection to Oracle
Connection conn = ds.getConnection();
if (conn == null)
{
throw new SQLException("Can't get database connection");
}
// With SQL statement get all settings and values
PreparedStatement ps = conn.prepareStatement("SELECT * from USERS where USERID = ?");
ps.setInt(1, id);
try
{
//get data from database
ResultSet result = ps.executeQuery();
while (result.next())
{
// Put the the data from Oracle into Hash Map
settingsMap.put("USERID", result.getString("USERID"));
settingsMap.put("GROUPID", result.getString("GROUPID"));
settingsMap.put("SPECIALNUMBER", result.getString("SPECIALNUMBER"));
settingsMap.put("USERNAME", result.getString("USERNAME"));
settingsMap.put("PASSWD", result.getString("PASSWD"));
settingsMap.put("DATETOCHANGEPASSWD", result.getString("DATETOCHANGEPASSWD"));
settingsMap.put("ADDRESS", result.getString("ADDRESS"));
settingsMap.put("STATEREGION", result.getString("STATEREGION"));
settingsMap.put("COUNTRY", result.getString("COUNTRY"));
settingsMap.put("USERSTATUS", result.getString("USERSTATUS"));
settingsMap.put("TELEPHONE", result.getString("TELEPHONE"));
settingsMap.put("DATEUSERADDED", result.getString("DATEUSERADDED"));
settingsMap.put("USEREXPIREDATE", result.getString("USEREXPIREDATE"));
settingsMap.put("DATEUSERLOCKED", result.getString("DATEUSERLOCKED"));
settingsMap.put("CITY", result.getString("CITY"));
settingsMap.put("EMAIL", result.getString("EMAIL"));
settingsMap.put("DESCRIPTION", result.getString("DESCRIPTION"));
}
}
finally
{
ps.close();
conn.close();
}
}
// Editable
boolean editable;
public boolean isEditable()
{
return editable;
}
public void setEditable(boolean editable)
{
this.editable = editable;
}
}
例のJSFページはalue="#{order.orderList}" var="o"
、データを表示するために使用します。私の場合、Javahashmap
を使用してデータを表示していますが、これを行う方法がわかりませんhashmap
。私の場合、編集可能なものを作成する方法を教えてくださいh:panelGrid
。
幸運をお祈りしています