cancel
Showing results for 
Search instead for 
Did you mean: 

Question about CustomDialog

rcortesr
Star Contributor
Star Contributor
Hi,

I have created a new dialog for to add aspects to the documents.
I have used the example CustomDialog.
I want to hide aspects in the page of selection, because only I see my custom aspects.
I want to hide Dublin Core, Localizable, Auditable…

This is possible?? How I can do it?

Thanks!!
9 REPLIES 9

gavinc
Champ in-the-making
Champ in-the-making
The thing to do in this scenario is to add a method to your custom bean to return the list of custom aspects you want to display.

Have a look at the getTestableAspects() method in BaseActionWizard for an example of how to do this (although you may not need all the config lookup code if you know what you want).

You can then change the JSP to get the list of aspects from your bean, for example if you added a getMyCustomAspects() method to your dialog bean you could use the following in your JSP:

<h:selectOneMenu value="#{DialogManager.bean.aspect}">
   <f:selectItems value="#{DialogManager.bean.myCustomAspects}" />
</h:selectOneMenu>

Hope that helps.

rcortesr
Star Contributor
Star Contributor
Hi,

I have created myCustomAspects() method, this is the code:
package org.alfresco.sample;

import javax.faces.context.FacesContext;

import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.actions.BaseActionWizard;
import java.util.List;

/**
* Bean implementation for the "Add Aspect Dialog"
*
* @author gavinc
*/
public class AddAspectDialog extends BaseDialogBean
{
   protected String aspect;
   protected List myCustomAspects;
     
   @Override
   protected String finishImpl(FacesContext context, String outcome) throws Exception
   {
      // get the space the action will apply to
      //NodeRef nodeRef = this.browseBean.getActionSpace().getNodeRef();
   NodeRef nodeRef = this.browseBean.getDocument().getNodeRef();
     
      // resolve the fully qualified aspect name
      QName aspectToAdd = Repository.resolveToQName(this.aspect);
     
      // add the aspect to the space
      this.nodeService.addAspect(nodeRef, aspectToAdd, null);
     
      // return the default outcome
      return outcome;
   }

   @Override
   public boolean getFinishButtonDisabled()
   {
      return false;
   }

   public String getAspect()
   {
      return aspect;
   }

   public void setAspect(String aspect)
   {
      this.aspect = aspect;
   }
  
   public List myCustomAspects()
   {
      BaseActionWizard x = null;
      System.out.println(x.getAspects());
      this.myCustomAspects = x.getAspects();
      return x.getAspects();
   }

}

My selectAspect.jsp is the following:
<h:outputText value="Opciones: " />
<h:selectOneMenu value="#{DialogManager.bean.aspect}">
     <f:selectItems value="#{DialogManager.bean.myCustomAspects}" />
</h:selectOneMenu>

When I launch the custom dialog appears the following ERROR:
javax.faces.FacesException: Bean: org.alfresco.sample.AddAspectDialog, property: myCustomAspects
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:421)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.alfresco.web.app.servlet.AlfrescoFacesServlet.service(AlfrescoFacesServlet.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.apache.jasper.JasperException: Bean: org.alfresco.sample.AddAspectDialog, property: myCustomAspects
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
at org.apache.jsp.jsp.dialog.container_jsp._jspService(org.apache.jsp.jsp.dialog.container_jsp:497)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:415)
… 21 more

Do you know what is the problem??

Thanks.

alpha
Champ in-the-making
Champ in-the-making
do you have the same error when you rename your method with getMyCustomAspects() instead of myCustomAspects()?

rcortesr
Star Contributor
Star Contributor
do you have the same error when you rename your method with getMyCustomAspects() instead of myCustomAspects()?
Yes, the error is the same.

gavinc
Champ in-the-making
Champ in-the-making
The problem is with the code within the method.

BaseActionWizard x = null;
System.out.println(x.getAspects());
this.myCustomAspects = x.getAspects();
return x.getAspects();

The variable "x" is null and never instantiated, this is what is causing the error i.e. a NullPointerException, granted JSF's error message is far from helpful!


The method should also be called getMyCustomAspects().

rcortesr
Star Contributor
Star Contributor
Hi gavinc,

The problem is that I can't to instantiate the variable "x" with the BaseActionWizard constructor. It Appears one ERROR: cannot instantiate the type BaseActionWizard
This is the new code:
   public List myCustomAspects()
   {
      BaseActionWizard x = new BaseActionWizard();
      System.out.println(x.getAspects());
      this.myCustomAspects = x.getAspects();
      return x.getAspects();
   }

gavinc
Champ in-the-making
Champ in-the-making
Hi,

Yes, i was jsut highlighting where the error was coming from. You don't/shouldn't instantiate a wizard object in here.

For your test just copy the code from RunActionWizard.getTestableAspects() into your method. Once you have an idea how it works replace that code with your own.

rcortesr
Star Contributor
Star Contributor
Hi,

Yes, i was jsut highlighting where the error was coming from. You don't/shouldn't instantiate a wizard object in here.

For your test just copy the code from RunActionWizard.getTestableAspects() into your method. Once you have an idea how it works replace that code with your own.
Hi gavinc,

I have done that you say.
If I call the property DialogManager.bean.getMyCustomAspects appers the following error:
javax.faces.FacesException: Bean: org.alfresco.sample.AddAspectDialog, property: getMyCustomAspects
caused by:
org.apache.jasper.JasperException: Bean: org.alfresco.sample.AddAspectDialog, property: getMyCustomAspects
caused by:
javax.faces.el.PropertyNotFoundException: Bean: org.alfresco.sample.AddAspectDialog, property: getMyCustomAspects
And if I call the method DialogManager.bean.getMyCustomAspects() appears this error:
javax.faces.FacesException: Invalid expression: '${DialogManager.bean.getMyCustomAspects()}'
caused by:
org.apache.jasper.JasperException: Invalid expression: '${DialogManager.bean.getMyCustomAspects()}'
caused by:
javax.faces.el.ReferenceSyntaxException: Invalid expression: '${DialogManager.bean.getMyCustomAspects()}'
caused by:
org.apache.commons.el.parser.ParseException: Encountered "(" at line 1, column 40.
Was expecting one of:
"}" …
"." …
">" …
"gt" …
"<" …
"lt" …
"==" …
"eq" …
"<=" …
"le" …
">=" …
"ge" …
"!=" …
"ne" …
"[" …
"+" …
"-" …
"*" …
"/" …
"div" …
"%" …
"mod" …
"and" …
"&&" …
"or" …
"||" …
"?" …

What is the problem??
Thanks

gavinc
Champ in-the-making
Champ in-the-making
Your value binding expression should be:

#{DialogManager.bean.myCustomAspects}

May I also suggest that you go through a couple of JSF tutorials as a lot of the questions you've asked would become clearer following this.