Query for passing an instance
sainath_nair Feb 16, 2010 3:41 PMHi all,
In my application , I have a screen with two tabs
1. Grid View :- which has a datatable with all the records
2. Record View :- Where we can insert , update or delete a record.
In the record view tab, I have two input fields with pop-ups.
1. product category(foreign key)
2.products.(foreign key)
Pop-ups show records for the particular field.
When I select a value for product category using the pop-up , I need to get that instance in my product pop-up i.e I need to select products belonging to the product category selected by the user. I m trying to write a query for this requirement in my bean class for the pop-up.
Can anyone please, suggest me a way to do this? I dunno if I am correct with my idea. It can be using jsf, xml or by using a backing bean for the pop -up
Any ideas on this issue would be highly appreciated and followed.
The code is as follows :-
*******************************************************************************************************************888888
product pop-up.xhtml
<-- javascript for fetching the selected values and passing it to the parent window
<script type="text/javascript" >
/* <![CDATA[ */
/*
Function to highlight the row of the data table on mouse click
*/
function addOnclickToDatatableRows() {
var trs = document.getElementById('cyProductsListForm:cyProductsPopupList').getElementsByTagName('tr');
for (var i = 0; i < trs.length; i++) {
trs[i].onclick = new Function("highlightRow(this)");
}
}
var hilitedRow;
//Function to highlight a particular row
function highlightRow(tr) {
tr.bgColor = (tr.bgColor != '#ff0000') ? '#ff0000' : '#ffffff';
hilitedRow = tr;
}
/*
* Function to pass the selected values back to the parent window
*/
function chooseStatus()
{
if (opener && !opener.closed){ //check if opener is still open
if (hilitedRow){
var selectedStatus = hilitedRow.getElementsByTagName('td')[1].innerHTML;
var selectedStatusSqlIdentity =hilitedRow.getElementsByTagName('td')[2].getElementsByTagName('span')[0].innerHTML;
window.opener.document.getElementById("cyProductstockcreation:pscProductnameField:pscProductname").value = selectedStatus;
window.opener.document.getElementById("cyProductstockcreation:pscProductnameField:cyProductSqlidentity").value = selectedStatusSqlIdentity;
window.opener.focus();
}
else {
alert("Please select a row.");
return;
}
}
self.close();
}
/* ]]> */
</script>
<h:form id="cyProductsListForm">
<rich:dataTable id="cyProductsPopupList"
var="_cyProducts" rows="10" columnClasses="center"
value="#{cyProductsPopupList.resultList}"
bgcolor="#FFFFFF"
rendered="#{not empty cyProductsPopupList.resultList}">
<rich:column sortBy="#{_cyProducts.prdProductname}" filterBy="#{_cyProducts.prdProductname}" filterEvent="onkeyup">
<f:facet name="header">
<ui:include src="../layout/sort.xhtml">
<ui:param name="entityList" value="#{cyProductsPopupList}"/>
<ui:param name="propertyLabel" value=" Product name"/>
<ui:param name="propertyPath" value="cyProducts.prdProductname"/>
</ui:include>
</f:facet>
<h:outputText value="#{_cyProducts.prdProductname}"/>
</rich:column>
<rich:column sortBy="#{_cyProducts.prdDesc}" filterBy="#{_cyProducts.prdDesc}" filterEvent="onkeyup">
<f:facet name="header">
<ui:include src="../layout/sort.xhtml">
<ui:param name="entityList" value="#{cyProductsPopupList}"/>
<ui:param name="propertyLabel" value="Product description"/>
<ui:param name="propertyPath" value="cyProducts.prdDesc"/>
</ui:include>
</f:facet>
<h:outputText value="#{_cyProducts.prdDesc}"/>
</rich:column>
<f:facet name="footer">
<rich:datascroller align="center" for="cyProductsPopupList" maxPages="20" />
</f:facet>
<rich:column id="cysqlidentityzz" style="width:150px;" headerClass="hiddenColumn" styleClass="hiddenColumn">
<f:facet name="header">
<ui:include src="../layout/sort.xhtml">
<ui:param name="entityList" value="#{cyProductsPopupList}"/>
<ui:param name="propertyLabel" value="Prd Sqlidentity"/>
<ui:param name="propertyPath" value="cyProducts.prdSqlidentity"/>
</ui:include>
</f:facet>
<h:inputHidden id="sqlIdentityInput" value="#{_cyProducts.prdSqlidentity}" />
<h:outputText id="sqlcategoryOutput" value="#{_cyProducts.prdSqlidentity}"/>
</rich:column>
</rich:dataTable>
***************************************************************************************************************************
popuplist.java
public class CyProductsPopupList extends EntityQuery<CyProducts> {
@In(create = true)
private EntityManager entityManager;
@In(create = true)
CyProductsList cyProductsList;
private CyProductstockcreation cyProductstockcreation = new CyProductstockcreation();
@In(create = true)
CyProductstockcreationHome cyProductstockcreationHome;
private CyProducts cyProducts = new CyProducts();
public CyProducts getCyProducts() {
return cyProducts;
}
private static String EJBQL =new String();
private static final String[] RESTRICTIONS = {
"lower(cyProducts.prdDesc) like lower(concat(#{cyProductsList.cyProducts.prdDesc},'%'))",
"lower(cyProducts.prdDetaileddesc) like lower(concat(#{cyProductsList.cyProducts.prdDetaileddesc},'%'))",
"lower(cyProducts.prdProductname) like lower(concat(#{cyProductsList.cyProducts.prdProductname},'%'))", };
public CyProductsPopupList() {
EJBQL = "select cyProducts from CyProducts cyProducts where cyProducts.cyStatus.stsCode = 'ACT' and cyProducts.cyProductcategory.prcProductcategory = #{cyProductstockcreationHome.instance.cyProductcategory.prcSqlidentity} ";
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setEjbql(EJBQL);
}
public void setCyProducts(CyProducts cyProducts) {
this.cyProducts = cyProducts;
}
In my application , I have a screen with two tabs
1. Grid View :- which has a datatable with all the records
2. Record View :- Where we can insert , update or delete a record.
In the record view tab, I have two input fields with pop-ups.
1. product category(foreign key)
2.products.(foreign key)
Pop-ups show records for the particular field.
When I select a value for product category using the pop-up , I need to get that instance in my product pop-up i.e I need to select products belonging to the product category selected by the user. I m trying to write a query for this requirement in my bean class for the pop-up.
Can anyone please, suggest me a way to do this? I dunno if I am correct with my idea. It can be using jsf, xml or by using a backing bean for the pop -up
Any ideas on this issue would be highly appreciated and followed.
The code is as follows :-
*******************************************************************************************************************888888
product pop-up.xhtml
<-- javascript for fetching the selected values and passing it to the parent window
<script type="text/javascript" >
/* <![CDATA[ */
/*
Function to highlight the row of the data table on mouse click
*/
function addOnclickToDatatableRows() {
var trs = document.getElementById('cyProductsListForm:cyProductsPopupList').getElementsByTagName('tr');
for (var i = 0; i < trs.length; i++) {
trs[i].onclick = new Function("highlightRow(this)");
}
}
var hilitedRow;
//Function to highlight a particular row
function highlightRow(tr) {
tr.bgColor = (tr.bgColor != '#ff0000') ? '#ff0000' : '#ffffff';
hilitedRow = tr;
}
/*
* Function to pass the selected values back to the parent window
*/
function chooseStatus()
{
if (opener && !opener.closed){ //check if opener is still open
if (hilitedRow){
var selectedStatus = hilitedRow.getElementsByTagName('td')[1].innerHTML;
var selectedStatusSqlIdentity =hilitedRow.getElementsByTagName('td')[2].getElementsByTagName('span')[0].innerHTML;
window.opener.document.getElementById("cyProductstockcreation:pscProductnameField:pscProductname").value = selectedStatus;
window.opener.document.getElementById("cyProductstockcreation:pscProductnameField:cyProductSqlidentity").value = selectedStatusSqlIdentity;
window.opener.focus();
}
else {
alert("Please select a row.");
return;
}
}
self.close();
}
/* ]]> */
</script>
<h:form id="cyProductsListForm">
<rich:dataTable id="cyProductsPopupList"
var="_cyProducts" rows="10" columnClasses="center"
value="#{cyProductsPopupList.resultList}"
bgcolor="#FFFFFF"
rendered="#{not empty cyProductsPopupList.resultList}">
<rich:column sortBy="#{_cyProducts.prdProductname}" filterBy="#{_cyProducts.prdProductname}" filterEvent="onkeyup">
<f:facet name="header">
<ui:include src="../layout/sort.xhtml">
<ui:param name="entityList" value="#{cyProductsPopupList}"/>
<ui:param name="propertyLabel" value=" Product name"/>
<ui:param name="propertyPath" value="cyProducts.prdProductname"/>
</ui:include>
</f:facet>
<h:outputText value="#{_cyProducts.prdProductname}"/>
</rich:column>
<rich:column sortBy="#{_cyProducts.prdDesc}" filterBy="#{_cyProducts.prdDesc}" filterEvent="onkeyup">
<f:facet name="header">
<ui:include src="../layout/sort.xhtml">
<ui:param name="entityList" value="#{cyProductsPopupList}"/>
<ui:param name="propertyLabel" value="Product description"/>
<ui:param name="propertyPath" value="cyProducts.prdDesc"/>
</ui:include>
</f:facet>
<h:outputText value="#{_cyProducts.prdDesc}"/>
</rich:column>
<f:facet name="footer">
<rich:datascroller align="center" for="cyProductsPopupList" maxPages="20" />
</f:facet>
<rich:column id="cysqlidentityzz" style="width:150px;" headerClass="hiddenColumn" styleClass="hiddenColumn">
<f:facet name="header">
<ui:include src="../layout/sort.xhtml">
<ui:param name="entityList" value="#{cyProductsPopupList}"/>
<ui:param name="propertyLabel" value="Prd Sqlidentity"/>
<ui:param name="propertyPath" value="cyProducts.prdSqlidentity"/>
</ui:include>
</f:facet>
<h:inputHidden id="sqlIdentityInput" value="#{_cyProducts.prdSqlidentity}" />
<h:outputText id="sqlcategoryOutput" value="#{_cyProducts.prdSqlidentity}"/>
</rich:column>
</rich:dataTable>
***************************************************************************************************************************
popuplist.java
public class CyProductsPopupList extends EntityQuery<CyProducts> {
@In(create = true)
private EntityManager entityManager;
@In(create = true)
CyProductsList cyProductsList;
private CyProductstockcreation cyProductstockcreation = new CyProductstockcreation();
@In(create = true)
CyProductstockcreationHome cyProductstockcreationHome;
private CyProducts cyProducts = new CyProducts();
public CyProducts getCyProducts() {
return cyProducts;
}
private static String EJBQL =new String();
private static final String[] RESTRICTIONS = {
"lower(cyProducts.prdDesc) like lower(concat(#{cyProductsList.cyProducts.prdDesc},'%'))",
"lower(cyProducts.prdDetaileddesc) like lower(concat(#{cyProductsList.cyProducts.prdDetaileddesc},'%'))",
"lower(cyProducts.prdProductname) like lower(concat(#{cyProductsList.cyProducts.prdProductname},'%'))", };
public CyProductsPopupList() {
EJBQL = "select cyProducts from CyProducts cyProducts where cyProducts.cyStatus.stsCode = 'ACT' and cyProducts.cyProductcategory.prcProductcategory = #{cyProductstockcreationHome.instance.cyProductcategory.prcSqlidentity} ";
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setEjbql(EJBQL);
}
public void setCyProducts(CyProducts cyProducts) {
this.cyProducts = cyProducts;
}