on 09-06-2006 4:01 PM
Hi All,
I have created Dynamic UI Checkbox which is creating dynamic checkboxes based on the database Table fields.
Here is my code in Start View
// -
// This file has been generated partially by the Web Dynpro Code Generator.
// MODIFY CODE ONLY IN SECTIONS ENCLOSED BY @@begin AND @@end.
// ALL OTHER CHANGES WILL BE LOST IF THE FILE IS REGENERATED.
// -
package com.titan.retailauditreport;
//
// IMPORTANT NOTE:
// ALL IMPORT STATEMENTS MUST BE PLACED IN THE FOLLOWING SECTION ENCLOSED
// BY @@begin imports AND @@end. FURTHERMORE, THIS SECTION MUST ALWAYS CONTAIN
// AT LEAST ONE IMPORT STATEMENT (E.G. THAT FOR IPrivateStartView).
// OTHERWISE, USING THE ECLIPSE FUNCTION "Organize Imports" FOLLOWED BY
// A WEB DYNPRO CODE GENERATION (E.G. PROJECT BUILD) WILL RESULT IN THE LOSS
// OF IMPORT STATEMENTS.
//
//@@begin imports
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDCheckBox;
import com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDTransparentContainer;
import com.sap.tc.webdynpro.progmodel.api.IWDNode;
import com.sap.tc.webdynpro.progmodel.api.IWDNodeElement;
import com.sap.tc.webdynpro.progmodel.api.IWDNodeInfo;
import com.sap.tc.webdynpro.progmodel.api.IWDUIElement;
import com.titan.retailauditreport.wdp.IPrivateStartView;
//@@end
//@@begin documentation
//@@end
public class StartView
{
/**
Logging location.
*/
private static final com.sap.tc.logging.Location logger =
com.sap.tc.logging.Location.getLocation(StartView.class);
static
{
//@@begin id
String id = "$Id$";
//@@end
com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);
}
/**
Private access to the generated Web Dynpro counterpart
for this controller class. </p>
*
Use <code>wdThis</code> to gain typed access to the context,
to trigger navigation via outbound plugs, to get and enable/disable
actions, fire declared events, and access used controllers and/or
component usages.
*
@see com.titan.retailauditreport.wdp.IPrivateStartView for more details
*/
private final IPrivateStartView wdThis;
/**
Root node of this controller's context. </p>
*
Provides typed access not only to the elements of the root node
but also to all nodes in the context (methods node<i>XYZ</i>())
and their currently selected element (methods current<i>XYZ</i>Element()).
It also facilitates the creation of new elements for all nodes
(methods create<i>XYZ</i>Element()). </p>
*
@see com.titan.retailauditreport.wdp.IPrivateStartView.IContextNode for more details.
*/
private final IPrivateStartView.IContextNode wdContext;
/**
A shortcut for <code>wdThis.wdGetAPI()</code>. </p>
Represents the generic API of the generic Web Dynpro counterpart
for this controller. </p>
*/
private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;
/**
A shortcut for <code>wdThis.wdGetAPI().getComponent()</code>. </p>
Represents the generic API of the Web Dynpro component this controller
belongs to. Can be used to access the message manager, the window manager,
to add/remove event handlers and so on. </p>
*/
private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;
public StartView(IPrivateStartView wdThis)
{
this.wdThis = wdThis;
this.wdContext = wdThis.wdGetContext();
this.wdControllerAPI = wdThis.wdGetAPI();
this.wdComponentAPI = wdThis.wdGetAPI().getComponent();
}
//@@begin javadoc:wdDoInit()
/** Hook method called to initialize controller. */
//@@end
public void wdDoInit()
{
//@@begin wdDoInit()
// IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
// IPrivateStartView.INodeAElement ele=wdContext.createNodeAElement();
// wdContext.nodeNodeA().addElement(ele);
// IWDNodeInfo multiplenode=wdContext.nodeNodeA().getNodeInfo();
// IWDNodeInfo multipleinfo=multiplenode.addChild("MultiNode",null,true,true,false,false,false,true,null,null,null);
// multiplenode.addAttribute("roles", "ddic:com.sap.dictionary.string");
// multipleinfo.addAttribute("roles", "ddic:com.sap.dictionary.string");
// IWDNodeElement elem;
//IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
//node.addAttribute("BrandID");
ResultSet rs=null;
ResultSetMetaData rsmd=null;
Connection con=null;
PreparedStatement pst=null;
String status="SELECT BrandMaster.BrandID,BrandMaster.BrandName FROM BrandMaster WHERE BrandMaster.BrandID=?";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
wdComponentAPI.getMessageManager().reportSuccess("Driver Loaded");
con=DriverManager.getConnection("jdbc:odbc:Pankaj");
wdComponentAPI.getMessageManager().reportSuccess("Connected");
pst=con.prepareStatement(status);
pst.setInt(1,1);
rs=pst.executeQuery();
wdComponentAPI.getMessageManager().reportSuccess("Query Fired");
rsmd=rs.getMetaData();
int ttlcolumns=rsmd.getColumnCount();
wdComponentAPI.getMessageManager().reportSuccess("Populating Data1");
IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
//node.addAttribute("BrandID","BrandID:com.titan.retailauditreport");
node.addAttribute("BrandID",);
while(rs.next())
{
wdComponentAPI.getMessageManager().reportSuccess("Populating Data");
// IWDNode node1=wdContext.nodeNodeA().getChildNode("MultiNode",IWDNode.NO_SELECTION);
// IWDNodeElement elem=wdContext.nodeNodeA().createElement();
// node1.addElement(elem);
IWDNode node1=wdContext.getChildNode("DynamicNode",0);
IWDNodeElement ne1=node1.createElement();
for(int i=1;i<=ttlcolumns;i++)
{
if(i==1)
{
//elem.getBrandID(rs.getString(i));
String s1=rs.getString(i);
ne1.getAttributeValue("BrandID"+s1);
}
else if(i==2)
{
//elem.getBrandName(rs.getString(i));
//String BN=setBrandName((rs.getString(i)));
String s2=rs.getString(i);
ne1.getAttributeValue("BrandName"+s2);
}
}
rs.close();
pst.close();
con.close();
wdComponentAPI.getMessageManager().reportSuccess("Resources Closed");
}
}
catch(Exception e)
{
wdComponentAPI.getMessageManager().reportException("Error "+e,true);
}
//@@end
}
//@@begin javadoc:wdDoExit()
/** Hook method called to clean up controller. */
//@@end
public void wdDoExit()
{
//@@begin wdDoExit()
//@@end
}
//@@begin javadoc:wdDoModifyView
/**
Hook method called to modify a view just before rendering.
This method conceptually belongs to the view itself, not to the
controller (cf. MVC pattern).
It is made static to discourage a way of programming that
routinely stores references to UI elements in instance fields
for access by the view controller's event handlers, and so on.
The Web Dynpro programming model recommends that UI elements can
only be accessed by code executed within the call to this hook method.
*
@param wdThis Generated private interface of the view's controller, as
provided by Web Dynpro. Provides access to the view controller's
outgoing controller usages, etc.
@param wdContext Generated interface of the view's context, as provided
by Web Dynpro. Provides access to the view's data.
@param view The view's generic API, as provided by Web Dynpro.
Provides access to UI elements.
@param firstTime Indicates whether the hook is called for the first time
during the lifetime of the view.
*/
//@@end
public static void wdDoModifyView(IPrivateStartView wdThis, IPrivateStartView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
if(firstTime)
{
IWDTransparentContainer theGroup= (IWDTransparentContainer)view.getElement("RootUIElementContainer");
theGroup.createLayout(com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDMatrixLayout.class);
theGroup.destroyAllChildren();
IWDUIElement uiElement = null;
IWDCheckBox icb=(IWDCheckBox)view.createElement(IWDCheckBox.class,"CheckB");
//IWDAttributeInfo info = wdContext.getNodeInfo().getChild("NodeA").getChild("MultiNode").getAttribute("roles");
icb.bindChecked("DynamicNode.BrandID");
uiElement=icb;
theGroup.addChild(uiElement);
}
//@@end
}
/*
The following code section can be used for any Java code that is
not to be visible to other controllers/views or that contains constructs
currently not supported directly by Web Dynpro (such as inner classes or
member variables etc.). </p>
*
Note: The content of this section is in no way managed/controlled
by the Web Dynpro Designtime or the Web Dynpro Runtime.
*/
//@@begin others
//@@end
}
But iam not able to add attribute in the statement
int ttlcolumns=rsmd.getColumnCount();
wdComponentAPI.getMessageManager().reportSuccess("Populating Data1");
IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
//node.addAttribute("BrandID","BrandID:com.titan.retailauditreport");
node.addAttribute("BrandID",);
its throwing an error
Error:com.sap.tc.webdynpro.services.exceptions.WDTypeNotFoundException: type Boolean not found
Is that my database connectivity code ?
Can anybody plz help me out?
i
Thanks and Regards
Santosh Saraf
Hi,
The attribute which is added to the node should have a datatype value boolean.
so use the following code instead of node.addAttribute("BrandID",);
node.addAttribute("BrandID","ddic:com.sap.dictionary.boolean");
regards
Karthik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
It didnt work.So i changed my coding,Iam able to get checkbox.
Here is my code
public static void wdDoModifyView(IPrivateStartView wdThis, IPrivateStartView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
IWDMessageManager msgMngr=wdThis.wdGetAPI().getComponent().getMessageManager();
if(firstTime)
{
//IWDTransparentContainer theGroup= (IWDTransparentContainer)view.getElement("RootUIElementContainer");
IWDTransparentContainer theGroup= (IWDTransparentContainer)view.getElement("TransparentContainer");
theGroup.createLayout(com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDMatrixLayout.class);
theGroup.destroyAllChildren();
//IWDUIElement uiElement = null;
//IWDUIElement uiElement1 = null;
IWDUIElement uiElementnew = null;
//IWDCheckBox icb2=(IWDCheckBox)view.createElement(IWDCheckBox.class,"CheckA");
//IWDCheckBox icb1=(IWDCheckBox)view.createElement(IWDCheckBox.class,"CheckB");
//icb1.setText("Checkbox1");
//icb2.setText("Checkbox2");
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Pankaj");
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=st.executeQuery("select * from BrandMaster");
int count=0;
while(rs.next())
{
count++;
}
msgMngr.reportSuccess(""+count);
rs.beforeFirst();
IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
node.addAttribute("BrandID","ddic:com.sap.dictionary.boolean");
while(rs.next())
{
IWDNode node1=wdContext.getChildNode("DynamicNode",0);
IWDNodeElement ne1=node1.createElement();
ne1.setAttributeValue("BrandID",new Boolean(true));
//ne1.getAttributeValue("BrandID"+rs.getString(2));
IWDCheckBox icbnew=(IWDCheckBox)view.createElement(IWDCheckBox.class,"Checknew");
icbnew.setText(rs.getString(2));
icbnew.bindChecked("DynamicNode.BrandID");
uiElementnew=icbnew;
theGroup.addChild(uiElementnew);
}
msgMngr.reportSuccess(""+count);
}
catch(Exception e)
{}
//IWDAttributeInfo info = wdContext.getNodeInfo().getChild("NodeA").getChild("MultiNode").getAttribute("roles");
// icb1.bindChecked("DynamicNode.BrandID");
// icb2.bindChecked("DynamicNode.BrandID");
// uiElement=icb1;
// uiElement1=icb2;
// theGroup.addChild(uiElement);
// theGroup.addChild(uiElement1);
//
try
{if(con!=null)
con.close();
}
catch(Exception e)
{}
}
//@@end
}
/*
The following code section can be used for any Java code that is
not to be visible to other controllers/views or that contains constructs
currently not supported directly by Web Dynpro (such as inner classes or
member variables etc.). </p>
*
Note: The content of this section is in no way managed/controlled
by the Web Dynpro Designtime or the Web Dynpro Runtime.
*/
//@@begin others
//@@end
}
But now the problem is i need to have five dynamic checkboxes based on my tablebut iam getting only one check box with the first value of a column in a table(First Row).
I want to display all the five rows,even if iam giving the rs.next in while loop.
Here ia my table structure
Master Table
BrandID BrandName
1 abc
2 def
3 ghi
4 jkl
5 mno
Iam getting the only one checkbox with abc as text,i want all the five rows checkbox.
Plz help me out in this regard
Thanks and Regards
Santosh Saraf
Hi santosh,
if you use the following code to add attribute to node
node.addAttribute("BrandID","ddic:com.sap.dictionary.boolean");
then you will get one record. so put the following code in while loop.
set the count value to "0" before every while loop.
while(rs.next())
{
node.addAttribute("BrandID" + count,"ddic:com.sap.dictionary.boolean");
count++;
}
and if you want to set value to the attribute then use
while(rs.next())
{
.
.
ne1.setAttributeValue("BrandID"+count,new Boolean(true));
.
.
icbnew.bindChecked("DynamicNode.BrandID"+count);
.
count++;
}
hope this will work.
Hi,
The following line of code looks puzzling:
IWDCheckBox icbnew=(IWDCheckBox)view.createElement(IWDCheckBox.class,"Checknew");
This will always create UI elements with ID CheckNew. I think you should add different IDs to these UI elements.
For example:
IWDCheckBox icbnew=(IWDCheckBox)view.createElement(IWDCheckBox.class,"Checknew" + count);
Regards,
Satyajit.
Hi santosh,
create a checkbox in design time.
Bind an boolean attribute of a value node to the checked property of the checkbox.
create one action and bind that action to the onToggle property of the checkbox.
now you can write that code in this action. And one more thing, if you select the check box then all the dynamic check boxes are selected. then if you deselect that checkbox what would be done?
regards
karthik
Hi all,
I have followed the steps what u have told.But when i click that my dynamic check boxes are disappearing and only the select all check box is appearing.
Here is my code
public static void wdDoModifyView(IPrivateStartView wdThis, IPrivateStartView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
IWDMessageManager msgMngr=wdThis.wdGetAPI().getComponent().getMessageManager();
IWDTransparentContainer theGroup= (IWDTransparentContainer)view.getElement("TransparentContainer");
theGroup.createLayout(com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDMatrixLayout.class);
theGroup.destroyAllChildren();
IWDUIElement uiElementnew = null;
IWDUIElement uiElementnew1 = null;
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Pankaj");
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=st.executeQuery("select * from BrandMaster");
int count=0;
while(rs.next())
{
count++;
}
msgMngr.reportSuccess(""+count);
rs.beforeFirst();
IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
int a=count;
count=0;
while(rs.next())
{
node.addAttribute("BrandID"+count,"ddic:com.sap.dictionary.boolean");
count++;
msgMngr.reportSuccess("inwhile");
}
int b=count;
count=0;
rs.beforeFirst();
while(rs.next())
{
msgMngr.reportSuccess("inwhile1");
IWDNode node1=wdContext.getChildNode("DynamicNode",0);
IWDNodeElement ne1=node1.createElement();
ne1.setAttributeValue("BrandID"+count,new Boolean(true));
//ne1.getAttributeValue("BrandID"+rs.getString(2));
IWDCheckBox icbnew=(IWDCheckBox)view.createElement(IWDCheckBox.class,"Checknew"+count);
icbnew.setText(rs.getString(2));
icbnew.bindChecked("DynamicNode.BrandID"+count);
uiElementnew=icbnew;
theGroup.addChild(uiElementnew);
count++;
}
msgMngr.reportSuccess(""+count);
}
catch(Exception e)
{}
try
{
if(con!=null)
con.close();
}
catch(Exception e)
{}
// }
//@@end
}
//@@begin javadoc:onActionOnToggleCheckBox(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionOnToggleCheckBox(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionOnToggleCheckBox(ServerEvent)
IWDNode node=wdContext.getChildNode("DynamicNode",0);
for(int i=0;i<node.size();i++)
{
node.getElementAt(i).setAttributeValue("BrandID"+i,new Boolean(wdContext.currentNodeAElement().getValue()));
}
//@@end
}
What to be done now?
Thanks and Regards
Santosh saraf
Hi santosh,
sorry I tried that but that code doesn't work.
in your doModify() part,use the if condition
if(firstTime)
{
place your existing DoModify() code here.
}
else
{
for(int i=0;i<n;i++)// n is the number of checkboxes created by you.
{
IWDCheckBox chk=(IWDCheckBox)view.getElement("Checknew" + i);
chk.setChecked(true);
}
the else part contains the code which is done in onToggle action. this works fine, try it.
regards
karthik
}
Hi Karthikeyan,
I tried it but the same problem.
Here is my code
public static void wdDoModifyView(IPrivateStartView wdThis, IPrivateStartView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
IWDMessageManager msgMngr=wdThis.wdGetAPI().getComponent().getMessageManager();
IWDTransparentContainer theGroup= (IWDTransparentContainer)view.getElement("TransparentContainer");
theGroup.createLayout(com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDMatrixLayout.class);
theGroup.destroyAllChildren();
IWDUIElement uiElementnew = null;
IWDUIElement uiElementnew1 = null;
Connection con=null;
int count=0;
if(firstTime)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Pankaj");
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=st.executeQuery("select * from BrandMaster");
int c=count;
count=0;
while(rs.next())
{
count++;
}
msgMngr.reportSuccess(""+count);
rs.beforeFirst();
IWDNodeInfo node=wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
int a=count;
count=0;
while(rs.next())
{
node.addAttribute("BrandID"+count,"ddic:com.sap.dictionary.boolean");
count++;
msgMngr.reportSuccess("inwhile");
}
int b=count;
count=0;
rs.beforeFirst();
while(rs.next())
{
msgMngr.reportSuccess("inwhile1");
IWDNode node1=wdContext.getChildNode("DynamicNode",0);
IWDNodeElement ne1=node1.createElement();
ne1.setAttributeValue("BrandID"+count,new Boolean(true));
//ne1.getAttributeValue("BrandID"+rs.getString(2));
IWDCheckBox icbnew=(IWDCheckBox)view.createElement(IWDCheckBox.class,"Checknew"+count);
icbnew.setText(rs.getString(2));
icbnew.bindChecked("DynamicNode.BrandID"+count);
uiElementnew=icbnew;
theGroup.addChild(uiElementnew);
count++;
}
msgMngr.reportSuccess(""+count);
}
catch(Exception e)
{}
try
{
if(con!=null)
con.close();
}
catch(Exception e)
{}
}
else
{
for(int i=0;i<count;i++)// n is the number of checkboxes created by you.
{
IWDCheckBox chk=(IWDCheckBox)view.getElement("Checknew" + i);
chk.setChecked(true);
}
}
//@@end
}
//@@begin javadoc:onActionOnToggleCheckBox(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionOnToggleCheckBox(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionOnToggleCheckBox(ServerEvent)
IWDNode node=wdContext.getChildNode("DynamicNode",0);
for(int i=0;i<node.size();i++)
{
node.getElementAt(i).setAttributeValue("BrandID"+i,new Boolean(wdContext.currentNodeAElement().getValue()));
}
//@@end
}
/*
The following code section can be used for any Java code that is
not to be visible to other controllers/views or that contains constructs
currently not supported directly by Web Dynpro (such as inner classes or
member variables etc.). </p>
*
Note: The content of this section is in no way managed/controlled
by the Web Dynpro Designtime or the Web Dynpro Runtime.
*/
//@@begin others
//@@end
}
Can u plz help me out since its very urgent.
Thanks and Regards
Santosh saraf
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.