Thursday, July 12, 2012

Most Used codes


1. FOR FACES MESSAGE POPUP -To show warning/error/info messages on view page
 

  1. FacesContext fctx = FacesContext.getCurrentInstance();
  2. FacesMessage msg=new FacesMessage(Severity,String Summary, String Message);
  3. fctx.addMessage(inputText.getId(), msg);

For Eg:
  1. FacesContext fc=FacesContext.getCurrentInstance();
  2. FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Save It" ,"Before Navigating to details Click Save..");
  3. fc.addMessage(null,msg);


2.TO GET OPERATION BINDING:
  1. BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding
  2. ("CreateInsert2").execute();
  3.      OR
  4. BindingContainer bindings = getBindings();
  5. OperationBinding glOP = bindings.getOperationBinding("Commit");
  6. glOP.execute();
  7. if (!glOP.getErrors().isEmpty()) { //in case operation binding returns error
  8. } else{
  9. }

3.TO GET CURRENT ROW FROM ITERATOR BINDING:
  1. BindingContext btx = BindingContext.getCurrent();
  2. DCBindingContainer dcbct = (DCBindingContainer)btx.getCurrentBindingsEntry();
  3. DCIteratorBinding binding = dcbct.findIteratorBinding("EmployeeIterator");
  4. Row currentRow = binding.getCurrentRow();
  5.      OR
  6. DCIteratorBinding iterBind= (DCIteratorBinding)dcbct .get("testIterator");
  7. String attribute = (String)iterBind.getCurrentRow().getAttribute("empName");
  8.      OR
  9. FacesContext ctx = FacesContext.getCurrentInstance();
  10. ExpressionFactory exf = ctx.getApplication().getExpressionFactory();
  11. ValueExpression vale = exf.createValueExpression(ctx.getELContext(), "#{bindings.EmployeeIterator.currentRow.dataProvider}", Emp.class);
  12. Emp name= (Emp)vale.getValue(ctx.getELContext());


4.TO REFRESH THE PAGE:
  1. protected void refreshPage() {
  2. FacesContext fctx = FacesContext.getCurrentInstance();
  3. String refreshpage = fctx.getViewRoot().getViewId();
  4. ViewHandler ViewH = fctx.getApplication().getViewHandler();
  5. UIViewRoot UIV = ViewH.createView(fctxc, refreshpage);
  6. UIV.setViewId(refreshpage);
  7. fctx.setViewRoot(UIV);
  8. }

5.TO REFRESH (PPR) ANY UI COMPONENT:
  1. AdfFacesContext.getCurrentInstance().addPartialTarget(UIComponent);

6.TO OPEN A POPUP
  1. private void showPopup(RichPopup pop, boolean visible) {
  2. try {
  3. FacesContext context = FacesContext.getCurrentInstance();
  4. if (context != null && pop != null) {
  5. String popupId = pop.getClientId(context);
  6. if (popupId != null) {
  7. StringBuilder script = new StringBuilder();
  8. script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");
  9. if (visible) {
  10. script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
  11. } else {
  12. script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");
  13. }
  14. ExtendedRenderKitService erks =
  15. Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
  16. erks.addScript(context, script.toString());
  17. }
  18. }
  19. } catch (Exception e) {
  20. throw new RuntimeException(e);
  21. }
  22. }

No comments:

Post a Comment