You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Alexander Wallace <aw...@rwmotloc.com> on 2007/05/17 01:13:57 UTC

default-edit on myfaces

still trying to succesfully used the edit mode of a portlet... I've  
seen that on SUN's impl. you can use the edit mode by just using  
navigation rules... for this you specify your from and outcomes in  
faces-config.xml but portlet.xm has a parameter such as:

    <init-param>
             <name>com.sun.faces.portlet.INIT_EDIT</name>
             <value>EditMode.jsp</value>
         </init-param>

in myfaces we do:

        <init-param>
             <name>default-view</name>
             <value>/index.jsp</value>
         </init-param>

real quick I tried to use:

         <init-param>
             <name>default-edit</name>
             <value>/edit.jsp</value>
         </init-param>

No errors as expected, but doesn't make a difference at runtime...

Is there such a thing in myfaces (i ignore if this is an impl  
specific thing or part of the specs)...

i tried this in 1.1.5 and 1.1.4

thanks!


Re: default-edit on myfaces

Posted by Alexander Wallace <aw...@rwmotloc.com>.
Thank you very much for your reply... I think i really lost my train  
of thought when I asked this... I have a similar override and works  
to some extent... My main and real issue is returning to view mode  
after an action takes place in edit mode and not only switching the  
mode but actually displaying the default view for view mode...  
Currently i get both the edit and vew pages displayed when i switch  
back...

In looking for a cleaner way i ran accross the fact that with sun's  
jsf you can do the switching using  init parameters... But I don't  
think that still solves my problem (the switching on an action)...  
will keep on trying..

Thanks!

On May 17, 2007, at 9:21 AM, Nebinger, David wrote:

> I don't really think this is a faces issue per-se, it is really a
> programmatic thing (I would guess that Sun included a workaround in
> their portlet to make it work).
>
> Basically a portlet has some do methods (doView(), doEdit(), and
> doHelp()) that, by overriding, you can access the various modes you're
> looking for.
>
> I've got an extension of MyFacesGenericPortlet that has the code  
> below.
> Change your portlet inheritance in your web.xml file, and add  
> values for
> the pages as init parameters in portlet.xml and you should be good to
> go...
>
> 	/**
> 	 * viewPage: The view page for view mode.
> 	 */
> 	protected String viewPage = null;
> 	/**
> 	 * editPage: The edit page for edit mode.
> 	 */
> 	protected String editPage = null;
> 	/**
> 	 * helpPage: The help page for help mode.
> 	 */
> 	protected String helpPage = null;
>
> 	/**
> 	 * @see
> org.apache.myfaces.portlet.MyFacesGenericPortlet#doEdit 
> (javax.portlet.Re
> nderRequest, javax.portlet.RenderResponse)
> 	 */
> 	protected void doEdit(RenderRequest request, RenderResponse
> response) throws PortletException, IOException {
>
> 		// Determine if the portlet mode has changed, indicates
> a needed switch to edit mode.
> 		Boolean isPortletModeChanged = (Boolean)
> request.getAttribute("isPortletModeChanged");
> 		
> 		if (isPortletModeChanged.booleanValue()) {
> 			setPortletRequestFlag(request);
> 			nonFacesRequest(request, response, editPage);
> 			return;
> 		}
>
> 		facesRender(request, response);
> 	}
>
> 	/**
> 	 * @see
> org.apache.myfaces.portlet.MyFacesGenericPortlet#doHelp 
> (javax.portlet.Re
> nderRequest, javax.portlet.RenderResponse)
> 	 */
> 	protected void doHelp(RenderRequest request, RenderResponse
> response) throws PortletException, IOException {
>
> 		// Determine if the portlet mode has changed, indicates
> a needed switch to edit mode.
> 		Boolean isPortletModeChanged = (Boolean)
> request.getAttribute("isPortletModeChanged");
> 		
> 		if (isPortletModeChanged.booleanValue()) {
> 			setPortletRequestFlag(request);
> 			nonFacesRequest(request, response, helpPage);
> 			return;
> 		}
>
> 		facesRender(request, response);
> 	}
> 	
> 	/**
> 	 * @see org.apache.myfaces.portlet.MyFacesGenericPortlet#init()
> 	 */
> 	@Override
> 	public void init() throws PortletException {
> 		// grab the possible initialization parameters which
> support modes.
> 		viewPage = getInitParameter("ViewPage");
> 		editPage = getInitParameter("EditPage");
> 		helpPage = getInitParameter("HelpPage");
> 		
> 		super.init();
> 	}
>
> 	/**
> 	 * @see
> javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
> javax.portlet.RenderResponse)
> 	 */
> 	@Override
> 	public void render(RenderRequest request, RenderResponse
> response) throws PortletException, IOException {
> 		// Get the current portlet session.
> 		PortletSession session = request.getPortletSession();
> 		
> 		// Find out what the current portlet mode is from the
> session.
> 		PortletMode mode = (PortletMode)
> session.getAttribute("CurrentPortletMode");
>
> 		if (mode == null) {
> 			// if not in the session, try to get from the
> request.
> 			mode = request.getPortletMode();
> 		}
>
> 		// Set the portlet mode changed flag accordingly
> 		if (mode != request.getPortletMode()) {
> 			if (logger.isDebugEnabled()) {
> 				logger.debug("Portlet mode has changed
> to " + mode.toString());
> 			}
> 			
> 			request.setAttribute("isPortletModeChanged",
> Boolean.TRUE);
> 			mode = request.getPortletMode();
> 		} else {
> 			request.setAttribute("isPortletModeChanged",
> Boolean.FALSE);
> 		}
>
> 		// save the mode in the session.
> 		session.setAttribute("CurrentPortletMode", mode);
> 		
> 		super.render(request, response);
> 	}
>
> NOTE: We do not really use the edit or help modes, so honestly this  
> code
> has not been tested...
>


RE: default-edit on myfaces

Posted by "Nebinger, David" <dn...@tbbgl.com>.
I don't really think this is a faces issue per-se, it is really a
programmatic thing (I would guess that Sun included a workaround in
their portlet to make it work).

Basically a portlet has some do methods (doView(), doEdit(), and
doHelp()) that, by overriding, you can access the various modes you're
looking for.

I've got an extension of MyFacesGenericPortlet that has the code below.
Change your portlet inheritance in your web.xml file, and add values for
the pages as init parameters in portlet.xml and you should be good to
go...

	/**
	 * viewPage: The view page for view mode.
	 */
	protected String viewPage = null;
	/**
	 * editPage: The edit page for edit mode.
	 */
	protected String editPage = null;
	/**
	 * helpPage: The help page for help mode.
	 */
	protected String helpPage = null;

	/**
	 * @see
org.apache.myfaces.portlet.MyFacesGenericPortlet#doEdit(javax.portlet.Re
nderRequest, javax.portlet.RenderResponse)
	 */
	protected void doEdit(RenderRequest request, RenderResponse
response) throws PortletException, IOException {

		// Determine if the portlet mode has changed, indicates
a needed switch to edit mode.
		Boolean isPortletModeChanged = (Boolean)
request.getAttribute("isPortletModeChanged");
		
		if (isPortletModeChanged.booleanValue()) {
			setPortletRequestFlag(request);
			nonFacesRequest(request, response, editPage);
			return;
		}

		facesRender(request, response);
	}

	/**
	 * @see
org.apache.myfaces.portlet.MyFacesGenericPortlet#doHelp(javax.portlet.Re
nderRequest, javax.portlet.RenderResponse)
	 */
	protected void doHelp(RenderRequest request, RenderResponse
response) throws PortletException, IOException {

		// Determine if the portlet mode has changed, indicates
a needed switch to edit mode.
		Boolean isPortletModeChanged = (Boolean)
request.getAttribute("isPortletModeChanged");
		
		if (isPortletModeChanged.booleanValue()) {
			setPortletRequestFlag(request);
			nonFacesRequest(request, response, helpPage);
			return;
		}

		facesRender(request, response);
	}
	
	/**
	 * @see org.apache.myfaces.portlet.MyFacesGenericPortlet#init()
	 */
	@Override
	public void init() throws PortletException {
		// grab the possible initialization parameters which
support modes.
		viewPage = getInitParameter("ViewPage");
		editPage = getInitParameter("EditPage");
		helpPage = getInitParameter("HelpPage");
		
		super.init();
	}

	/**
	 * @see
javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)
	 */
	@Override
	public void render(RenderRequest request, RenderResponse
response) throws PortletException, IOException {
		// Get the current portlet session.
		PortletSession session = request.getPortletSession();
		
		// Find out what the current portlet mode is from the
session.
		PortletMode mode = (PortletMode)
session.getAttribute("CurrentPortletMode");

		if (mode == null) {
			// if not in the session, try to get from the
request.
			mode = request.getPortletMode();
		}

		// Set the portlet mode changed flag accordingly
		if (mode != request.getPortletMode()) {
			if (logger.isDebugEnabled()) {
				logger.debug("Portlet mode has changed
to " + mode.toString());
			}
			
			request.setAttribute("isPortletModeChanged",
Boolean.TRUE);
			mode = request.getPortletMode();
		} else {
			request.setAttribute("isPortletModeChanged",
Boolean.FALSE);
		}

		// save the mode in the session.
		session.setAttribute("CurrentPortletMode", mode);
		
		super.render(request, response);
	}

NOTE: We do not really use the edit or help modes, so honestly this code
has not been tested...