Joe ONeil

Greenhorn
+ Follow
since Jan 16, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joe ONeil

<!--Header you have to experiment with the sizes it will not be exact-->


<t:panelGrid columns="2" bgcolor="#a8b8cf"
style="font-size: 11px; width: 350px; font-weight: bold;">
<t:outputLabel value="Column1"
style="width: 100px; align: center;" styleClass="headerText"></t:outputLabel>
<t:outputLabel value="Column2"
style="width: 232px; align: center;" styleClass="headerText"></t:outputLabel>
</t:panelGrid>

<!--Table-->
<div style="height: 300px; width: 350px; overflow: auto">
<t:dataTable id="table" renderedIfEmpty="false" cellpadding="2"
width="100%" cellspacing="1" var="List"
value="#{SearchHandler.rowsList}"
binding="#{SearchHandler.myDataTable}" rows="0"
rowClasses="row1, row2" headerClass="headerText"
footerClass="footerText" preserveDataModel="false"
preserveSort="false" border="1" styleClass="searchBox">

<t:column width="100px">
<h:outputLink
<t:outputText value="#{List.col1}" />

</h:outputLink>

</t:column>

<t:column width="250px">

<t:outputText id="ad" value="#{List.col2}" />
</h:outputLink>
</t:column>

</t:dataTable>

</div>

This create a table 300X350 with a scrollable data table
14 years ago
JSF
function callbutton(){
document.getElementById("Frm1" + ":vendbtn").click();
}

if you want to make the button invisible you can do this

<h:form id="Frm1">

<t:commandButton id="vendbtn" value="" action="#{poDetail.loadVendorAddresses}" immediate="true"
style="visibility:hidden;" />
</h:form>
immediate ="true // skip validation and you will not beable to pick up values from the page
the style hides the button and there is no tab location
14 years ago
JSF
Did you register the custom message file in the JSF config file

<application>
<message-bundle>customMessages</message-bundle>
</application>

14 years ago
JSF
immediate="true" but you will not be able to read any of the input fields this is good if you are going to open a popup or go to another div
14 years ago
JSF
http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-jsf.html
This is a complete JSF example This is what I started with but I have since tweeked it quite a bit
Spring Beans instead of JSF Managed beans
Ibaitis instead of Hibernate since I was working on a legacy app and I do not have control of the database
I have made many changes but it is a good place to start
I started with JSP and converted to Facelets much better performance
I also use the Myfaces Tomahawk implimentation
14 years ago
JSF
Tomahawk has <t:inputFileUpload>
14 years ago
JSF
Yes

<h:inputText value="#{bean.keyword}" onblur ="document.getElementById('formName:btn1').click();"/>


<h:commandButton action ="#{bean.search}" value="Search" id="btn1"/>

When the value change it gets the bean id and fire the click event
14 years ago
JSF
Building Dynamic Data table
The problem I had to solve was to be able to search multiple parts
over multiple sources one method of doing it was to create a static number of tables but that would be limiting
Solution
Create a binded panel grid

JSP/Facelet Page


<h:form id="dynTable" >
<t:panelGrid binding="#{multiPartSearch.panelGrid}" id="pgdt" />
</h:form>
Java Code
public class MultiPartSearch extends ConObject {
private HtmlPanelGrid panelGrid;

.......

public HtmlPanelGrid getPanelGrid() {
return panelGrid;
}

public void setPanelGrid(HtmlPanelGrid panelGrid) {
this.panelGrid = panelGrid;
}
Binding the grid alone is not enough you also have to Initialize it in the class constructor


panelGrid=(HtmlPanelGrid) fc
.getCurrentInstance().getViewRoot().findComponent("dynTable:pgdt");

I have a search method that creates the Datamodels After getthing the datamodels
You clear the panelGrid otherwise each time you hit search you will append to the panelGrid




public void searchRecords() {
//Clear children on each search
panelGrid.getChildren().clear();
.....

For Part number A create a panelGrid

HtmlPanelGrid dtPanelGrid = new HtmlPanelGrid();

Pass the dtPanelGrid into the createDemandTable method
After the table is created add it to dtPanelGrid
You can add as many tables as memory will allow to the dtPanelgrid


/*This Method creates a Data table inside of a panel grid

public void createDemandTable(HtmlPanelGrid dtPanelGrid,
String dtValueExpression, DataModel datamodel, String rowVar) {

HtmlDataTable dataTable1 = new HtmlDataTable();
dataTable1.setValueExpression("value", createValueExpression(
dtValueExpression + ".dataModel}", DataModel.class));
dataTable1.setId("demdt" + rowVar);
// dataTable1.setRenderedIfEmpty(false);
dataTable1.setBorder(0);
dataTable1.setCellpadding("1");
dataTable1.setVar(rowVar);
dataTable1.setHeaderClass("headerText");
dataTable1.setFooterClass("footerText");
dataTable1.setRowClasses("row1, row2");
HtmlColumn col1 = new HtmlColumn();
col1.setId("demCol1"+idcount++);
HtmlOutputText header1 = new HtmlOutputText();
header1.setValue("MPN");
header1.setId("demdtMpn" + rowVar);
HtmlCommandLink idLink = new HtmlCommandLink();
idLink.setStyleClass("highLightLink");
idLink.setId("demandlink" + rowVar); // Custom ID is required in
// dynamic
// UIInput
// and UICommand.
idLink.setValueExpression("value", createValueExpression("#{" + rowVar
+ ".part}", String.class));
idLink.setActionExpression(createActionExpression(dtValueExpression
+ ".selectDataModel}", String.class));
col1.getChildren().add(idLink);
col1.setHeader(header1);

dataTable1.getChildren().add(col1);

dataTable1.getChildren().add(addColumn2(rowVar, "IPN", "internalPart","dem1"));

dataTable1.getChildren().add(addColumn2(rowVar, "MFR", "mfgCode","dem2"));
dataTable1.getChildren().add(addColumn2(rowVar, "D/C", "dateCode","dem3"));
dataTable1.getChildren().add(addARColumn2(rowVar, "Qty", "requestQty","dem4"));
dataTable1.getChildren().add(
addColumn2(rowVar, "Demand Type", "demandTypeCode","dem5"));
dataTable1.getChildren().add(
addColumn2(rowVar, "Account Code", "accountCode","dem6"));
dataTable1.getChildren().add(
addColumn2(rowVar, "Account Classification",
"accountClassificationDesc","dem7a"));
dataTable1.getChildren().add(
addColumn2(rowVar, "Business Type", "businessTypeCode","dem7"));
dataTable1.getChildren().add(
addARColumn2(rowVar, "Target Price ($)", "targetPrice","dem8"));
dataTable1.getChildren().add(
addDateColumn2(rowVar, "Target Date", "strTargetDate","dem10"));
dataTable1.getChildren().add(
addDateColumn2(rowVar, "Update Date", "strUpdateDate","dem11"));
dataTable1.getChildren().add(
addColumn2(rowVar, "Trader", "salespersonName","dem12"));
// dataTable1.setRows(10);
Div div = new Div();
div.setId("demdiv"+idcount++);
// createScrollerDiv(div, "dem", rowVar);

dataTable1.setFooter(div);
HtmlOutputText blank = new HtmlOutputText();
blank.setValue(" ");
blank.setId("demhblnk"+rowVar);
dtPanelGrid.getChildren().add(blank);
dtPanelGrid.getChildren().add(dataTable1);
}



When dtPanelGrid is full you add it to the panelGrid on the JSP/facelet page
panelGrid.getChildren().add(dtPanelGrid);

This can be done in a while loop and repeated over and over as memory allows

Problem with these data tables is duplicate IDS so it is best to assign a id to each component
Originally I put each set of parts in a collapsible panel but going to a detail page and back to the search page resulted in duplicate IDs
putting it in a Panelgrid and assigning ids seems to have eliminated the problem
14 years ago
JSF
I got it to work by hacking I just passed the datasource into the execute. I think spring closes the connection and by passing the data source the connection stays open it is really strange

This Spring stored procedure passes in an array of tab delimited strings the procedure validates the strings if there are errors in validation an error is added to the error array and the array is passed back



public class JdbcUpLoadPOLinesDAOImpl extends StoredProcedure implements JdbcUploadPOLinesDAO {

private static final String UPLOAD_PO_LINES = "necxadm.po_upload_lines";
private static final String p_po_line_array= "p_po_line_array";

public JdbcUpLoadPOLinesDAOImpl(DataSource dataSource) {
super(dataSource, UPLOAD_PO_LINES);
final String[] errorList=new String[50];
declareParameter(new SqlParameter("poid", Types.BIGINT));
declareParameter(new SqlParameter("insert_user",Types.BIGINT));
declareParameter(new SqlParameter("version",Types.VARCHAR));
declareParameter(new SqlParameter("PO_LINES", Types.ARRAY,"STRING_ARRAY"));
declareParameter(new SqlOutParameter("results",Types.VARCHAR));
declareParameter(new SqlOutParameter("ERRORS", Types.ARRAY, "STRING_ARRAY", new SqlReturnType() {
public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException {
Connection con = cs.getConnection();
Map typeMap = con.getTypeMap();
typeMap.put(typeName, errorList);
Object o = cs.getObject(paramIndex);
return o;
}
}));
compile();
}

public Map upLoadLines(DriverManagerDataSource ds ,Long poid,Long loginUser,String version,String[] poLines) {
Map inParameters = new HashMap();
final String[] temp = poLines;
inParameters.put( "poid", poid );
inParameters.put( "insert_user", loginUser );
inParameters.put( "version", version );
inParameters.put("PO_LINES", new AbstractSqlTypeValue() {

protected Object createTypeValue(Connection con, int type, String typeName)
throws SQLException {
if( con.isClosed()){
System.out.println("connection is closed");
}else{
System.out.println("connection is open");
}
ArrayDescriptor desc = new ArrayDescriptor(typeName, con);
return new ARRAY(desc, con, temp);
}
});

Map out = execute( inParameters ); // Call on parent class


System.out.println("results="+out.get("results"));
ARRAY simpleArray=(ARRAY )out.get("ERRORS");
Object[] obj;
try {
obj = (Object[]) simpleArray.getArray(out);
System.out.println("obj[0]"+obj[0]);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return out;
}

This is the the outpput and it is what I expected
[STDOUT] obj[0]Header: Invalid Label for 'Part Number': xPart Number

Different scenarios require different approaches. You can reset the bean and page By creating a loadSomething() method this will be called after the bean is constructed and and then will forward the page to itself

Public String Reset(){
YourSessionBean = new YourSessionBean();
YourBean.loadSomething();// this method will set all your default values
Return “Page_u_are_On”;


This will do a total page refresh with new values

Now if You using partial page rendering say with a changeValueListener or action method I will Bind the component and reset the values in the java code also so that the page and bean are refreshed(but not the whole page)

Class Abc{
HtmlInputText xComponent;
String testComp;

//I can do this in an action
public void Reset(){
YourSessionBean = new YourSessionBean();
YourBean.loadSomething();

xComponent.setValue(“anyvalue”);
}


public HtmlInputText getXComponent() {
return xComponent;
}
public void setXComponent(HtmlInputText component) {
xComponent = component;
}
public String getTestComp() {
return testComp;
}
public void setTestComp(String testComp) {
this.testComp = testComp;
}


This is JSP /or XML Page
<t:inputText binding=”#{abc.xComponent}” value="#{abc.testComp}"/>

The init method will only work if the default values do not affect any of the Component on the JSF page


15 years ago
JSF
Set the initial values you want for the session bean in the constructor or an init method that is called by the constructor
When the bean is reset it you are basically destroying the bean and a new one is created and the constructor is fired again or you can give the properties default values
15 years ago
JSF
add these to your FacesUtil file

private static String getJsfEl(String value) {
return "#{" + value + "}";
}

public static void resetManagedBean(String beanName) {
getValueBinding(getJsfEl(beanName)).setValue(
FacesContext.getCurrentInstance(), null);
}

and reference this example
http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-jsf.html
probably all the jsf applications in the world have this as thier basic design
15 years ago
JSF