Skip to main content

ADF: Auto Suggest - solutions

I had implemented autosuggest on an input text field and it was all working so I moved it into our template to make it available application wide. The component stopped working (bind problem first then it would not return the value I needed into the text box). Here are the fixes.

The component is quick go button functionality with a suggest lookup to any menu link.

Bind problems solution: I needed to lookup the template binding using the current bind did not have my VO:
 BindingContext bctx = BindingContext.getCurrent();
  DCBindingContainer bindings = 
      bctx.findBindingContainer(
      "package_formTemplatePageDef");


Not returning the value solution: I had a uppercase conveter on my input text field - this was messing with my return value on the autosuggest. I removed it and it worked like magic.

The working code (note the query is limited to 5 rows in the VO with a bind variable linked to rownum):

JSFF
<af:panelGroupLayout id="pt_ag12" layout="horizontal">
  <af:inputText labelStyle="color: white" label="Go Link" id="pt_it7" value="#{menuBean.goValue}">
    <af:autoSuggestBehavior suggestItems="#{menuBean.suggestGoItems}"
      maxSuggestedItems="#{menuBean.maxSuggestionResults}"/>
  </af:inputText>
  <af:commandButton text="go" id="pt_cbGo" disabled="#{menuBean.goEnabled}"
    action="#{menuBean.performGo}"/>
</af:panelGroupLayout>

Bean
public int getMaxSuggestionResults() {
  return 5;
}

public List suggestGoItems(
  FacesContext fctx, oracle.adf.view.rich.model.AutoSuggestUIHints hints) {
  ArrayList selectItems = new ArrayList();
  String submittedValue = hints.getSubmittedValue();
  if(submittedValue != null && submittedValue.length() > 3) {
    BindingContext bctx = BindingContext.getCurrent();
    DCBindingContainer bindings = 
      bctx.findBindingContainer(
      "package_formTemplatePageDef");
    DCIteratorBinding binding = bindings.findIteratorBinding("AutoSuggestMenuVOIterator");

    HashMap variables = new HashMap();
    variables.put("userCode", super.getUserCode());
    variables.put("maxLimit", new Integer(getMaxSuggestionResults()));
    variables.put("searchName", submittedValue.toUpperCase());
    ADFUtils.setBindVariables(binding.getViewObject(), variables);
    binding.executeQuery();
    Row[] rows = binding.getAllRowsInRange();
    for(Row row : rows) {
      Object action = row.getAttribute("Action");
      String name = (String) row.getAttribute("Name");
      selectItems.add(new SelectItem(action, name));
    }
  }
  return selectItems;
}

public boolean isGoEnabled() {
  return goValue != null && goValue.length() > 3;
}

public String getGoValue() {
 return goValue;
}

public void setGoValue(String goValue) {
  this.goValue = goValue;
 }

public String performGo() {
  ExternalContext eCtx = JSFUtils.getExternalContext();
  //sql query to get the destination
  String destination = MenuUtility.getDestinationBasedOnKey(goValue, "name");

  if(destination != null) {
    String contextPath = ((HttpServletRequest) eCtx.getRequest()).getContextPath();
    try {
      logger.debug("redirectUrl=[" + contextPath + destination + "]");
      eCtx.redirect(contextPath + destination);
    } catch(Exception e) {
      logger.error("", e);
    }
  }
  return null;
}

ADFUtils.setBindVariables


public static void setBindVariables(ViewObject view, Map variables) {
  VariableValueManager vm = view.ensureVariableManager();
  for(String key : variables.keySet()) {
    vm.setVariableValue(key, variables.get(key));
  }
}

So anyway here are a couple of auto suggestions for the autosuggest component:

1) I want to control the value selected so a on select method would be nice.
2) The no results found text should be easily customized.

Comments

Popular posts from this blog

ADF Encountered deferred syntax #{ in template text.

OracleJSP error: oracle.jsp.parse.JspParseException:  Error: Encountered deferred syntax #{ in template text.  If intended as a literal, escape it or set directive  deferredSyntaxAllowedAsLiteral This normally happens when you have some tag lib dependancy problems but this was  not the case for me... My problem: For some reason my model project had web stuff in it(public html etc)  so I had to remove the public html stuff from my project and manually edit the Model.jpr project file and remove the tag lib entries at the bottom o the file. Go figure.    

JBO-25013: TooManyObjectsException

oracle.jbo.TooManyObjectsException: JBO-25013: Too many objects match the primary key oracle.jbo.Key[Key null ]. Ok so for you it may be trying to insert a duplicate record this should explain your problem (also check trigger they could be the cause.) NOTE: You can also try to create a new duplicate EO if you have a page with two VO's using the same EO. This could sort your problems. For me I needed to add a launch listener on my LOV and clear the cache of my vo. LOV <af:inputListOfValues id="NameId" popupTitle="#{bindings.Name.hints.label}" value="#{bindings.RolName1.inputValue}" label="#{bindings.RolName1.hints.label}" model="#{bindings.RolName1.listOfValuesModel}" required="#{bindings.RolName1.hints.mandatory}" columns="#{bindings.RolName1.hints.displayWidth}" shortDesc="#{bindings.RolName1.hints.tooltip}" launchPopupListener="#{backingBeanScope.backingBean.launchPop

OJDeploy: Documentation for the tool

Real DOCS:  http://docs.oracle.com/cd/E26098_01/user.1112/e17455/deploying_apps.htm#OJDUG645 OJDeploy Documentation if you run it from the command line - I keep looking for this so I though I would post it here so I remeber. Oracle JDeveloper Deploy 11.1.2.1.0.6081 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. Usage:   ojdeploy -profile <name> -workspace <jws> [ -project <name> ] [ <options> ]   ojdeploy -buildfile <ojbuild.xml> [ <options> ]   ojdeploy -buildfileschema Arguments:   -profile               the name of the Profile to deploy   -workspace      full path to the JDeveloper Workspace file(.jws)   -project              name of the JDeveloper Project within the .jws where the Profile can be found. If omitted, the Profile is assumed to be in the Workspace.   -buildfile            full path to a build file for batch deploy   -buildfileschema  print XML Schema for the build file