Thursday, January 20, 2011

Advanced Search Bean to get Criteria and Load based on it OA Framework

Controller Code

public void SetQuery(OAPageContext pageContext, OAWebBean webBean)
AllianceTeamAMImpl MyRequestAm =(AllianceTeamAMImpl) pageContext.getApplicationModule(webBean);
OAQueryBean queryBean =(OAQueryBean)webBean.findIndexedChildRecursive("SearchRn");
Dictionary[] dic = queryBean.getCriteria(pageContext);
// If the dictionary is empty, then it means that no non-view criteria
// is available, so return.
if(pageContext.getParameter(queryBean.getGoButtonName()) != null )
// When Button is pressed it will go in below loop
if (dic != null && !dic.toString().equals(""))
// Otherwise process the dictionary to build your where clause.
Hashtable params = new Hashtable();
int size = dic.length;
int clauseCount = 0;
int bindCount = 2;
StringBuffer whereClause = new StringBuffer();
Vector parameters = new Vector();
ViewObject allTeamVO = MyRequestAm.findViewObject("MyAllianceTeamVO2");

// Iterate through the dictionary to set your where clauses
for (int i=0; i < size; i++) { // Item for which the criteria is defined. String itemName = (String) dic[i].get(OAViewObject.CRITERIA_ITEM_NAME); String viewAttributename = (String)dic[i].get(OAViewObject.CRITERIA_VIEW_ATTRIBUTE_NAME); String columnName = allTeamVO.findAttributeDef(viewAttributename).getColumnNameForQuery(); // Condition is the SQL condition - examples: like , = etc String condition = (String) dic[i].get(OAViewObject.CRITERIA_CONDITION); // String criteriaDataType = (String)dic[i].get(OAViewObject.CRITERIA_DATATYPE); // Value is the value entered with the appropriate % based on condition Object value = dic[i].get(OAViewObject.CRITERIA_VALUE); // Join condition is either AND or OR depending on what user chooses String joinCondition = (String) dic[i].get(OAViewObject.CRITERIA_JOIN_CONDITION); if(value != null) { if(clauseCount > 0)
whereClause.append(" AND ");
whereClause.append(columnName + " " + condition + " :");
// If where clause and criteria then get query
if(dic != null && whereClause != null)
MyRequestAm.initMyAllianceTeamUserVOQuery("" +pageContext.getUserId(), pageContext.getTransactionTransientValue("Team").toString(),whereClause.toString(),parameters);
// When Criteria is null Bring all
MyRequestAm.initMyAllianceTeamUserVOQuery("" +pageContext.getUserId(), pageContext.getTransactionTransientValue("Team").toString());

AM Code
public void initMyAllianceTeamUserVOQuery(String user,String team,String WhereClause, Vector parameters)
    MyAllianceTeamVOImpl vo=  getMyAllianceTeamVO2();
      MessageToken[] errTokens = {new MessageToken("OBJECT_NAME", "MyAllianceTeamVO")};
      throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);

    if(WhereClause != null)
      int cnt = parameters.size();
      for(int i=0;i
Controller code
1. We are taking the region of Search and getting its QueryBean
2. Next we are checking whether button is pressed.
3. we are getting the search criteria selected by user and assin it to dictionary
4. We are looping through Dictionary and create where clause and parameters and send it to AM to execute based on search clause given
5. If i dont pass any parameters , then by default all is loaded.
6. I have set bindcount to 2 because i have already 2 parameters

Model Code

1. We are getting the parameters and adding the parameters to the view object and execute it.

How to get bean value in Advanced Search OA Framework

In Advanced search the criteria is stored in order of Value_0,Value_1,...

I want to set a oaMessageChoice bean value in page load(processRequest)

My code will be.

OAAdvancedSearchBean advBean = (OAAdvancedSearchBean)webBean.findChildRecursive("advancedSearch");
OAMessageChoiceBean StatusSearch = (OAMessageChoiceBean)advBean.findChildRecursive("Value_1");
StatusSearch.setValue(pageContext,"Pending with Alliance");


advanced search is the ID of AdvancedSearch Region